  :root {
    --bg: #0b0e14;
    --panel: #12151f;
    --panel-border: #232838;
    --cell-bg: #171b26;
    --cell-border: #2a3040;
    --text: #e8ebf3;
    --muted: #8a91a8;
    --accent: #7dd3fc;
    --accent-2: #a78bfa;
    --selected: #3b3620;
    --selected-cell: #f2c14e;
    --word-hl: #26314a;
    --correct: #2e7d5b;
    --incorrect: #7d2e3a;
    --black: #05060a;
  }
  * { box-sizing: border-box; }
  html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
    overflow-x: hidden;
    height: 100%;
  }
  body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 12px 60px;
  }
  header {
    width: 100%;
    max-width: 920px;
    text-align: center;
    margin-bottom: 14px;
    flex-shrink: 0;
  }
  h1 {
    font-size: clamp(1.3rem, 4vw, 1.9rem);
    margin: 0 0 4px;
    letter-spacing: 0.5px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
  .subtitle {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0;
  }
  .layout {
    width: 100%;
    max-width: 920px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    flex: 1 1 auto;
    min-height: 0;
  }
  .board-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    min-height: 0;
    max-width: 420px;
  }
  .toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    flex-shrink: 0;
  }
  .toolbar button {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    color: var(--text);
    padding: 7px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
  }
  .toolbar button:hover { border-color: var(--accent); }
  .toolbar button:active { transform: scale(0.96); }
  .status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 420px;
    font-size: 0.8rem;
    color: var(--muted);
  }
  #timer { font-variant-numeric: tabular-nums; color: var(--accent); }
  .grid {
    display: grid;
    gap: 3px;
    background: var(--panel-border);
    border: 2px solid var(--panel-border);
    border-radius: 6px;
    padding: 3px;
    width: min(94vw, 420px);
    aspect-ratio: 1 / 1;
    flex-shrink: 1;
    min-height: 0;
  }
  .cell-wrap {
    position: relative;
    background: var(--cell-bg);
  }
  .cell-wrap.black { background: var(--black); }
  .cell-num {
    position: absolute;
    top: 1px;
    left: 3px;
    font-size: 0.55rem;
    color: var(--muted);
    pointer-events: none;
    user-select: none;
    z-index: 2;
  }
  input.cell {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--text);
    text-align: center;
    font-family: inherit;
    font-weight: 600;
    font-size: var(--cell-font-size, clamp(0.9rem, 3.6vw, 1.3rem));
    line-height: 1;
    text-transform: uppercase;
    caret-color: transparent;
    outline: none;
    border-radius: 3px;
  }
  input.cell:disabled { background: transparent; }
  .cell-wrap.in-word input.cell { background: var(--word-hl); }
  .cell-wrap.active input.cell { background: var(--selected-cell); color: #1a1400; }
  .cell-wrap.correct input.cell { background: var(--correct) !important; color: #eafff2; }
  .cell-wrap.incorrect input.cell { background: var(--incorrect) !important; color: #ffeef0; }
  .clue-bar {
    width: min(94vw, 420px);
    min-height: 40px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }
  .clue-bar .dir-badge {
    background: var(--accent-2);
    color: #1a1030;
    font-weight: 700;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
  }
  .clues-toggle-btn {
    display: none;
    margin-left: auto;
    flex-shrink: 0;
    background: var(--cell-bg);
    border: 1px solid var(--panel-border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.7rem;
    padding: 5px 9px;
    border-radius: 6px;
    cursor: pointer;
  }
  .clues-backdrop {
    display: none;
  }
  .clues-header {
    display: none;
  }
  .clues {
    display: flex;
    gap: 16px;
    max-width: 420px;
    width: 100%;
  }
  .clue-list {
    flex: 1;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 10px;
    max-height: 260px;
    overflow-y: auto;
  }
  .clue-list h3 {
    margin: 0 0 6px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
  }
  .clue-item {
    font-size: 0.78rem;
    padding: 4px 6px;
    border-radius: 5px;
    cursor: pointer;
    line-height: 1.35;
  }
  .clue-item:hover { background: var(--cell-bg); }
  .clue-item.active { background: var(--selected); color: var(--selected-cell); }
  .clue-item .n { color: var(--muted); margin-right: 4px; }
  .win-banner {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%) translateY(20px);
    width: min(92vw, 420px);
    background: linear-gradient(90deg, #1c3f2e, #143329);
    border: 1px solid var(--correct);
    color: #d7ffe9;
    padding: 12px 16px;
    border-radius: 10px;
    text-align: center;
    font-size: 0.85rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 80;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  }
  .win-banner.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
  }
  footer {
    margin-top: 24px;
    color: var(--muted);
    font-size: 0.7rem;
    text-align: center;
    flex-shrink: 0;
  }
  @media (max-width: 640px), (max-height: 500px) {
    .layout { flex-direction: column; flex-wrap: nowrap; align-items: center; }
    .clues { flex-direction: column; max-width: min(94vw, 420px); }
    .clue-list { max-height: 140px; }
  }

  /* ---- Small / short viewports: fit everything in one viewport, no page scroll ---- */
  @media (max-width: 640px), (max-height: 500px) {
    html, body { height: 100dvh; overflow: hidden; }
    body { padding: 10px 10px 8px; justify-content: flex-start; }

    header { margin-bottom: 4px; }
    h1 { font-size: 1.1rem; margin-bottom: 0; }
    .subtitle { display: none; }
    .status-row { font-size: 0.7rem; max-width: none; }

    .board-col { gap: 8px; justify-content: center; width: 100%; }

    .grid {
      width: var(--grid-size, min(92vw, 58dvh));
      height: var(--grid-size, min(92vw, 58dvh));
      margin: 0 auto;
      flex-shrink: 0;
    }

    .clue-bar {
      width: 100%;
      max-width: none;
      min-height: unset;
      font-size: 0.75rem;
      padding: 6px 8px;
    }
    .clue-bar #activeClueText {
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    .clues-toggle-btn { display: inline-flex; }

    .toolbar {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 6px;
      width: 100%;
    }
    .toolbar button {
      padding: 6px 2px;
      font-size: 0.62rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    footer { display: none; }

    /* Clue lists collapse into a bottom sheet, off-flow (position:fixed),
       so they never contribute to page scroll height. */
    .clues-backdrop {
      display: block;
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.5);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s;
      z-index: 65;
    }
    .clues-backdrop.open { opacity: 1; pointer-events: auto; }

    .clues-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 0.75rem;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--accent);
      margin-bottom: 8px;
      flex-shrink: 0;
    }
    .clues-header button {
      background: none;
      border: none;
      color: var(--muted);
      font-size: 1.1rem;
      line-height: 1;
      cursor: pointer;
      padding: 2px 6px;
    }

    .clues {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      max-width: none;
      width: 100%;
      flex-direction: column;
      background: var(--panel);
      border-top: 1px solid var(--panel-border);
      border-radius: 14px 14px 0 0;
      padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
      max-height: 70dvh;
      transform: translateY(105%);
      transition: transform 0.25s ease;
      z-index: 70;
      box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
      gap: 10px;
    }
    .clues.open { transform: translateY(0); }
    .clue-list { max-height: none; overflow-y: auto; }
  }
