/* Turing Daily: 작도 격자 위의 한 장짜리 종이 (DESIGN.md). 둥근 모서리, 그림자, 빛 번짐은 없다.
   빨강은 지금 일어나는 것 하나(헤드 위 상태, 지금 쓰이는 규칙)와 실패에만 쓴다. */

:root {
  --sheet: #fbfbf9;
  --ink: #111111;
  --red: #e1251b;
  --cell: #ffffff;
  --hover: #ececE6;
  --ink-hover: #2e2e2e;
  --rule: #cfcfc7;
  --muted: #5e5e58;
  --faint: #a9a9a1;
  --grid: rgba(92, 133, 219, 0.15);
  --grid-major: rgba(92, 133, 219, 0.3);
  --pen: #24366e;
  --note-rule: rgba(92, 133, 219, 0.32);
  --cw: 60px;
  --ch: 60px;
  --side: 40px;
  --gutter: 24px;
  /* 말마다 다른 글꼴 (src/i18n.js). 본문, 그림 속 펜글씨, 격자 글꼴에 없는 이름(한중일)을 쓰는 굵은 글꼴 */
  --sans: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  --hand: Kalam, "Comic Sans MS", cursive;
  --grid-text: var(--sans);
  color-scheme: light;
}

/* 일본어와 중국어는 Pretendard를 쓰지 않는다 (Pretendard의 한자는 한국식 모양이라 가나, 간체와 섞이면 어긋난다) */
:root:lang(ja) {
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans JP", sans-serif;
  --hand: Kalam, Yomogi, cursive;
}

:root:lang(ko) {
  --hand: Kalam, Gaegu, cursive;
}

:root:lang(zh) {
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --hand: Kalam, "LXGW WenKai Lite", cursive;
}

/* 번체(zh-Hant)는 :lang(zh)에도 걸리니 뒤에서 대만 글꼴로 덮는다 */
:root:lang(zh-Hant) {
  --sans: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  --hand: Kalam, "LXGW WenKai TC", cursive;
}

/* 줄은 낱말 사이에서만 바꾼다 (body의 keep-all). 일본어와 중국어는 낱말 사이에 빈칸이 없어 글자 사이에서 바꾼다 */
body:lang(ja),
body:lang(zh) {
  word-break: normal;
}

/* 번역이 들어올 때까지 HTML의 영어 글을 숨긴다 (각 페이지 머리 스크립트가 붙이고 src/i18n.js가 뗀다) */
.i18n-wait [data-i18n] {
  visibility: hidden;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

/* 단추를 빨리 연달아 누르면 (한 걸음, 속도 등) 휴대전화 사파리가 두 번 탭 확대로 알아듣고 화면을 끌어당긴다.
   단추에서만 두 번 탭 확대를 끈다. 두 손가락 확대와 글자를 두 번 탭해 확대하기는 그대로 */
button {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--sheet);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  word-break: keep-all;
  line-break: strict;
}

svg {
  display: block;
  flex: none;
}

[hidden] {
  display: none !important;
}

.spacer {
  flex: 1;
}

.app {
  container: app / inline-size;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 18px var(--gutter) 28px;
}

/* ── 머리 ── */

/* 첫 줄: TURING-DAILY와 오른쪽에 날짜·남은 시간 (신문 제호처럼). 둘째 줄: 난이도와 목표, 오른쪽에 Help·Stats.
   휴대전화처럼 좁으면 아래 @container에서 첫 줄에 단추, 둘째 줄에 날짜, 셋째 줄에 난이도 */
.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 20px;
  row-gap: 10px;
  margin-bottom: 20px;
}

.top > .spacer {
  display: none;
}

.meta,
.meta-line:first-child {
  display: contents;
}

.wordmark {
  display: flex;
  grid-column: 1;
  grid-row: 1;
  margin: 0;
  font-size: inherit;
  line-height: 0;
}

.meta-line + .meta-line {
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  flex-wrap: nowrap;
  min-width: 0;
  max-width: 100%;
}

.top-actions {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
}

.meta-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.wordmark svg {
  color: var(--ink);
}

/* 머리 단추(Today, How-to, Practice, Learn, Stats, About)와 겹치지 않게 TURING-DAILY는 단추 옆에 남는 너비만큼 (제 크기보다 크게는 늘지 않는다) */
.top .wordmark .gt {
  width: 100%;
  max-width: 260px;
  height: auto;
}

.date svg {
  color: var(--muted);
}

/* 날짜와 남은 시간: 오른쪽, TURING-DAILY와 같은 줄 */
.when {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 18px;
  padding-top: 2px;
  min-height: 21px;
}

.clock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

/* 난이도를 한 상자에 */
.facts {
  width: fit-content;
  margin-top: 6px;
  padding: 6px 12px;
  border: 1px solid var(--ink);
  background: var(--cell);
}

.tier {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 14px;
  color: var(--muted);
}

.tier i {
  width: 10px;
  height: 10px;
  border: 2px solid var(--ink);
}

.tier i.on {
  background: var(--ink);
}

.tier span {
  margin-left: 6px;
}

.top-actions {
  display: flex;
  gap: 4px;
}

/* 처음 온 사람에게 ? 단추와 연습 단추를 가리키는 빨간 색연필 동그라미 (하는 법, 연습을 한 번 열면 없어진다).
   단추 둘레로 삐져나오고, 누르는 데는 끼지 않는다. 들어오고 잠깐 뒤 한 번에 그어 나간다 */
#btn-help,
#btn-practice,
.top-actions {
  position: relative;
}

.pencil-ring {
  position: absolute;
  left: -27.27%;
  top: -27.27%;
  width: 154.55%;
  height: 154.55%;
  pointer-events: none;
}

.pencil-ring polyline {
  stroke-dasharray: 1 2;
  stroke-dashoffset: 1.05;
  animation: ring-draw 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.6s forwards;
}

