:root {
    --background-color: #f0f2f5;
    --puzzle-background: #ffffff;
    --cell-border: transparent;
    --cell-text: #111827;
    --highlight-color: #e0f2fe;
    --active-cell-color: #bae6fd;
    --clue-text: #4b5563;
    --clue-hover: #f3f4f6;
    --font-sans: 'Inter', sans-serif;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
    --correct-word-color: #a7f3d0;
    --incorrect-word-color: #fca5a5;
}


/* ─── Dark mode ─────────────────────────────────────────────────────────────── */

[data-theme="dark"] {
    --background-color:    #111827;
    --puzzle-background:   #1f2937;
    --highlight-color:     #1e3a5f;
    --active-cell-color:   #1d4ed8;
    --cell-text:           #f9fafb;
    --clue-text:           #d1d5db;
    --clue-hover:          #374151;
    --correct-word-color:  #065f46;
    --incorrect-word-color:#7f1d1d;
}

[data-theme="dark"] #endgame-dialog {
    background: #1f2937;
    color: #f9fafb;
}

[data-theme="dark"] .endgame-copy-btn {
    background: #374151;
    color: #f9fafb;
}

[data-theme="dark"] .endgame-copy-btn:hover {
    background: #4b5563;
}

[data-theme="dark"] #endgame-close {
    color: #6b7280;
}

[data-theme="dark"] #endgame-close:hover {
    color: #d1d5db;
    background: #374151;
}

[data-theme="dark"] .kb-key {
    background: #374151;
    color: #f9fafb;
}

/* ─── Base ──────────────────────────────────────────────────────────────────── */

body {
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--cell-text);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
}

/* Keep shared layout elements full-bleed on play view */
.site-header,
.site-footer,
.ad-wrapper,
.mobile-clue-bar {
    width: 100%;
}

/* ─── Mobile clue bar — hidden on desktop ───────────────────────────────────── */

.mobile-clue-bar {
    display: none;
}


/* ─── Desktop layout ────────────────────────────────────────────────────────── */

.crossword-container {
    display: flex;
    gap: 40px;
    padding: 20px;
    width: 100%;
    max-width: 1200px;
    height: calc(100vh - 40px);
    box-sizing: border-box;
}

.puzzle {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10px;
    min-width: 0;
}

#puzzle-title {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--cell-text);
}

#puzzle-grid {
    display: grid;
    width: min(calc(100vh - 380px), calc(100vw - 400px));
    aspect-ratio: 1 / 1;
    gap: 3px;
}


/* ─── Cells ─────────────────────────────────────────────────────────────────── */

.cell {
    position: relative;
    aspect-ratio: 1 / 1;
    background-color: var(--puzzle-background);
    box-sizing: border-box;
    box-shadow: var(--box-shadow);
    border-radius: 4px;
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    cursor: pointer;
}

/* Empty cells (not part of any word) */
.cell:not(:has(.cell-letter)) {
    background-color: transparent;
    box-shadow: none;
    pointer-events: none;
    cursor: default;
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: clamp(7px, 1vw, 11px);
    font-weight: 600;
    color: var(--clue-text);
    line-height: 1;
    pointer-events: none;
}

/* Letter display — absolutely positioned to fill cell */
.cell-letter {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(12px, 2.2vw, 20px);
    font-weight: 600;
    color: var(--cell-text);
    user-select: none;
    pointer-events: none;
}


/* ─── Highlight states ──────────────────────────────────────────────────────── */

.cell.highlight {
    background-color: var(--highlight-color);
}

.cell.active {
    background-color: var(--active-cell-color);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
}


/* ─── Wordle cell states ─────────────────────────────────────────────────────── */

/* Correct letter, wrong position — yellow */
.cell.wordle-present {
    background-color: #fef08a;
}

/* Letter not in answer — grey */
.cell.wordle-absent {
    background-color: #d1d5db;
}

/* Right letter, right spot (wrong word) — light green */
.cell.wordle-correct {
    background-color: #bbf7d0;
}

/*
 * Active word: keep Wordle feedback colors visible; use inset rings for selection
 * (replacing the cell bg with --highlight-color hid gray/yellow/green entirely).
 */
.cell.wordle-absent.highlight {
    background-color: #d1d5db;
    box-shadow: inset 0 0 0 2px var(--highlight-color), var(--box-shadow);
}

.cell.wordle-present.highlight {
    background-color: #fef08a;
    box-shadow: inset 0 0 0 2px var(--highlight-color), var(--box-shadow);
}

