:root {
  --bg: #f4f2ec;
  --fg: #33302a;
  --muted: #8a8478;
  --line: #d8d2c6;
  --card: #ffffff;
  --card-edge: #d8d2c6;
  --sel: #3f5a55;
  --scope: #d9a441;
  --inno-bg: #e3f0dc;
  --inno: #3f7d3a;
  --crim-bg: #f6dcd7;
  --crim: #b2463a;
  --wrong: #c1503f;
  --key-bg: #e5ded3;
  --btn-bg: #3f5a55;
  --btn-fg: #f9f6f2;
  --sheet-bg: #ffffff;
  /* 메모 색 표시 넷. 정체 색(초록·빨강)과 겹치지 않게 고른다. */
  --tag0: #d6457a;
  --tag1: #e3a52a;
  --tag2: #3a8fd0;
  --tag3: #8a5ad1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1816;
    --fg: #e6dfd5;
    --muted: #9a9286;
    --line: #3b352f;
    --card: #26221e;
    --card-edge: #3b352f;
    --sel: #7cc2b2;
    --scope: #e0b25a;
    --inno-bg: #24361f;
    --inno: #8fcf86;
    --crim-bg: #42241f;
    --crim: #ee8a7c;
    --wrong: #e0705c;
    --key-bg: #3a322c;
    --sheet-bg: #26221e;
  }
}

* { 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) clamp(10px, 4vmin, 28px);
}

/* 한 화면에 다 들어가게 높이를 화면에 묶고, 남는 높이를 판이 가져간다. 판이 고정 높이였을
   때는 작은 폰에서 무고·범인 단추가 화면 밖으로 밀려 카드를 고를 때마다 스크롤해야 했다. */
body { height: 100vh; height: 100dvh; }

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

/* 헤더 배치는 모든 게임이 같다. 양옆을 1fr로 묶으면 좌우 내용의 폭이 달라도 이름이
   화면 한가운데에 온다. */
.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(26px, 6.5vmin, 36px);
  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; }

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

.back:hover { opacity: 1; }

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.levels { display: flex; gap: 6px; }

.level {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: inherit;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
}

.level[aria-pressed="true"] {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-fg);
}

.toggle.sound { font-size: 12px; }

/* 취소선은 소리 토글에만 준다. 도움말 토글의 꺼짐은 "안 열림"이라 뜻이 다르다. */
.toggle.sound[aria-pressed="false"] { opacity: 0.38; text-decoration: line-through; }

.meta { display: flex; align-items: center; gap: 12px; }
.mistakes { font-size: 13px; font-weight: 700; color: var(--muted); }
.mistakes.some { color: var(--wrong); }

.timer {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.board-wrap { position: relative; flex: 1 1 auto; min-height: 0; }

/* 열 글자 한 줄과 행 번호 한 칸을 둘레에 둔 4×5. 행 높이는 판에 남은 높이를 다섯으로 나눈
   것이고, 큰 화면에서 카드가 길쭉해지지 않게 위로만 막는다. */
.board {
  display: grid;
  grid-template-columns: 14px repeat(4, minmax(0, 1fr));
  grid-template-rows: auto repeat(5, minmax(0, 1fr));
  gap: 5px;
  height: 100%;
  max-height: 620px;
}

.axis {
  align-self: center;
  justify-self: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

/* 카드 높이를 고정한다. 밝힐 때 단서 글이 들어와도 판이 출렁이지 않게 — 줄마다 높이가 바뀌면
   누르려던 카드가 손가락 밑에서 밀려난다. */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-height: 0;
  padding: 5px 4px 4px;
  /* 카드 크기에 따라 안의 그림과 글을 줄인다(아래 @container). */
  container-type: size;
  border: 0;
  border-radius: 9px;
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--card-edge);
  color: var(--fg);
  font-family: inherit;
  cursor: pointer;
  overflow: hidden;
}

.face { display: inline-flex; color: var(--muted); }
.face svg { width: 24px; height: 24px; }
.face .mask, .face .smile { display: none; }
.card.criminal .face { color: var(--crim); }
.card.criminal .face .mask { display: inline; fill: var(--crim-bg); }
.card.innocent .face { color: var(--inno); }
.card.innocent .face .smile { display: inline; stroke: var(--inno-bg); }

