:root {
  --cell-selected: #ffda00;
  --word-highlight: #a7d8ff;
  --clue-bar: #dcefff;
  --check-blue: #2860d8;
  --wrong-red: #e63333;
  --key: #d3d6da;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.timer-wrap { display: flex; align-items: center; gap: 6px; }
.timer { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; min-width: 44px; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px; display: flex; }
.icon-btn svg { width: 18px; height: 18px; fill: var(--ink); }
.menus { display: flex; gap: 4px; }
.menu { position: relative; }
.menu-btn {
  background: none;
  border: 0;
  font-size: 15px;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.menu-btn:hover, .menu-btn.open { background: #f0f0f0; }
.menu-list {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  min-width: 150px;
  z-index: 20;
  padding: 4px 0;
}
.menu-list.open { display: block; }
.menu-list button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: 0;
  text-align: left;
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
}
.menu-list button:hover { background: #f3f3f3; }
.checkmark::after { content: ""; }
.checkmark.on::after { content: "✓"; font-weight: 700; }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  display: flex;
  gap: 40px;
  justify-content: center;
  align-items: flex-start;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}
.puzzle { width: 100%; max-width: 480px; }

.clue-bar {
  display: flex;
  align-items: center;
  background: var(--clue-bar);
  border-radius: 4px;
  min-height: 60px;
  margin-bottom: 16px;
}
.clue-text { flex: 1; font-size: 17px; padding: 10px 4px; line-height: 1.3; }
.clue-text b { margin-right: 8px; }
.clue-arrow { background: none; border: 0; cursor: pointer; padding: 0 10px; height: 60px; display: flex; align-items: center; }
.clue-arrow svg { width: 22px; height: 22px; }

.grid-wrap { position: relative; container-type: inline-size; }
.grid {
  display: grid;
  grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n, 5), minmax(0, 1fr));
  border: 3px solid var(--ink);
  background: var(--ink);
  gap: 1px;
  aspect-ratio: 1;
  width: 100%;
  user-select: none;
  touch-action: manipulation;
}
.grid.blurred { filter: blur(10px); }
.cell {
  position: relative;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}
.cell.black { background: var(--ink); cursor: default; }
.cell.word { background: var(--word-highlight); }
.cell.selected { background: var(--cell-selected); }
.cell .num {
  position: absolute;
  top: 3%;
  left: 5%;
  /* scale with the square size so 5x5 through 15x15 grids all read well */
  font-size: max(7px, calc(100cqw / var(--n, 5) * 0.27));
  font-weight: 500;
  line-height: 1;
}
.cell .letter {
  font-size: calc(100cqw / var(--n, 5) * 0.58);
  font-weight: 400;
  line-height: 1;
  margin-top: 10%;
  text-transform: uppercase;
}
.cell.checked .letter { color: var(--check-blue); }
.cell.wrong::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent calc(50% - 1.5px), var(--wrong-red) calc(50% - 1.5px), var(--wrong-red) calc(50% + 1.5px), transparent calc(50% + 1.5px));
  pointer-events: none;
}
.cell.revealed::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-style: solid;
  border-width: 0 12px 12px 0;
  border-color: transparent var(--wrong-red) transparent transparent;
}
.cell.revealed .letter { color: var(--check-blue); }
.grid.solved .cell:not(.black) { animation: solved-wave 0.6s ease-in-out both; }
@keyframes solved-wave {
  50% { transform: scale(1.08); background: var(--word-highlight); }
}

.paused {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
}
.paused[hidden] { display: none; }

/* ---------- Clue lists ---------- */
.clue-lists { display: flex; gap: 28px; width: 100%; max-width: 440px; }
.clue-col { flex: 1; min-width: 0; }
.clue-col h2 {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.clue-col ol { list-style: none; margin: 0; padding: 0; }
.clue-col li {
  display: flex;
  gap: 10px;
  padding: 8px 10px 8px 8px;
  font-size: 16px;
  line-height: 1.3;
  cursor: pointer;
  border-left: 8px solid transparent;
  border-radius: 2px;
}
.clue-col li b { min-width: 16px; }
.clue-col li.active { background: var(--word-highlight); }
.clue-col li.cross { border-left-color: var(--word-highlight); }
.clue-col li.done { color: #959595; }

/* ---------- On-screen keyboard (touch devices) ---------- */
.keyboard { display: none; padding: 8px 4px 12px; background: #f4f4f4; }
.keyboard .row { display: flex; justify-content: center; gap: 5px; margin-bottom: 7px; }
.keyboard button {
  flex: 1;
  max-width: 44px;
  height: 52px;
  border: 0;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  font-size: 19px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
.keyboard button:active { background: var(--key); }
.keyboard button.wide { max-width: 70px; flex: 1.5; font-size: 13px; }
.keyboard svg { width: 22px; height: 22px; }


.modal .star { font-size: 48px; color: var(--check-blue); line-height: 1; margin-bottom: 8px; }

/* ---------- Bigger grids (Midi, Daily) ---------- */
body.big .layout { max-width: 1240px; gap: 32px; }
body.big .puzzle { max-width: 560px; }
body.big.daily .puzzle { max-width: 640px; }
body.big .clue-lists { max-width: 560px; }
body.big .clue-col ol { max-height: min(640px, 70vh); overflow-y: auto; overscroll-behavior: contain; }
body.big .clue-col li { font-size: 15px; padding: 6px 8px 6px 6px; }
body.big .clue-col li b { min-width: 22px; }
body.big .grid { border-width: 2px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; align-items: center; padding-top: 12px; gap: 24px; }
  .clue-lists { max-width: 480px; }
}

@media (pointer: coarse), (max-width: 600px) {
  body.touch .keyboard { display: block; }
  body.touch .layout { padding-top: 12px; padding-bottom: 12px; }
  body.touch .puzzle { max-width: min(480px, calc(100dvh - 400px)); }
  body.touch .clue-bar { min-height: 52px; margin-bottom: 12px; }
  body.touch .clue-lists { display: none; }
  .home-label { display: none; }
  .topbar h1 { font-size: 22px; }
}
@media (max-width: 380px) {
  .topbar .pill.small { padding: 0 10px; font-size: 13px; }
  .menu-btn { padding: 8px 6px; font-size: 14px; }
}