.cell.wordle-correct.highlight {
    background-color: #bbf7d0;
    box-shadow: inset 0 0 0 2px var(--highlight-color), var(--box-shadow);
}

.cell.wordle-absent.active {
    background-color: #d1d5db;
    box-shadow: inset 0 0 0 3px var(--active-cell-color), 0 6px 10px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
}

.cell.wordle-present.active {
    background-color: #fef08a;
    box-shadow: inset 0 0 0 3px var(--active-cell-color), 0 6px 10px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
}

.cell.wordle-correct.active {
    background-color: #bbf7d0;
    box-shadow: inset 0 0 0 3px var(--active-cell-color), 0 6px 10px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Word correctly completed — permanent green, not overridable by highlight */
.cell.wordle-locked {
    background-color: #86efac !important;
}

.cell.wordle-locked .cell-letter {
    color: #14532d;
}

/* Dim highlight/active on locked cells so green stays readable */
.cell.wordle-locked.highlight {
    background-color: #86efac !important;
}

.cell.wordle-locked.active {
    background-color: #4ade80 !important;
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
}


/* ─── Clue sidebar ───────────────────────────────────────────────────────────── */

.clues {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 280px;
    max-width: 350px;
    background-color: var(--puzzle-background);
    border-radius: 8px;
    box-shadow: var(--box-shadow);
    padding: 20px;
    box-sizing: border-box;
    height: 100%;
    overflow: hidden;
}

.clue-list-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.clue-list-container h2 {
    margin-top: 0;
    border-bottom: 2px solid var(--background-color);
    padding-bottom: 5px;
    color: var(--cell-text);
}

.clue-list {
    flex-grow: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    margin: 0;
    padding: 5px;
}

.clue-list li {
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    color: var(--clue-text);
    margin-bottom: 2px;
    list-style: none;
    font-size: 14px;
}

.clue-list li:hover {
    background-color: var(--clue-hover);
}

.clue-list li.active {
    font-weight: bold;
    color: var(--cell-text);
    background-color: var(--highlight-color);
    box-shadow: inset 3px 0 0 0 var(--cell-text);
}


/* ─── Word completion animations ────────────────────────────────────────────── */

@keyframes correct-hop {
    0%   { transform: scale(1);                   background-color: var(--correct-word-color); }
    30%  { transform: scale(1.2) translateY(-8px); }
    60%  { transform: scale(0.95) translateY(2px); }
    100% { transform: scale(1);                   background-color: var(--correct-word-color); }
}

@keyframes incorrect-shake {
    0%   { transform: translateX(0); }
    20%  { transform: translateX(-5px); }
    40%  { transform: translateX(5px); }
    60%  { transform: translateX(-3px); }
    80%  { transform: translateX(3px); }
    100% { transform: translateX(0); }
}

.cell.correct-word   { animation: correct-hop    0.8s ease-in-out; }
.cell.incorrect-word { animation: incorrect-shake 0.5s ease-in-out; }


/* ─── Victory cascade animation ─────────────────────────────────────────────── */

@keyframes cascade-hop {
  0%   { transform: scale(1);                    background-color: var(--correct-word-color); }
  25%  { transform: scale(1.25) translateY(-10px); background-color: #6ee7b7; }
  55%  { transform: scale(0.93) translateY(3px);  }
  80%  { transform: scale(1.05);                  }
  100% { transform: scale(1);                    background-color: var(--correct-word-color); }
}

.cell.cascade-win {
  animation: cascade-hop 0.75s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  background-color: var(--correct-word-color) !important;
}


/* ─── Endgame overlay & dialog ───────────────────────────────────────────────── */

#endgame-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#endgame-overlay.visible {
  opacity: 1;
}

#endgame-dialog {
  position: relative;
  background: #ffffff;
  border-radius: 20px;
  padding: 40px 36px 32px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: 0 24px 60px rgba(0,0,0,0.18), 0 8px 20px rgba(0,0,0,0.1);
  text-align: center;
  transform: scale(0.88) translateY(20px);
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
}

#endgame-overlay.visible #endgame-dialog {
  transform: scale(1) translateY(0);
}

#endgame-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 18px;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

#endgame-close:hover {
  color: #374151;
  background: #f3f4f6;
}

.endgame-trophy {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 12px;
  animation: trophy-bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s both;
}

@keyframes trophy-bounce {
  from { transform: scale(0.4) rotate(-15deg); opacity: 0; }
  to   { transform: scale(1)   rotate(0deg);   opacity: 1; }
}