@keyframes ring-draw {
  to {
    stroke-dashoffset: 0;
  }
}

/* 처음 온 사람에게 채울 칸(?)을 가리키는 빨간 색연필 고리와 펜글씨 (칸을 한 번 열면 없어진다). 자리는 app.js가 잰다.
   고리를 다 그은 뒤 펜글씨가 나타난다. 자리만 바뀌어 다시 그을 때(.still)는 움직이지 않는다 */
.fill-hint {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.fill-note {
  position: absolute;
  font: 400 24px/1.1 var(--hand);
  color: var(--red);
  width: max-content;
  transform: rotate(-5deg);
  opacity: 0;
  animation: note-in 0.35s ease-out 1.35s forwards;
}

@keyframes note-in {
  to {
    opacity: 1;
  }
}

.fill-hint.still polyline,
.fill-hint.still .fill-note {
  animation: none;
  stroke-dashoffset: 0;
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .pencil-ring polyline {
    animation: none;
    stroke-dashoffset: 0;
  }

  .fill-note {
    animation: none;
    opacity: 1;
  }
}

/* ── 단추 ── */

.btn,
.submit,
.row,
.opt,
.rt-cell {
  appearance: none;
  font: inherit;
  color: inherit;
  border-radius: 0;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--ink);
  background: var(--cell);
  color: var(--ink);
  cursor: pointer;
}

.btn:hover {
  background: var(--hover);
}

.btn:active {
  background: var(--ink);
  color: var(--sheet);
}

.btn:disabled {
  background: var(--sheet);
  border-color: var(--rule);
  color: var(--faint);
  cursor: default;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.ghost:hover {
  background: var(--hover);
}

.btn.ghost:active {
  background: var(--ink);
  color: var(--sheet);
}

.btn.ghost:disabled {
  background: transparent;
  border-color: transparent;
}

.btn.ghost.armed {
  border-color: var(--red);
  color: var(--red);
}

.btn.text {
  width: auto;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 560;
}

.btn.sq {
  width: 52px;
  height: 52px;
}

.btn.run {
  width: 64px;
  height: 64px;
  background: var(--ink);
  border-color: var(--ink);
  color: var(--sheet);
}

.btn.run:hover {
  background: var(--ink-hover);
}

.btn.run:active {
  background: #000;
}

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--sheet);
}

.btn.primary:hover {
  background: var(--ink-hover);
}

/* 아이콘 아래 짧은 이름이 붙은 단추 */
.btn.labeled {
  flex-direction: column;
  gap: 3px;
  width: auto;
  min-width: 48px;
  height: 50px;
  padding: 0 6px;
}

.btn.labeled .ic {
  width: 22px;
  height: 22px;
}

.btn .cap {
  font-size: 11px;
  font-weight: 560;
  line-height: 1;
  white-space: nowrap;
}

.btn.sq.labeled {
  width: 58px;
  height: 58px;
  padding: 0;
}

.btn.run.labeled {
  width: 70px;
  height: 70px;
  padding: 0;
}

.btn.run.labeled .ic {
  width: 28px;
  height: 28px;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* ── 판 ── */

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 24vw, 340px);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "tape tests"
    "table tests"
    "transport tests";
  gap: 16px;
  align-items: start;
}

/* 구역 안은 모눈이 흐릿하게 비친다: 종이색을 반쯤 덮고 뒤를 살짝 번지게 한다 */
.panel {
  position: relative;
  border: 2px solid var(--ink);
  padding: 12px 16px;
  min-width: 0;
  background: rgba(251, 251, 249, 0.6);
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
}

/* 구역 이름: 위 테두리에 걸쳐 쓰고, 글자 첫 칸을 구역 안쪽 여백에 맞춘다 */
.panel-label {
  position: absolute;
  top: -8px;
  left: 10px;
  padding: 0 6px;
  background: var(--sheet);
  color: var(--muted);
}

.panel-label.end {
  left: auto;
  right: 12px;
}

.panel-label svg {
  display: block;
}

.panel-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.tape-panel {
  grid-area: tape;
}

.table-panel {
  grid-area: table;
  align-self: stretch;
  min-height: 260px;
  container: table / inline-size;
}

/* 표 옆에 자리가 남으면 Undo, Reset을 표 머리 줄 오른쪽으로 올려 한 줄을 아낀다 (참고 해답 표시 줄은 그대로) */
@container table (min-width: 350px) {
  #table-bar:has(#btn-undo),
  #table-bar:empty {
    position: absolute;
    top: 10px;
    right: 14px;
    min-height: 0;
  }

  #table-bar:has(#btn-undo) + .table-scroll,
  #table-bar:empty + .table-scroll {
    margin-top: 0;
  }
}

/* 머리의 격자 글자와 판은 스크립트(app.js)가 그린다. 그리기 전 빈 자리도 그린 뒤와 같은 크기로 잡아 둔다
   (모듈이 늦게 와도 판 아래 글이 밀려 내려가지 않게. Lighthouse의 CLS). 크기는 tape.js, 규칙표 칸(--ch), 예시 다섯 줄, 단추 높이에서 */
.wordmark:not(:has(svg)) {
  min-height: 28px;
}

.date:empty {
  height: 21px;
}

.tier:empty {
  height: 20px;
}

#tape:empty {
  height: 108px;
}

#table:empty {
  height: calc(40px + 3 * var(--ch));
}

#table-bar:empty,
#tries:empty {
  min-height: 50px;
}

.transport:empty {
  min-height: 70px;
}

#rows:empty {
  min-height: 240px;
}

@media (max-width: 760px) {
  .tier:empty {
    height: 10px;
  }

  #tape:empty {
    height: 102px;
  }

  .transport:empty {
    min-height: 86px;
  }
}

