
/* ================================
   Corner Connect (no Tailwind)
   ================================ */

:root {
    --bg: #0f172a;           /* slate-900 */
    --panel: #1e293b;        /* slate-800 */
    --panel-2: #0b1220;
    --text: #e2e8f0;         /* slate-200 */
    --muted: #94a3b8;        /* slate-400 */
    --border: rgba(148, 163, 184, 0.18);
    --border-strong: rgba(148, 163, 184, 0.28);
    --cyan: #22d3ee;
    --cyan-2: #06b6d4;
    --blue: #3b82f6;
    --yellow: #facc15;
    --shadow: 0 30px 60px rgba(0,0,0,0.35);
    --bg-deep: #050914;
    --bg-ink: #071427;
    /* Approx current desktop board size; used as max */
    /* Increased ~5% for a slightly larger board */
    --cc-board-max-size: 458px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; }

.cc-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    background:
        linear-gradient(180deg, rgba(5, 9, 20, 0.70), rgba(5, 9, 20, 0.92)),
        url("../img/bg.png");
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    background-attachment: fixed;
    color: var(--text);
}

.cc-app ::selection {
    background: rgba(34, 211, 238, 0.25);
}

.cc-title {
    margin: 0 0 8px;
    font-size: clamp(32px, 4vw, 44px);
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(90deg, #22d3ee, #a855f7);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.cc-title--modal {
    text-align: center;
    margin-top: 6px;
}

.cc-topbar {
    position: fixed;
    top: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 60;
}

.cc-level-indicator {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
}

.cc-level-indicator__value {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #e2e8f0;
}

.cc-topbar__left .cc-btn--icon,
.cc-topbar__right .cc-btn--icon {
    background: rgba(30, 41, 59, 0.55);
    border: 1px solid rgba(148, 163, 184, 0.20);
    box-shadow: 0 10px 24px rgba(0,0,0,0.28);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.cc-topbar__left .cc-btn--icon:hover,
.cc-topbar__right .cc-btn--icon:hover {
    background: rgba(30, 41, 59, 0.72);
    border-color: rgba(34, 211, 238, 0.22);
    box-shadow: 0 14px 30px rgba(0,0,0,0.34);
}

.cc-topbar__left .cc-btn--icon:active,
.cc-topbar__right .cc-btn--icon:active {
    transform: scale(0.97);
}

.cc-start-open .cc-topbar {
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
}

.cc-modal-open .cc-topbar {
    pointer-events: none;
}

.cc-modal-open .cc-topbar__left,
.cc-modal-open .cc-topbar__right {
    pointer-events: none;
}

.cc-topbar__left,
.cc-topbar__right {
    display: flex;
    gap: 10px;
    pointer-events: auto;
}

.cc-topbar__center {
    position: absolute;
    top: calc(100% + 10px); /* place Play Again below the top row */
    left: 50%;
    transform: translateX(-50%);
    pointer-events: auto;
    display: flex;
    align-items: center;
}

/* Ensure top-center "Play Again" button matches icon button height */
.cc-topbar__center .cc-btn--secondary.cc-btn--small {
    height: 44px;
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 22px;
    padding-right: 22px;
    display: inline-flex;
    align-items: center;
    color: #fff;
    border: 0;
    background: linear-gradient(90deg, #0ea5e9 0%, #f97316 100%);
    box-shadow:
        0 4px 20px rgba(14, 165, 233, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}

.cc-topbar__right {
    justify-content: flex-end;
}

.cc-stage {
    position: relative;
}

.cc-grid {
    display: grid;
    gap: 4px;
    padding: 10px;
    border-radius: 14px;
    /* Fixed square gameboard: width == height, shrinks on small screens but
       keeps the same max size on desktop. */
    width: min(var(--cc-board-max-size), 92vw, 92vh);
    aspect-ratio: 1 / 1;
    grid-auto-rows: 1fr;
    /* Match start modal palette (cool navy) */
    background: #121a27;
    border: 0;
    box-shadow:
        0 26px 56px rgba(0, 0, 0, 0.42),
        0 14px 28px rgba(0, 0, 0, 0.28);
    position: relative;
    z-index: 1;
}

.cc-grid::before {
    content: none;
}

.cc-grid::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 14px;
    pointer-events: none;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.10) inset,
        0 -1px 0 rgba(0,0,0,0.35) inset;
}

/* Game layout (avoid JS inline styles) */
.cc-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.cc-grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.cc-grid--5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}
.cc-grid--6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}
.cc-grid--7 {
    grid-template-columns: repeat(7, minmax(0, 1fr));
}
.cc-grid--8 {
    grid-template-columns: repeat(8, minmax(0, 1fr));
}

.cc-tile {
    width: 100%;
    height: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border-radius: 8px;
    border: 0;
    background: #182132;
    color: inherit;
    cursor: pointer;
    transition: background-color 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
    overflow: visible;
    position: relative;
    box-shadow:
        0 10px 18px rgba(0,0,0,0.30),
        0 1px 0 rgba(255,255,255,0.10) inset,
        0 -10px 20px rgba(0,0,0,0.22) inset;
}