.name { font-size: 13px; font-weight: 800; line-height: 1.15; }
.job { font-size: 10.5px; color: var(--muted); line-height: 1.1; }

/* 단서는 카드 안에 작게. 크게 읽는 자리는 판 아래의 상세 칸이다. */
.clue {
  margin-top: 2px;
  font-size: 10px;
  line-height: 1.25;
  text-align: center;
  word-break: keep-all;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.card.open .job { display: none; }

/* 다 쓴 단서는 흐리게. 지우지 않는다 — 나중에 다시 보아야 할 때가 있다. */
.card.used .clue { opacity: 0.35; }

/* 카드 모서리의 메모 점. */
.tags-on { position: absolute; top: 4px; right: 4px; display: flex; gap: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.dot[hidden] { display: none; }

/* 낮은 카드: 얼굴을 빼고 단서를 두 줄로. 단서 전문은 판 아래 상세 칸에 있다. */
@container (max-height: 84px) {
  .face { display: none; }
  .name { font-size: 12px; }
  .clue { -webkit-line-clamp: 2; margin-top: 1px; }
}

@container (max-height: 58px) {
  .card.open .clue { -webkit-line-clamp: 1; }
  .job { display: none; }
}

.card.innocent { background: var(--inno-bg); }
.card.criminal { background: var(--crim-bg); }
.card.scope { box-shadow: inset 0 0 0 2px var(--scope); }
.card.selected { box-shadow: inset 0 0 0 2.5px var(--sel); }
.card.flash { animation: flash 900ms ease-out; }

@keyframes flash {
  25% { filter: brightness(1.15); transform: scale(1.04); }
}

.detail {
  flex: none;
  /* 높이를 고정한다. 글 길이에 따라 늘면 판이 그만큼 줄어 카드가 출렁인다. */
  height: 74px;
  overflow: hidden;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--card-edge);
}
.detail p { margin: 0; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; }
.detail-tools { display: flex; align-items: center; }
.tags { display: flex; gap: 8px; }
.tags[hidden], .used-toggle[hidden] { display: none; }

/* 색 표시 단추. 손가락에 맞게 22px, 켜면 속이 찬다. */
.tag-pick {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 2.5px solid var(--c);
  background: none;
  cursor: pointer;
}
.tag-pick[aria-pressed="true"] { background: var(--c); }
.tag-pick[data-tag="0"], .dot[data-tag="0"] { --c: var(--tag0); }
.tag-pick[data-tag="1"], .dot[data-tag="1"] { --c: var(--tag1); }
.tag-pick[data-tag="2"], .dot[data-tag="2"] { --c: var(--tag2); }
.tag-pick[data-tag="3"], .dot[data-tag="3"] { --c: var(--tag3); }

.used-toggle {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  cursor: pointer;
}
.used-toggle[aria-pressed="true"] { background: var(--muted); border-color: var(--muted); color: var(--card); }
.detail.note .detail-text { color: var(--sel); }
.detail-who { font-size: 13px; font-weight: 700; color: var(--muted); }
.detail-text {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  word-break: keep-all;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.verdict { flex: none; display: grid; grid-template-columns: 58px 1fr 1fr 58px; gap: 6px; }

.pick {
  height: 46px;
  border: 0;
  border-radius: 9px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.pick.innocent { background: var(--inno-bg); color: var(--inno); }
.pick.criminal { background: var(--crim-bg); color: var(--crim); }
.pick:disabled { opacity: 0.4; cursor: default; }

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: none;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
}

/* 도구 아이콘은 글자가 아니라 도형이다(`shared/icons.js`). 기호 문자로 두었더니
   글꼴마다 크기와 두께가 달랐고, 아예 안 그리는 글꼴도 있었다. */
.tool-icon { display: inline-flex; line-height: 0; }
.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; }

.tool[aria-pressed="true"] {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-fg);
}

.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; }

.btn.ghost { background: none; color: var(--fg); box-shadow: inset 0 0 0 1.5px var(--muted); }

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

.help-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  line-height: 1.55;
}

@media (prefers-reduced-motion: reduce) {
  .card.flash { animation-duration: 1ms; }
}