@media (max-width: 460px) {
  .wordmark:not(:has(svg)) {
    min-height: 21px;
  }

  .date:empty {
    height: 14px;
  }
}

.tests-panel {
  grid-area: tests;
  align-self: stretch;
  display: flex;
  flex-direction: column;
}

.transport {
  grid-area: transport;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

/* 테이프 오른쪽 위: 지금 돌리는 예시의 입력과 바라는 결과 (예시 목록이 화면 밖이어도 목표가 보이게) */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--ink);
  background: var(--cell);
}

.strip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-wrap: nowrap;
}

/* 격자 글자 A B는 아이콘 칸 가운데 절반만 차지하니, 줄 안에서는 바짝 붙여 한 낱말처럼 읽히게 */
.strip .sym {
  margin-inline: -3px;
}

.tape {
  margin-top: 8px;
  overflow: hidden;
}

/* ── 규칙표 ── */

.table-scroll {
  overflow-x: auto;
  margin-top: 12px;
  padding: 2px 2px 6px;
}

.rule-grid {
  display: grid;
  grid-template-columns: var(--side) repeat(var(--cols), var(--cw));
  width: max-content;
}

.rt-head {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
}

.rt-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  height: var(--ch);
}

.rt-cell {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  padding: 0;
  background: var(--cell);
  border: 0;
  border-left: 2px solid var(--ink);
  border-top: 2px solid var(--ink);
  cursor: pointer;
}

.rt-cell.r {
  border-right: 2px solid var(--ink);
}

.rt-cell.b {
  border-bottom: 2px solid var(--ink);
}

.rt-cell svg {
  width: 100%;
  height: 100%;
}

.rt-cell:hover {
  background: var(--hover);
}

.rt-cell:disabled {
  cursor: default;
}

.rt-cell:disabled:hover {
  background: var(--cell);
}

/* 채워 준 칸: 참고 해답에서 옮겨 와 고칠 수 없다. 인쇄된 칸처럼 옅은 회색 바탕, 고칠 칸만 흰 바탕 */
.rt-cell.given:not(.live) {
  background: var(--hover);
}

.rt-cell.live,
.rt-cell.live:hover {
  background: var(--red);
}

.rt-cell.editing::after,
.rt-cell.missing::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 3px solid var(--ink);
  pointer-events: none;
}

.rt-cell.missing::after {
  border-color: var(--red);
}

.ref-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 560;
}

/* ── 예시 ── */

.rows {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 6px 12px 7px;
  background: transparent;
  border: 2px solid transparent;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  cursor: pointer;
}

.row:hover {
  background: var(--hover);
}

.row.sel {
  background: var(--cell);
  border: 2px solid var(--ink);
  padding-bottom: 6px;
}

.ans {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.res {
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
}

.res.ok {
  background: var(--ink);
}

.res.bad {
  background: var(--red);
  border-color: var(--red);
}

.tests-foot {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.tries {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sq-row {
  display: inline-flex;
  gap: 6px;
  margin-right: auto;
}

.sq-row i {
  width: 18px;
  height: 18px;
  border: 2px solid var(--ink);
}

.sq-row i.ok {
  background: var(--ink);
}

.sq-row i.bad {
  background: var(--red);
  border-color: var(--red);
}

.submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 56px;
  border: 2px solid var(--ink);
  background: var(--cell);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.submit:hover {
  background: var(--hover);
}

.submit:active {
  background: var(--ink);
  color: var(--sheet);
}

.submit:disabled {
  background: var(--sheet);
  border-color: var(--rule);
  color: var(--faint);
  cursor: default;
}

/* ── 편집 창 ── */

.editor {
  position: absolute;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  background: var(--cell);
  border: 2px solid var(--ink);
}

.ed-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ed-read {
  display: inline-flex;
  padding: 6px;
  border: 1px solid var(--ink);
  background: var(--cell);
}

.ed-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.ed-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ed-cap {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  flex: none;
  width: 30px;
  height: 46px;
}

.opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--rule);
  background: var(--cell);
  cursor: pointer;
}

.opt:hover {
  border-color: var(--ink);
}

.opt[aria-pressed="true"] {
  background: var(--hover);
  border: 3px solid var(--ink);
}

/* ── 겹창 ── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(251, 251, 249, 0.88);
}

.card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 60px 24px 24px;
  background: var(--sheet);
  border: 2px solid var(--ink);
}

.card .close {
  position: absolute;
  top: 8px;
  right: 8px;
}

.res-head {
  display: flex;
  justify-content: center;
  margin: 4px 0 18px;
}

.gt-reveal rect {
  opacity: 0;
  animation: cell-in 0.01s forwards;
}

@keyframes cell-in {
  to {
    opacity: 1;
  }
}

.res-goals {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 20px;
}

.res-goals span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.res-goals b {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* 그날 집계: 상위 몇 %, 푼 사람 비율. 받아 오기 전에는 자리만 (높이가 튀지 않게) */
.res-today {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  min-height: 20px;
  margin: -8px 0 18px;
  font-size: 14px;
  color: var(--muted);
}

.res-today b {
  color: var(--ink);
  font-weight: 600;
}

.res-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}

.res-actions .btn {
  width: auto;
  height: 48px;
  padding: 0 18px;
  font-size: 16px;
  font-weight: 700;
}

/* 공유 칸: 카드 미리 보기, SNS 여덟 곳 (판의 칸처럼 먹선을 함께 쓰는 한 줄), 저장·복사 단추 */
.share-box {
  display: grid;
  justify-items: center;
  gap: 14px;
  margin: -8px 0 24px;
}

.share-box[hidden] {
  display: none;
}

.share-preview {
  width: min(100%, 240px);
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  background: var(--sheet);
}

.share-preview img {
  display: block;
  width: 100%;
  height: 100%;
}

