@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&display=swap');

  :root {
    --bg: #060907;
    --panel: #0c110c;
    --line: #1c3620;
    --line-bright: #35803f;
    --text: #c8f7c5;
    --text-dim: #82b57f;
    --amber: #ffb454;
    --cursor: #eafff0;
    --glow: rgba(200, 247, 197, 0.55);
  }

  * {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
  }

  button, select, input, .debug-label {
    touch-action: manipulation;
  }

  @media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  }

  body {
    margin: 0;
    background: var(--bg);
    background-image:
      radial-gradient(ellipse at center, rgba(53,128,63,0.06), transparent 70%);
    color: var(--text);
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 14px 16px;
    position: relative;
  }

  body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
      to bottom,
      rgba(0,0,0,0) 0px,
      rgba(0,0,0,0) 2px,
      rgba(0,0,0,0.10) 3px
    );
    mix-blend-mode: multiply;
    opacity: 0.5;
  }

  .crt {
    width: min(940px, 100%);
    position: relative;
    z-index: 1;
  }

  .prompt-line {
    font-size: 12px;
    color: var(--text-dim);
    letter-spacing: 0.5px;
    margin-bottom: 4px;
  }
  .caret {
    display: inline-block;
    width: 7px;
    height: 12px;
    background: var(--cursor);
    margin-left: 4px;
    vertical-align: -2px;
    animation: blink 1.1s steps(1) infinite;
  }
  @keyframes blink { 50% { opacity: 0; } }

  .titlebar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid var(--line-bright);
    padding-bottom: 8px;
    margin-bottom: 10px;
  }
  .titlebar h1 {
    font-size: 18px;
    letter-spacing: 3px;
    margin: 0;
    font-weight: 600;
    color: var(--amber);
    text-shadow: 0 0 10px rgba(255,180,84,0.35);
  }
  .titlebar .sub { color: var(--text-dim); font-size: 12px; letter-spacing: 1px; }

  .layout {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: 20px;
  }
  @media (max-width: 720px) {
    .layout { grid-template-columns: 1fr; }
    .side { height: auto; }
    .side .legend-panel { flex: none; }
    .row { padding: 4px 0; }
    input[type="checkbox"] { width: 20px; height: 20px; }
  }
  @media (max-width: 460px) {
    body { padding: 10px 10px; }
    .titlebar h1 { font-size: 15px; letter-spacing: 2px; }
    .prompt-line { display: none; }
    .legend { grid-template-columns: 1fr; }
  }

  .panel {
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 12px 14px;
    position: relative;
  }

  .cornered { position: relative; }
  .cornered::before, .cornered::after {
    position: absolute;
    color: var(--line-bright);
    font-size: 13px;
    line-height: 1;
    pointer-events: none;
  }
  .cornered::before { content: '┌'; top: -1px; left: -1px; }
  .cornered::after { content: '┘'; bottom: -1px; right: -1px; }

  .board-wrap { position: relative; }

  .board-frame {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  .board-row {
    display: flex;
    gap: 4px;
  }
  .header-spacer {
    width: 20px;
    flex-shrink: 0;
  }
  .col-headers {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
  }
  .col-headers span {
    text-align: center;
    color: var(--text-dim);
    font-size: 11px;
    letter-spacing: 1px;
  }
  .row-headers {
    display: grid;
    grid-template-rows: repeat(8, 1fr);
    width: 20px;
    flex-shrink: 0;
  }
  .row-headers span {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 11px;
  }

  .board-square-wrap {
    flex: 1;
    min-width: 0;
  }

  #board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    width: 100%;
    aspect-ratio: 1;
    user-select: none;
  }

  .cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a120a;
    border: 1px dashed var(--line);
    font-size: var(--cell-font-size, 22px);
    line-height: 1;
    font-weight: 600;
    cursor: grab;
    position: relative;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    transition: border-color 0.15s ease, background 0.15s ease;
    aspect-ratio: 1;
  }
  .cell:hover { border-color: var(--line-bright); background: rgba(53,128,63,0.16); }

  .cell.selected {
    border-style: solid;
    border-color: var(--cursor);
    box-shadow: 0 0 10px 1px var(--glow) inset;
  }

  .cell:focus-visible {
    outline: 2px solid var(--cursor);
    outline-offset: 2px;
  }
  button:focus-visible,
  select:focus-visible,
  input:focus-visible,
  .debug-label:focus-within {
    outline: 2px solid var(--amber);
    outline-offset: 2px;
  }
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .cell.matched-glow { animation: glow 0.38s ease-in-out; }
  @keyframes glow {
    0% { box-shadow: none; }
    50% { box-shadow: 0 0 14px 3px currentColor inset, 0 0 10px 2px currentColor; }
    100% { box-shadow: 0 0 14px 3px currentColor inset, 0 0 10px 2px currentColor; }
  }

  .cell.clearing { animation: pop 0.22s ease forwards; }
  @keyframes pop {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.25); opacity: 0; }
  }

  .cell.hint { animation: pulse 0.7s ease-in-out infinite; }
  @keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 1px var(--amber) inset; }
    50% { box-shadow: 0 0 10px 2px var(--amber) inset; }
  }

  .status-line {
    margin-top: 8px;
    min-height: 18px;
    color: var(--text-dim);
    font-size: 12px;
    letter-spacing: 0.5px;
  }
  .status-line.active { color: var(--amber); }

  .side {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  .side h2 {
    font-size: 12px;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin: 0 0 10px 0;
    font-weight: 600;
  }
  .side .panel { margin-bottom: 12px; flex-shrink: 0; }
  .side .legend-panel {
    margin-bottom: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  .side .legend-panel .legend { align-content: start; }

  .score-display { font-size: 30px; color: var(--amber); font-weight: 700; text-shadow: 0 0 10px rgba(255,180,84,0.3); }
  .combo-tag {
    font-size: 12px;
    color: #ff9a7a;
    min-height: 16px;
    display: block;
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.5s ease;
  }
  .combo-tag.show { opacity: 1; }
  .combo-tag.fadeout { opacity: 0; }

  .row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
  }
  .row label { color: var(--text-dim); }
  .row input[type="number"] {
    width: 48px;
    background: #080d08;
    border: 1px solid var(--line);
    color: var(--text);
    font-family: inherit;
    padding: 3px 4px;
    text-align: center;
  }
  select {
    background: #080d08;
    border: 1px solid var(--line);
    color: var(--text);
    font-family: inherit;
    padding: 3px 4px;
  }
  input[type="checkbox"] { accent-color: var(--amber); }

  button {
    width: 100%;
    background: #080d08;
    border: 1px solid var(--line-bright);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    letter-spacing: 1px;
    padding: 9px 6px;
    cursor: pointer;
    margin-top: 6px;
    transition: background 0.15s, color 0.15s;
  }
  button:hover { background: var(--line-bright); color: #06110a; }
  button:disabled { opacity: 0.35; cursor: not-allowed; }
  button.primary { border-color: var(--amber); color: var(--amber); }
  button.primary:hover { background: var(--amber); color: #1a0f00; }

  .legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: min-content;
    gap: 6px;
    font-size: 12px;
    min-height: calc(4 * 1.6em);
  }
  .legend div { display: flex; align-items: center; gap: 6px; color: var(--text-dim); }
  .legend span.glyph { font-size: 15px; width: 16px; text-align: center; }

  .footer-note {
    margin-top: 10px;
    border-top: 1px solid var(--line);
    padding-top: 8px;
  }

  .board-footnote {
    margin-top: 6px;
    color: var(--text-dim);
    font-size: 11px;
    line-height: 1.5;
  }

  .debug-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
    font-size: 12px;
    color: var(--text-dim);
    flex-wrap: wrap;
  }
  .debug-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    white-space: nowrap;
  }
  .debug-shapes {
    display: none;
    gap: 6px;
    flex-wrap: wrap;
  }
  .debug-shapes button {
    width: auto;
    margin: 0;
    padding: 4px 9px;
    font-size: 15px;
    line-height: 1;
    opacity: 0.35;
    cursor: not-allowed;
    background: #080d08;
  }
  .debug-shapes button.active {
    opacity: 1;
    cursor: pointer;
  }
  .debug-shapes button.active:hover {
    background: var(--line-bright);
  }

  /* confirm modal */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
  }
  .modal-backdrop.open { display: flex; }
  .modal-box {
    background: var(--panel);
    border: 1px solid var(--line-bright);
    padding: 18px 22px;
    min-width: 260px;
    max-width: 90vw;
    font-size: 13px;
  }
  .modal-box .modal-heading {
    color: var(--amber);
    font-size: 12px;
    letter-spacing: 2px;
    margin-bottom: 10px;
  }
  .modal-box .modal-body-text { color: var(--text); line-height: 1.5; }
  .modal-box .modal-body-sub { color: var(--text-dim); font-size: 11px; margin-top: 4px; }
  .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
  .modal-actions button { flex: 1; }
  #confirmYes { border-color: var(--amber); color: var(--amber); }
  #confirmYes:hover { background: var(--amber); color: #1a0f00; }