.cc-tile::before {
    content: none;
}

.cc-tile:hover {
    background: #1b263a;
}
.cc-tile:disabled { cursor: default; }
.cc-tile--empty { cursor: default; }
.cc-tile--empty:hover { background: #182132; }

.cc-tile--valid {
    /* keep state readable without glow */
    background: #1c2a40;
}

.cc-tile--solved {
    opacity: 0.85;
}

.cc-tile__svg {
    width: 100%;
    height: 100%;
    padding: 8px;
    pointer-events: none;
    overflow: visible;
}

.cc-overlay,
.cc-modal {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cc-overlay {
    z-index: 2;
    border-radius: 14px;
    background: transparent;
}

.cc-panel {
    width: min(460px, 92vw);
    background: linear-gradient(165deg, #1a1f2e 0%, #0f1419 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px;
    box-shadow:
        0 24px 56px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    padding: 30px 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

/* Win/Game-over dialog: cooler + lighter than start panel */
#win-overlay .cc-panel {
    background: rgba(20, 36, 58, 0.92);
    border-color: rgba(56, 189, 248, 0.18);
    box-shadow:
        0 28px 70px rgba(0, 0, 0, 0.52),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
}

.cc-panel__title {
    margin: 0;
    font-size: 34px;
    font-weight: 800;
    color: #fff;
}

.cc-panel__subtitle {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 15px;
}

.cc-win__actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 2px;
}

/* Make both win buttons fill their grid cells */
#win-overlay .cc-btn--secondary,
#win-overlay .cc-btn--primary {
    width: 100%;
}

.cc-btn {
    border: 1px solid var(--border-strong);
    background: var(--panel);
    color: rgba(226, 232, 240, 0.85);
    border-radius: 999px;
    cursor: pointer;
    transition: transform 180ms ease, background-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.cc-btn:hover {
    background: rgba(148, 163, 184, 0.10);
    color: #fff;
}

.cc-btn:active { transform: scale(0.98); }

.cc-btn--icon {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.cc-btn i {
    font-size: 18px;
    line-height: 1;
}

.cc-btn--primary {
    width: min(320px, 100%);
    padding: 16px 20px;
    font-size: 18px;
    font-weight: 900;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #fff;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(90deg, #0ea5e9 0%, #f97316 100%);
    box-shadow:
        0 4px 20px rgba(14, 165, 233, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.15) inset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.cc-btn--secondary {
    width: min(320px, 100%);
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(226, 232, 240, 0.92);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(255, 255, 255, 0.06);
    box-shadow:
        0 18px 34px rgba(0,0,0,0.26),
        0 0 0 1px rgba(0,0,0,0.35) inset;
}

.cc-btn--secondary:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.09);
    color: #fff;
}

.cc-btn--secondary:active {
    transform: translateY(0);
}

.cc-btn--small {
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.cc-btn--primary:hover {
    transform: translateY(-1px);
    box-shadow:
        0 8px 28px rgba(14, 165, 233, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

.cc-btn--primary:active {
    transform: translateY(0);
}

.cc-btn--primary i {
    font-size: 16px;
}

.cc-btn--full {
    width: 100%;
    border-radius: 12px;
    padding: 14px 16px;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(90deg, #0ea5e9 0%, #f97316 100%);
    border: 0;
    margin-top: 16px;
    box-shadow:
        0 4px 20px rgba(14, 165, 233, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}

.cc-btn--full:hover {
    transform: translateY(-1px);
    box-shadow:
        0 8px 28px rgba(14, 165, 233, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

.cc-btn--fullwidth {
    width: 100%;
}

.cc-start__actions {
    margin: 0;
    width: 100%;
    display: grid;
    gap: 10px;
}

.cc-modal {
    position: fixed;
    z-index: 100;
    padding: 16px;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* Keep win overlay centered and independent of grid width */
.cc-overlay {
    position: fixed;
}

.cc-modal--start {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.cc-modal--tutorial {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* When any modal is open, show game behind but disable interactions */
.cc-modal-open #grid-container {
    pointer-events: none;
}

.cc-modal-open .cc-topbar {
    pointer-events: none;
}

/* When start screen is open, hide the in-game grid so only bg + start popup show */
.cc-start-open #grid-container {
    display: none;
}

.cc-modal__panel {
    width: min(420px, 92vw);
    background: rgba(20, 36, 58, 0.92);
    border: 1px solid rgba(56, 189, 248, 0.18);
    border-radius: 20px;
    box-shadow:
        0 28px 70px rgba(0, 0, 0, 0.52),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    padding: 22px 20px;
    position: relative;
}

.cc-modal__panel--start {
    width: min(380px, 92vw);
    padding: 20px 20px 22px;
    border-radius: 20px;
    background: rgba(20, 36, 58, 0.92);
    border: 1px solid rgba(56, 189, 248, 0.18);
    box-shadow:
        0 28px 70px rgba(0, 0, 0, 0.52),
        0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.cc-start__brand {
    text-align: center;
    margin: 0;
}

.cc-start__logo {
    max-width: 260px;
    width: 90%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.cc-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.cc-start__level-card {
    margin: 0 auto;
    width: 110px;
    height: 110px;
    padding: 6px;
    border-radius: 18px;
    border: 1px solid rgba(14, 165, 233, 0.35);
    background: linear-gradient(145deg, rgba(14, 165, 233, 0.14), rgba(249, 115, 22, 0.1));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.2) inset,
        0 0 28px rgba(14, 165, 233, 0.2);
}

.cc-start__level-number {
    font-size: 44px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.02em;
    text-align: center;
    background: linear-gradient(90deg, #38bdf8, #fb923c);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 0 12px rgba(14, 165, 233, 0.6)) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.cc-start__level-label {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    text-align: center;
    color: rgba(226, 232, 240, 0.7);
    margin-right: -0.2em; /* offset trailing letter-spacing so label is visually centered */
}

.cc-btn--cta {
    padding: 14px 16px;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    border-radius: 12px;
    border: 0;
    background: linear-gradient(90deg, #0ea5e9 0%, #f97316 100%);
    box-shadow:
        0 4px 20px rgba(14, 165, 233, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.15) inset;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.cc-btn--cta:hover {
    transform: translateY(-1px);
    box-shadow:
        0 8px 28px rgba(14, 165, 233, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

.cc-btn--cta:active {
    transform: translateY(0) scale(0.99);
}


.cc-modal__panel::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 20px;
    pointer-events: none;
    background: transparent;
    opacity: 0;
}

.cc-modal__panel > * {
    position: relative;
    z-index: 1;
}

.cc-modal__title {
    margin: 0 0 16px;
    font-size: 20px;
    font-weight: 800;
    color: #fff;
}

.cc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 12px;
    color: rgba(226, 232, 240, 0.88);
    font-size: 13px;
}

.cc-list__item {
    display: flex;
    gap: 12px;
    line-height: 1.4;
}

.cc-badge {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: rgba(148, 163, 184, 0.10);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.cc-dot {
    width: 8px;
    height: 8px;
}
.cc-dot--good {
    border-radius: 999px;
    background: var(--cyan);
    box-shadow: 0 0 6px rgba(34, 211, 238, 0.8);
}
.cc-dot--neutral {
    background: #64748b;
}

.cc-icon--trophy {
    color: var(--yellow);
    filter: none;
}
.cc-icon--trophy-small {
    color: var(--yellow);
}

.is-hidden { display: none !important; }

/* Custom Animations */
@keyframes pulse-glow {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(0.95); }
}
.animate-pulse-slow {
    animation: pulse-glow 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* SVG styling helpers (avoid style="...") */
.cc-seg {
    transition: filter 0.3s ease, color 0.3s ease;
    color: #475569;
}
.cc-seg--connected {
    color: var(--cyan);
    filter: drop-shadow(0 0 3px rgba(34, 211, 238, 0.6));
}

.cc-tile__svg .cc-line {
    stroke: currentColor;
    stroke-linecap: round;
}
.cc-tile__svg .cc-dot {
    fill: currentColor;
}
.cc-tile__svg .cc-line--connected { stroke-width: 8; }
.cc-tile__svg .cc-line--loose { stroke-width: 6; }

.cc-tile__svg .cc-center-dot {
    fill: #334155;
}
.cc-tile__svg .cc-center-dot--solved {
    fill: var(--cyan);
}

/* Disable tap highlight on mobile */
button {
    -webkit-tap-highlight-color: transparent;
}

/* ================================
   Responsive layout
   ================================ */

/* Tablet landscape (769px–1024px) */
@media (max-width: 1024px) {
    .cc-stage {
        transform: scale(0.95);
        transform-origin: center center;
    }
}

/* Tablet portrait (641px–768px) */
@media (max-width: 768px) {
    .cc-stage {
        transform: scale(0.9);
        transform-origin: center center;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .cc-stage {
        transform: scale(0.85);
        transform-origin: center center;
    }

    .cc-topbar {
        top: 10px;
        left: 10px;
        right: 10px;
    }
}

/* Small mobile (≤480px) */
@media (max-width: 480px) {
    .cc-stage {
        transform: scale(0.8);
        transform-origin: center center;
    }

    .cc-topbar__left,
    .cc-topbar__right {
        gap: 6px;
    }

    .cc-level-indicator__value {
        font-size: 14px;
        letter-spacing: 0.10em;
    }
}

/* Landscape mobile */
@media (max-width: 640px) and (orientation: landscape) {
    .cc-stage {
        transform: scale(0.78);
        transform-origin: center center;
    }

    .cc-app {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .cc-topbar {
        top: 6px;
    }
}