.share-sns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  border: 2px solid var(--ink);
  background: var(--cell);
}

.sns {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  padding: 0;
  border: 0;
  border-left: 2px solid var(--ink);
  background: var(--cell);
  color: var(--ink);
  cursor: pointer;
}

.sns:first-child {
  border-left: 0;
}

.share-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.sns:hover {
  background: var(--hover);
}

.sns:active {
  background: var(--ink);
  color: var(--sheet);
}

/* 저장·복사 단추는 같은 너비로 둘씩. 하나 남으면 한 줄을 다 쓴다 */
.share-tools {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

.share-tools .btn {
  width: 100%;
  height: 44px;
}

.share-tools .btn:last-child:nth-child(odd) {
  grid-column: span 2;
}

/* 좁으면 SNS 줄을 넷씩 두 줄로 (칸이 손가락보다 작아지지 않게) */
@media (max-width: 480px) {
  .share-sns {
    grid-template-columns: repeat(4, 1fr);
  }

  .sns:nth-child(5) {
    border-left: 0;
  }

  .sns:nth-child(n + 5) {
    border-top: 2px solid var(--ink);
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 16px 0;
  border-top: 2px solid var(--ink);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat b {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat span {
  font-size: 13px;
  color: var(--muted);
}

/* 제출 횟수 분포. 서버가 있으면 두 칸: 내 기록(날 수)과 오늘 모두(끝낸 사람 가운데 %), 같은 줄끼리 나란히 */
.dist {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 4px 8px;
  align-items: center;
  padding-bottom: 16px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.dist.crowd {
  grid-template-columns: 16px 1fr 1fr;
}

.dist-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
  margin-bottom: 2px;
  font-size: 13px;
  font-weight: 600;
}

.dist-head em {
  font-style: normal;
  font-weight: 400;
  color: var(--muted);
}

.bar {
  display: block;
  justify-self: start;
  width: var(--w);
  min-width: 24px;
  padding: 1px 6px;
  background: var(--rule);
  text-align: right;
}

.bar b {
  font-size: 13px;
  font-weight: 700;
}

.bar.mine {
  background: var(--ink);
  color: var(--sheet);
}

.next {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 2px solid var(--ink);
  font-size: 14px;
  color: var(--muted);
}

.next b {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.acct {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
}

.acct span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn.wide {
  width: 100%;
  height: 48px;
}

/* 구글 로그인: 단추 아래에 까닭을 작게 */
.acct.signin {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.signin-why {
  margin: 0;
  font-size: 13px;
  text-align: center;
}

/* ── 노트 (하는 법, 그림 쪽지) ── */

.notebook {
  display: flex;
  border: 2px solid var(--ink);
  background-color: var(--cell);
  background-image:
    linear-gradient(var(--note-rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--note-rule) 1px, transparent 1px);
  background-size: 12px 12px;
}

.rings {
  flex: none;
  width: 26px;
  border-right: 1px solid var(--note-rule);
  background-image: radial-gradient(circle at 13px 12px, transparent 4px, #8b9099 4.5px, #8b9099 6px, transparent 6.5px);
  background-size: 26px 24px;
}

.page {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 쪽을 넘겨도 노트 높이가 그대로이게: 가장 큰 그림(52vh)과 제목 한 줄, 펜글씨 두 줄이 들어가는 높이 */
  min-height: calc(52vh + 156px);
  padding: 14px 16px 24px;
  overflow: hidden;
}

/* 쪽 맨 위 볼펜 제목 (The goal, How the machine works) */
.page-title {
  align-self: stretch;
  margin: 0 0 8px;
  font: 400 27px/1.2 var(--hand);
  color: #24366e;
  text-decoration: underline 2px;
  text-underline-offset: 6px;
}

/* 제목 아래 한 줄: 빨간 번호와 볼펜으로 적은 한두 줄 */
.page-line {
  align-self: stretch;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.page-no {
  flex: none;
  margin: -6px 0 0 -4px;
  line-height: 0;
}

.page-note {
  flex: 1;
  min-height: 2.3em;
  margin: 0;
  font: 400 25px/1.25 var(--hand);
  color: #24366e;
  text-wrap: pretty;
}

/* 번호 옆 글씨는 손글씨 숫자의 가운데에 맞게 살짝 내린다 */
.page-no + .page-note {
  padding-top: 4px;
}

.note-mark svg {
  display: inline-block;
  width: auto;
  height: 1.3em;
  margin: 0 -0.12em;
  vertical-align: -0.34em;
}

.page > svg,
.tip-page svg {
  max-width: 100%;
  height: auto;
}

/* 그림은 펜글씨 아래 남은 자리의 가운데 */
.page > svg {
  max-height: 52vh;
  margin: auto 0;
}

.nb-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}

.dots {
  display: inline-flex;
  gap: 6px;
}

.dots i {
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--pen);
  border-radius: 50%;
}

.dots i.on {
  background: var(--pen);
}

.tip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -6px 0 20px;
  padding: 8px 8px 8px 16px;
  border: 2px solid var(--ink);
  background-color: var(--cell);
  background-image:
    linear-gradient(var(--note-rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--note-rule) 1px, transparent 1px);
  background-size: 12px 12px;
}

.tip-page {
  flex: 1;
  min-width: 0;
}

a.btn {
  text-decoration: none;
}

/* 연습 문제: 다음 문제까지 남은 시간은 상관없어 숨긴다 */
.practice .clock {
  display: none;
}

.practice-note {
  max-width: 34ch;
  margin: -4px auto 22px;
  text-align: center;
  font-size: 15px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 60;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--sheet);
  font-size: 14px;
  font-weight: 560;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.on {
  opacity: 1;
}

/* ── 광고와 바닥글 ── */

/* 광고는 판에서 150px 넘게 떨어뜨리고(AdSense 게임 광고 간격), 광고라고 적는다. 채워지지 않으면 자리째 숨긴다 */
.ad {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ad:has(ins[data-ad-status="unfilled"]) {
  display: none;
}

.ad-label {
  font-size: 12px;
  line-height: 16px;
  color: var(--muted);
}

.ad-page {
  max-width: 970px;
  margin: 0 auto;
}

/* 판(실행 버튼, 제출 단추)에서 150px 띄운다. 보통 데스크톱 높이에서는 광고가 첫 화면 아래로 밀리지만 잘못 누르는 것보다 낫다 */
.ad-page:not(:empty) {
  margin-top: 150px;
}

.ad-page .adsbygoogle {
  min-height: 90px;
}

/* 좁은 화면에서만 판 아래 두 번째 광고. 첫 광고와 붙지 않게 띄운다 */
.ad-page2:not(:empty) {
  margin-top: 32px;
}

@media (min-width: 1244px) {
  .ad-page2 {
    display: none;
  }
}

/* 맨 위 광고: 양옆 광고가 없는 화면 중 휴대전화(320×50)와, 728×90이 들어가는 너비에 높이가 860px 넘는 화면에서만.
   판 아래 두 번째 광고 대신 나온다 (조건은 app.js의 top과 같다). 낮은 화면에서는 실행 단추가 첫 화면 밖으로 밀려 빼 둔다.
   광고가 오기 전부터 자리 높이를 잡아 둔다 (늦게 채워지며 머리와 판을 밀어내면 단추를 누르려던 손가락이 광고에 닿는다).
   머리 단추와 44px, 판과 150px 넘게 띄운다. 광고를 켰을 때(.rails)만 자리를 잡는다 */
#ad-top {
  display: none;
}

@media (max-width: 760px), (min-width: 776px) and (max-width: 1243px) and (min-height: 860px) {
  .rails #ad-top {
    display: block;
    height: 72px; /* 표시 16 + 사이 6 + 광고 50 */
    margin-bottom: 44px;
  }

  .ad-page2 {
    display: none;
  }
}

@media (min-width: 776px) and (max-width: 1243px) and (min-height: 860px) {
  .rails #ad-top {
    height: 112px; /* 표시 16 + 사이 6 + 광고 90 */
  }
}

.ad.ad-top {
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.ad-top .adsbygoogle {
  width: 320px;
  height: 50px;
}

@media (min-width: 761px) {
  .ad-top .adsbygoogle {
    width: 728px;
    height: 90px;
  }
}

/* 판 양옆 세로 광고: 광고를 켰고 화면이 넓으면(.rails) 판 양옆에 늘 자리를 둔다. 스크롤하면 판과 같이 올라간다
   (AdSense 고정 광고는 한 화면에 하나만, 양쪽 대칭은 안 된다).
   판과 150px 떨어지게 사이를 126px 둔다 (판 바깥 여백 24px과 합쳐 150px). 판이 640px(실행 막대와 규칙표가 잘리지 않는 가장 좁은 너비)이 되는 1244px부터 */
/* 바깥 자리(aside)만. 안의 광고 상자도 ad-rail 이름을 달고 있어 aside로 좁힌다 */
aside.ad-rail {
  display: none;
}

@media (min-width: 1244px) {
  .shell.rails {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr) 160px;
    column-gap: 126px;
    max-width: calc(1000px + 2 * (160px + 126px) + 32px);
    margin: 0 auto;
    padding: 0 16px;
  }

  .shell.rails aside.ad-rail {
    display: block;
    margin-top: 88px;
    align-self: start;
  }
}

.ad-rail .adsbygoogle {
  width: 160px;
  height: 600px;
}

/* ?ads=test의 회색 자리. 표시 글자가 자리 왼쪽 끝에 맞도록 자리 너비로 줄여 가운데 둔다 */
.ad:has(.ad-mock) {
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.ad-mock {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--faint);
  background: var(--hover);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.ad-mock-horizontal {
  width: 728px;
  max-width: 100%;
  height: 90px;
}

.ad-mock-banner {
  width: 728px;
  max-width: 100%;
  height: 90px;
}

.ad-mock-vertical {
  width: 160px;
  height: 600px;
}

.ad-mock .narrow {
  display: none;
}

@media (max-width: 760px) {
  .ad-mock-horizontal {
    width: 320px;
    height: 100px;
  }

  .ad-mock-banner {
    width: 320px;
    height: 50px;
  }

  .ad-mock .wide {
    display: none;
  }

  .ad-mock .narrow {
    display: inline;
  }
}

/* 판 아래 하는 법: 노트(그림)와 글 두 단. 판이 좁으면 노트 아래에 글. 노트는 쪽을 넘겨도 높이가 그대로다 */
.howto {
  margin-top: 48px;
  padding: 24px 24px 26px;
  scroll-margin-top: 24px;
  container: howto / inline-size;
}

/* 바로 위에 광고가 있으면 제목 단추를 잘못 누르지 않게 더 띄운다 */
.ad-page:not(:empty) ~ .howto {
  margin-top: 72px;
}

.howto-grid {
  display: grid;
  gap: 28px;
}

.howto-book {
  width: 100%;
  max-width: 460px;
  justify-self: center;
}

.howto .page {
  min-height: 0;
  height: 500px;
}

/* 겹창보다 좁은 노트라 볼펜 글씨도 줄인다 */
.howto .page-title {
  font-size: 22px;
}

.howto .page-note {
  font-size: 20px;
}

/* 펜글씨가 두 줄이면 그림이 줄어서 노트 안에 든다 */
.howto .page > svg {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 360px;
}

.howto-text h2 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
}

.howto-text * + h2 {
  margin-top: 22px;
}

.howto-text p,
.howto-text li {
  margin: 0;
  max-width: 62ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-hover);
}

.howto-text p + p {
  margin-top: 8px;
}

.howto-steps,
.howto-tips {
  margin: 10px 0 0;
  padding-left: 22px;
}

.howto-text .howto-more {
  margin-top: 18px;
}

.howto-more a {
  color: var(--ink);
  font-weight: 700;
}

.howto-steps li + li,
.howto-tips li + li {
  margin-top: 10px;
}

.howto-steps li::marker {
  font-weight: 700;
  color: var(--ink);
}

.howto-steps h3 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 700;
}

/* 제목이 노트 쪽을 고르는 단추. 보이는 쪽은 밑줄 */
.howto-step {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  text-align: left;
  text-decoration: underline 1px transparent;
  text-underline-offset: 4px;
  cursor: pointer;
}

.howto-step:hover {
  text-decoration-color: currentColor;
}

.howto-step.on {
  text-decoration: underline 2px currentColor;
}

.howto-step:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* 넓으면 노트를 왼쪽에 두고, 글을 읽어 내려가는 동안 노트가 따라 내려온다 */
@container howto (min-width: 700px) {
  .howto-grid {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 36px;
    align-items: start;
  }

  .howto-book {
    position: sticky;
    top: 24px;
  }
}

/* 판 아래 짧은 소개(무엇인지, 규칙 요약)와 /about 페이지의 소개: 무엇인지, 튜링 기계, 난이도, 기록 */
.about {
  margin-top: 48px;
  padding: 24px 24px 26px;
  /* 머리의 About 단추로 내려왔을 때 테두리 위 ABOUT 글자가 화면 끝에 붙지 않게 */
  scroll-margin-top: 24px;
}

.about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 22px 36px;
}