.endgame-title {
  font-family: var(--font-sans);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--cell-text);
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

.endgame-subtitle {
  font-size: 0.85rem;
  color: #6b7280;
  margin: 0 0 28px;
}

.endgame-stats {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 28px;
}

.stat-card {
  flex: 1;
  background: var(--background-color);
  border-radius: 12px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--cell-text);
  letter-spacing: -0.02em;
  line-height: 1;
}

.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.endgame-btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.endgame-share-btn,
.endgame-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 50px;
  padding: 13px 28px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  box-shadow: 0 4px 14px rgba(17,24,39,0.2);
}

.endgame-share-btn {
  background: var(--cell-text);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(17,24,39,0.25);
}

.endgame-copy-btn {
  background: #f3f4f6;
  color: #111827;
}

.endgame-share-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(17,24,39,0.3);
}

.endgame-copy-btn:hover {
  background: #e5e7eb;
  transform: translateY(-2px);
}

.endgame-share-btn:active,
.endgame-copy-btn:active {
  transform: translateY(0);
}

.share-icon,
.copy-icon {
  font-style: normal;
  font-size: 1rem;
}

.endgame-copy-msg {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: #10b981;
  min-height: 1.2em;
}


/* ─── On-screen Wordle keyboard ─────────────────────────────────────────────── */

#wordle-keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  width: 100%;
  max-width: min(calc(100vh - 380px), calc(100vw - 400px));
}

.kb-row {
  display: flex;
  gap: 5px;
  justify-content: center;
  width: 100%;
}

.kb-key {
  flex: 1;
  max-width: 44px;
  height: 42px;
  padding: 0 4px;
  background: #e5e7eb;
  border: none;
  border-radius: 5px;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--cell-text);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, opacity 0.1s;
}

.kb-key:active {
  opacity: 0.65;
}

.kb-wide {
  flex: 1.4;
  max-width: 60px;
}

.kb-key.kb-correct { background-color: #86efac; color: #14532d; }
.kb-key.kb-present { background-color: #fef08a; color: #713f12; }
.kb-key.kb-absent  { background-color: #9ca3af; color: #ffffff; }


@media (max-width: 640px) {
    body {
        justify-content: flex-start;
        align-items: stretch;
        padding-top: 50px;
    }

    /* Sticky clue bar — body has no overflow so window is the scroll container; sticky works */
    .mobile-clue-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        position: sticky;
        top: 0;
        z-index: 9999;
        width: 100%;
        padding: 10px 14px;
        margin-top: 5px;
        box-sizing: border-box;
        background-color: var(--active-cell-color);
        border-bottom: 2px solid #7dd3fc;
        min-height: 50px;
    }

    .mobile-clue-text {
        flex: 1;
        font-size: 13px;
        font-weight: 500;
        color: var(--cell-text);
        line-height: 1.4;
    }

    .mobile-next-btn {
        flex-shrink: 0;
        background: var(--cell-text);
        color: #fff;
        border: none;
        border-radius: 20px;
        padding: 6px 14px;
        font-size: 13px;
        font-weight: 600;
        font-family: var(--font-sans);
        cursor: pointer;
        white-space: nowrap;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-next-btn:active {
        opacity: 0.7;
    }

    /* Stack layout vertically */
    .crossword-container {
        flex-direction: column;
        height: auto;
        gap: 0;
        padding: 12px;
    }

    .puzzle {
        padding: 0;
        width: 100%;
    }

    #puzzle-title {
        font-size: 1.1rem;
        margin-bottom: 10px;
    }

    /* Grid fills full available width */
    #puzzle-grid {
        width: 100%;
        max-width: calc(100vw - 24px);
    }

    .cell-letter {
        font-size: clamp(11px, 4.5vw, 18px);
    }

    .cell-number {
        font-size: clamp(6px, 1.8vw, 9px);
    }

    /* Keep clues visible on mobile and allow scrolling for long lists */
    .clues {
        display: block;
        width: 100%;
        box-sizing: border-box;
        height: auto;
        max-height: calc(100vh - 220px);
        overflow-y: auto;
        margin-top: 18px;
        padding: 14px;
    }

    .clue-list-container {
        flex-grow: 0;
        margin-bottom: 12px;
    }

    .clue-list {
        max-height: none;
    }

    #wordle-keyboard {
        max-width: 100%;
        padding: 0 4px;
    }

    .kb-key {
        height: 46px;
        min-width: 28px;
        font-size: 0.75rem;
    }

    .kb-wide {
        min-width: 40px;
    }
}
