:root {
  --bg: #f5f4f1;
  --fg: #2b3138;
  --muted: #7c848d;
  --line: #d3d6da;
  --board-bg: #ffffff;
  --cell-bg: #eceff1;
  --cell-on: #2f3b46;
  --cell-mark: #9aa3ab;
  --rule: #b6bcc3;
  --rule-strong: #79828b;
  --accent: #c2603c;
  --btn-bg: #3c4650;
  --btn-fg: #f7f8f9;
  --sheet-bg: #ffffff;

  --pad-x: clamp(10px, 4vmin, 28px);
  --app-max: 440px;

  /* 판을 그릴 때 자바스크립트가 채운다. 칸 너비를 정수 픽셀로 끊어야 칸마다 폭이
     갈리지 않는다. */
  --cell: 24px;
  --clue: 16px;
  --clue-font: 11px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --fg: #dfe3e7;
    --muted: #838c95;
    --line: #2c3136;
    --board-bg: #1c1f23;
    --cell-bg: #262b30;
    --cell-on: #d8dde2;
    --cell-mark: #6b747d;
    --rule: #3a4147;
    --rule-strong: #6d767e;
    --accent: #e08055;
    --btn-bg: #333c45;
    --sheet-bg: #1f2327;
  }
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  display: flex;
  justify-content: center;
  padding: clamp(10px, 3vmin, 24px) var(--pad-x);
}

.app {
  width: min(100%, var(--app-max));
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 2vmin, 14px);
}

/* 헤더 배치는 모든 게임이 같다. */
.title-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.title-row h1 { text-align: center; }
.title-row .head-nav { justify-self: start; }
.head-nav { display: flex; align-items: center; gap: 14px; }
.title-row .head-actions { justify-self: end; }

h1 {
  margin: 0;
  font-size: clamp(20px, 5.2vmin, 30px);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.head-actions { display: flex; align-items: baseline; gap: 14px; }

.toggle {
  border: 0; background: none; padding: 0;
  color: inherit; font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; opacity: 0.6;
}
.toggle:hover { opacity: 1; }
.toggle.sound { font-size: 12px; }
.toggle.sound[aria-pressed="false"] { opacity: 0.38; text-decoration: line-through; }

.back {
  color: inherit; opacity: 0.6; text-decoration: none;
  font-size: 14px; font-weight: 600;
}
.back:hover { opacity: 1; }

.picker-row { display: flex; align-items: center; gap: 10px; }
.picker { display: flex; gap: 4px; }

.pick {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: inherit;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
}
.pick[aria-pressed="true"] {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-fg);
}

.best { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); }
.timer { font-size: 12px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }

.board-wrap { position: relative; }

/* 판은 네 칸짜리 격자다: 빈 모서리 · 위 힌트 · 왼쪽 힌트 · 칸들. */
.board {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  padding: 8px;
  border-radius: 14px;
  background: var(--board-bg);
  /* 끌어서 칠하므로 스크롤·확대에 넘기지 않는다. 이 자리에는 click으로 도는 조작을
     두지 않는다 — shared/base.js가 touchend를 취소해 click이 나지 않는다. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.col-clues { display: grid; grid-auto-flow: column; }
.col-clues .clue-line {
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  width: var(--cell);
}
.row-clues { display: grid; }
.row-clues .clue-line {
  display: flex; justify-content: flex-end; align-items: center;
  height: var(--cell);
}

.clue-line span {
  display: flex; align-items: center; justify-content: center;
  width: var(--clue); height: var(--clue);
  font-size: var(--clue-font); font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 다 맞춘 줄은 숫자를 흐린다. 남은 줄만 눈에 들어오게 하려는 것이고, 이 게임에서
   "어디까지 했나"의 절반은 이 표시로 읽힌다. */
.clue-line.done span { opacity: 0.3; }

.cells {
  display: grid;
  border-top: 1px solid var(--rule-strong);
  border-left: 1px solid var(--rule-strong);
}

.cell {
  width: var(--cell); height: var(--cell);
  background: var(--cell-bg);
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  position: relative;
}
/* 다섯 칸마다 굵은 줄. 칸을 세지 않고도 자리를 짚을 수 있다. */
.cell.block-x { border-right-color: var(--rule-strong); }
.cell.block-y { border-bottom-color: var(--rule-strong); }

.cell.on { background: var(--cell-on); }
/* 가위표는 글자가 아니라 선 두 개다. 글꼴에 따라 모양이 달라지지 않게. */
.cell.off::before, .cell.off::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 54%; height: 2px; margin: -1px 0 0 -27%;
  background: var(--cell-mark);
  border-radius: 2px;
}
.cell.off::before { transform: rotate(45deg); }
.cell.off::after { transform: rotate(-45deg); }

/* 다 푼 판. 메모로 친 가위표를 감춰 그림만 남긴다 — 이 그림이 이 놀이의 보상이다. */
.board.solved .cell.off::before, .board.solved .cell.off::after { display: none; }

.toast {
  margin: 0; min-height: 20px;
  font-size: 13px; font-weight: 700; text-align: center; color: var(--muted);
}
.toast b { color: var(--fg); }

/* 도움말의 차례 그림. 판에서 쓰는 것과 같은 모양이라야 설명이 된다. */
.cycle-row { list-style: none; margin-left: -18px; }
.cycle { display: inline-flex; align-items: center; gap: 20px; padding-left: 2px; }
.cycle-box {
  position: relative;
  width: 24px; height: 24px;
  background: var(--cell-bg);
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
}
.cycle-box + .cycle-box::before {
  content: '→';
  position: absolute; left: -16px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted); font-size: 11px;
}
.cycle-box.on { background: var(--cell-on); }
.cycle-box.off::after {
  content: '';
  position: absolute; inset: 0;
  background:
    linear-gradient(to bottom right, transparent calc(50% - 1px), var(--cell-mark) calc(50% - 1px), var(--cell-mark) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom left, transparent calc(50% - 1px), var(--cell-mark) calc(50% - 1px), var(--cell-mark) calc(50% + 1px), transparent calc(50% + 1px));
}

.pad { display: flex; }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }

.tool {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: none;
  color: inherit;
  font-family: inherit;
  padding: 8px 4px;
  cursor: pointer;
}
.tool-icon { display: block; }
.tool-icon svg { width: 19px; height: 19px; }
.tool-label { font-size: 11px; font-weight: 600; opacity: 0.8; }
.tool:disabled { opacity: 0.35; cursor: default; }

.btn {
  flex: 1;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

/* 도움말 시트. 껍데기는 shared/sheet.css, 결과 덮개는 shared/result.css. */
.sheet {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--sheet-bg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet[hidden] { display: none; }

.sheet-title { margin: 0; font-size: 19px; font-weight: 800; }
.sheet-note { margin: 0; font-size: 14px; color: var(--muted); }
.sheet-actions { display: flex; gap: 8px; }

.help-list { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.7; }
.help-list li { margin-bottom: 6px; }