/* 바로 위에 광고가 있으면 링크를 잘못 누르지 않게 더 띄운다 */
.ad-page:not(:empty) ~ .intro {
  margin-top: 72px;
}

.intro .intro-links {
  max-width: none;
  margin-top: 18px;
}

.intro-links a,
.about p a {
  color: var(--ink);
  font-weight: 700;
}

/* 글 속 링크와 꼬리말 링크의 아이콘 (src/links.js). 글자 크기에 맞춰 커지고, 붙은 낱말과 한 덩어리로 줄을 바꾼다.
   다른 사이트로 가는 링크는 아이콘이 글 뒤에 */
.link-glue {
  white-space: nowrap;
}

.link-ic {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  margin-right: 0.3em;
  vertical-align: -0.2em;
}

.link-ic.after {
  margin: 0 0 0 0.25em;
}

.about h2 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
}

/* 오른쪽 아래 테두리에 걸친 작은 커밋 해시 (배포한 판) */
.about-version {
  position: absolute;
  right: 12px;
  bottom: -8px;
  padding: 0 6px;
  background: var(--sheet);
  color: var(--faint);
  font-size: 11px;
  line-height: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.about p {
  margin: 0;
  max-width: 62ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-hover);
}

/* 연습 페이지(practice.html) 판 아래 풀이: 글은 HOW TO PLAY, ABOUT과 같은 활자. 답은 단추를 눌러 펼친다 */
/* 연습 페이지에는 판 아래 광고가 없어서 판 바로 아래에 붙인다 */
.guide {
  margin-top: 28px;
  padding: 24px 24px 26px;
}

.guide h1 {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.3;
}

.guide h2 {
  margin: 22px 0 6px;
  font-size: 15px;
  font-weight: 700;
}

.guide p,
.guide li {
  margin: 0;
  max-width: 62ch;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-hover);
}

.guide p + p,
.guide ul + p {
  margin-top: 8px;
}

.guide ul {
  margin: 6px 0 0;
  padding-left: 22px;
}

.guide li + li {
  margin-top: 6px;
}

.guide a:not(.btn) {
  color: var(--ink);
  font-weight: 700;
}

.guide-answer {
  margin-top: 22px;
}

.guide-answer > summary {
  height: 40px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 700;
  list-style: none;
}

.guide-answer > summary::-webkit-details-marker {
  display: none;
}

.guide-answer[open] > summary .show,
.guide-answer:not([open]) > summary .hide {
  display: none;
}

.guide-scroll {
  margin-top: 8px;
  overflow-x: auto;
}

/* 따라가기 표: 연한 칸 선, 머리 아래만 먹색 2px */
.guide-trace {
  min-width: 520px;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  background: var(--cell);
}

.guide-trace th,
.guide-trace td {
  padding: 6px 10px;
  border: 1px solid var(--rule);
  text-align: left;
}

.guide-trace thead th {
  border-bottom: 2px solid var(--ink);
}

.guide-trace td:last-child {
  letter-spacing: 0.08em;
  font-weight: 600;
}

/* 휴대전화: 칸을 좁혀 옆으로 밀지 않고 한 화면에 */
@media (max-width: 560px) {
  .guide-trace {
    min-width: 0;
    width: 100%;
    font-size: 13px;
  }

  .guide-trace th,
  .guide-trace td {
    padding: 6px 4px;
  }
}

@media (max-width: 400px) {
  .guide-trace {
    font-size: 12px;
  }

  .guide-trace th,
  .guide-trace td {
    padding: 6px 3px;
  }

  .guide-trace td:last-child {
    letter-spacing: 0.02em;
  }
}

/* 풀린 표 그림은 노트 종이 위에: 흰 바탕, 파란 모눈, 잉크 테두리 (DESIGN.md의 노트와 같은 재료) */
.guide-fig {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  margin: 22px 0 0;
  padding: 16px;
  border: 2px solid var(--ink);
  background-color: var(--cell);
  background-image:
    linear-gradient(var(--note-rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--note-rule) 1px, transparent 1px);
  background-size: 12px 12px;
}

.guide-pic svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.guide-fig figcaption {
  padding: 2px 6px;
  background: var(--cell);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
}

.guide .guide-take {
  margin-top: 22px;
  padding-left: 12px;
  border-left: 3px solid var(--ink);
}

.guide .guide-next {
  margin-top: 22px;
}

/* 읽을거리 (/learn/<글>): 연습 풀이(.guide)와 같은 활자. 판이 없어서 머리에서 띄운다. 인용은 왼쪽에 연한 선 */
.panel.article {
  margin-top: 48px;
}

.article blockquote {
  max-width: 58ch;
  margin: 10px 0 12px;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--rule);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-hover);
}

.article .guide-scroll,
.article .guide-fig {
  margin-top: 14px;
  margin-bottom: 14px;
}

/* 출처: 글 속 위첨자 번호와 글 끝 목록. 번호를 눌러 내려오면 그 줄을 잠깐 칠한다 */
.article sup.fn {
  font-size: 0.7em;
  line-height: 0;
}

.article sup.fn a {
  padding: 0 1px;
  font-weight: 700;
  text-decoration: none;
}

.article ol.footnotes {
  margin: 6px 0 0;
  padding-left: 24px;
}

.article .footnotes li {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  overflow-wrap: anywhere;
  scroll-margin-top: 24px;
}

.article .footnotes li + li {
  margin-top: 4px;
}

.article .footnotes a {
  font-weight: 400;
  color: var(--ink-hover);
}

.article .footnotes li:target {
  background: var(--hover);
}

/* 글 끝의 이전 글, 다음 글, 목록. 출처 목록과 줄로 나눈다 */
.article .guide-pager {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}

/* 입력과 출력만 있는 두 칸 표는 좁게 */
.guide-trace.pairs {
  min-width: 0;
  width: auto;
}

/* Turing 1936 논문의 표 (/learn/first-machines)도 좁게. 테이프는 고정폭 글꼴로 칸을 맞추고, 머리가 있는 칸은 밑줄 */
.guide-trace.t36 {
  min-width: 0;
  width: auto;
}

.guide-trace td.tape {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 400;
  letter-spacing: 0.15em;
  white-space: nowrap;
}

.guide-trace td.tape b {
  font-weight: 700;
  text-decoration: underline 2px;
  text-underline-offset: 3px;
}

/* 글로 채운 표 (부품 비교, busy beaver 숫자)는 마지막 칸도 보통 글씨 */
.guide-trace.plain td:last-child {
  letter-spacing: normal;
  font-weight: inherit;
}

/* 읽을거리 목록 (/learn): 한 줄에 제목(링크)과 한 문장 소개 */
.learn-list {
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.learn-list li {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 62ch;
  padding: 14px 0;
  border-top: 1px solid var(--rule);
}

.learn-list a {
  align-self: flex-start;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
}

.learn-sum {
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-hover);
}

.foot {
  margin-top: 40px;
  text-align: center;
  font-size: 13px;
}

/* 바로 위가 광고면 링크를 잘못 누르지 않게 더 띄운다 */
.ad-about:not(:empty) + .foot {
  margin-top: 72px;
}

.foot a {
  color: var(--muted);
}

/* 꼬리말 아래 말 고르기 (src/i18n.js가 단다). 고르면 저장하고 그 말로 다시 연다 */
.lang-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  margin: 14px auto 0;
  color: var(--muted);
}

.lang-pick select {
  font: inherit;
  color: var(--ink);
  background: var(--sheet);
  border: 1.5px solid var(--rule);
  border-radius: 0;
  padding: 4px 8px;
  cursor: pointer;
}

.lang-pick select:hover {
  border-color: var(--ink);
}

.lang-pick select:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 1px;
}

/* ── 좁은 화면 (휴대전화) ── */

/* 머리가 한 줄에 다 들어가지 않는 너비: 세 줄로. 양옆 광고가 있으면 화면보다 판이 좁으니 판 너비로 잰다 */
/* TURING-DAILY와 날짜가 한 줄에 들어가지 않는 너비 (휴대전화):
   첫 줄: TURING-DAILY와 버튼. 둘째 줄: 오른쪽에 날짜와 남은 시간. 셋째 줄: 난이도와 목표 */
@container app (max-width: 640px) {
  .top {
    column-gap: 12px;
    row-gap: 6px;
  }

  .when {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: end;
    gap: 14px;
    padding-top: 0;
  }

  .top-actions {
    grid-row: 1;
  }

  .meta-line + .meta-line {
    grid-column: 1 / -1;
    grid-row: 3;
  }
}

/* 단추 여섯이 TURING-DAILY 옆에 들어가지 않는 너비 (휴대전화): 단추는 셋째 줄에 너비 가득 고르게.
   첫 줄은 TURING-DAILY와 날짜, 둘째 줄은 난이도와 남은 시간. 글 페이지는 날짜가 없어 단추가 둘째 줄 */
@container app (max-width: 480px) {
  .when {
    display: contents;
  }

  .date {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    display: flex;
  }

  .clock {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
  }

  .meta-line + .meta-line {
    grid-column: 1;
    grid-row: 2;
  }

  .top-actions {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-self: stretch;
    justify-content: space-between;
    margin-top: 4px;
  }

}

@media (max-width: 760px) {
  :root {
    --cw: 56px;
    --ch: 56px;
    --side: 40px;
    --gutter: 16px;
  }

  .app {
    padding-top: 12px;
    padding-bottom: 0;
  }

  .top {
    margin-bottom: 14px;
  }

  .meta-line + .meta-line {
    gap: 8px;
  }

  .tier span {
    display: none;
  }

  .top-actions {
    gap: 0;
  }

  .top-actions .btn {
    width: 40px;
    height: 40px;
  }

  .top-actions .btn.labeled {
    width: auto;
    min-width: 44px;
    height: 46px;
    padding: 0 4px;
  }

  .btn.sq.labeled {
    width: 52px;
    height: 52px;
  }

  .btn.run.labeled {
    width: 64px;
    height: 64px;
  }

  .panel.about,
  .panel.howto,
  .panel.guide {
    margin-top: 32px;
    padding: 26px 14px 20px;
  }

  .panel.guide {
    margin-top: 24px;
  }

  .panel.guide.article {
    margin-top: 32px;
  }

  .top-actions .btn.text {
    width: auto;
    padding: 0 8px;
    font-size: 13px;
  }

  .board {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    /* 좁은 화면은 한 줄로: 테이프, 규칙표, 실행 막대가 첫 화면에 들어오게 위로, 예시와 검사·제출은 그 아래 (넓은 화면과 같은 읽는 차례).
       실행 막대는 화면 아래에 붙어 있다가 예시까지 내리면 표 밑 제자리에 선다 */
    grid-template-areas:
      "tape"
      "table"
      "transport"
      "tests";
    gap: 14px;
  }

  .panel {
    padding: 10px 12px;
  }

  .panel-label {
    left: 6px;
  }

  .panel-label.end {
    right: 6px;
  }

  .table-panel {
    min-height: 0;
  }

  .transport {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 0 calc(-1 * var(--gutter));
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
    background: var(--sheet);
    border-top: 2px solid var(--ink);
  }

  .btn.sq {
    width: 48px;
    height: 48px;
  }

  .btn.run {
    width: 60px;
    height: 60px;
  }

  .row {
    padding-left: 8px;
    padding-right: 8px;
  }

  .submit {
    height: 56px;
  }

  .stat b {
    font-size: 24px;
  }

  .card {
    padding: 56px 16px 16px;
  }

  .page {
    padding: 12px 10px 16px;
  }

  .page-title {
    font-size: 24px;
  }

  .page-note {
    font-size: 22px;
  }
}

/* 좁은 폰: 격자 글자를 한 칸 2px로 줄인다 */
@media (max-width: 460px) {
  .meta-line .gt,
  .when .gt {
    width: auto;
    height: 14px;
  }

  .top .wordmark .gt {
    max-width: 195px;
  }

  .when {
    gap: 10px;
  }

  .clock {
    gap: 4px;
  }

  .clock .ic {
    width: 14px;
    height: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}

/* ── 글 페이지 (/howto, /about) ── */

/* 머리는 TURING-DAILY와 단추 한 줄. 지금 페이지의 단추는 이름에 밑줄 */
.page-top {
  margin-bottom: 28px;
}

.page-top .top-actions {
  grid-row: 1;
}

/* 휴대전화: 단추는 TURING-DAILY 아래 둘째 줄에 너비 가득 (오늘 문제 화면과 같은 줄 모양) */
@container app (max-width: 480px) {
  .page-top .top-actions {
    grid-row: 2;
  }

  /* 단추 일곱이 한 줄에: 이름 길이만큼 차지하고 남는 자리는 고르게 나눈다 (이름 사이 틈이 같다, 누르는 자리는 줄 가득) */
  .top-actions .btn.labeled {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
  }
}

/* 아주 좁은 휴대전화(320px 안팎): 이름 글자를 조금 줄여 틈을 남긴다 */
@container app (max-width: 320px) {
  .top-actions .btn .cap {
    font-size: 10px;
  }
}

.top-actions [aria-current] .cap {
  text-decoration: underline 2px;
  text-underline-offset: 3px;
}

/* 구역 이름이 페이지 제목 (그리기 전에는 글로 보인다) */
h1.panel-label {
  margin: 0;
  font-size: 13px;
  line-height: 16px;
}

.top.page-top + .panel {
  margin-top: 8px;
}

.page-top ~ .ad-about:not(:empty) {
  margin-top: 48px;
}

/* 없는 주소 (404.html): 안내 한 줄, 오늘 문제 단추, 다른 페이지 링크. .about p의 margin: 0보다 앞서게 .about을 붙인다 */
.about .notfound > * + * {
  margin-top: 18px;
}

/* ── 튜링 기계 시뮬레이터 (/simulator, src/simulator.js) ──
   판은 오늘 문제와 같고, 오른쪽(좁으면 아래) 구역에 입력 고치기와 예시. 위아래는 글 페이지의 글 상자 */
.sim-intro h1 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.3;
}

.page-top + .sim-intro {
  margin-top: 8px;
}

.sim-board {
  margin-top: 28px;
}

.sim-text {
  margin-top: 28px;
}

.sim-text p + p {
  margin-top: 10px;
}

.sim-text .about-grid > div > h2:not(:first-child) {
  margin-top: 18px;
}

/* 테이프 위: 멈춘 까닭(왼쪽)과 걸음 수(오른쪽) */
.sim-status {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.sim-status.accepted {
  color: var(--ink);
}

.sim-status.rejected,
.sim-status.timeout {
  color: var(--red);
}

.sim-steps {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.sim-steps b {
  color: var(--ink);
}

/* 표 위: 상태 빼기·더하기, 되돌리기·지우기. 오늘 문제의 #table-bar처럼 표 옆으로 올리지 않는다 (상태가 많으면 표가 넓다) */
#sim-bar:empty {
  min-height: 50px;
}

/* 입력: 기호 띠와 그 아래 A, B, 빈칸, 지우기 단추 */
.sim-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  min-height: 52px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  background: var(--cell);
}

.sim-input .strip {
  display: inline-flex;
  flex-wrap: wrap;
}

.sim-empty {
  font-size: 14px;
  color: var(--faint);
}

.sim-keys {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  margin-top: 10px;
}

.sim-presets {
  display: flex;
  flex-direction: column;
  margin-top: 22px;
}

.sim-presets h2 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.sim-presets .row {
  font: inherit;
  font-size: 15px;
  color: var(--ink);
}
