/* 더 큰 쪽? — 청사진(도면) 위의 두 장의 도면 카드, 노란 줄자, 빨간 채점 색연필 */
:root {
  --field: #1f4fa0;        /* 청사진 바탕 */
  --field-deep: #173d80;
  --grid: rgba(255, 255, 255, .075);
  --grid-major: rgba(255, 255, 255, .15);
  --paper: #f7f9fd;        /* 도면 용지 */
  --ink: #142a5c;          /* 남색 제도 잉크 */
  --ink-soft: #52648f;
  --tape: #ffc928;         /* 줄자 노랑 */
  --tape-deep: #e2a60b;
  --red: #e23a2e;          /* 채점 색연필 */
  --steel: #6b7689;
  --display: 'Black Han Sans', 'Pretendard Variable', sans-serif;
  --body: 'Pretendard Variable', Pretendard, system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
body {
  margin: 0; height: auto; overflow-x: hidden; overflow-y: visible;
  font-family: var(--body); color: #fff; word-break: keep-all;
  background-color: var(--field);
  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: 80px 80px, 80px 80px, 16px 16px, 16px 16px;
  background-position: -1px -1px;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--tape); outline-offset: 3px; }

/* ── 화면 틀 ─────────────────────────────── */
.app {
  height: 100vh; height: 100svh; min-height: 560px;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.bar {
  flex: none; display: flex; align-items: center; gap: 10px;
  height: 54px; padding: 0 12px 0 14px;
}
.logo {
  flex: none; display: inline-block; padding: 5px 8px 4px; border-radius: 4px;
  background: var(--paper); color: var(--ink); text-decoration: none;
  font: 400 15px/1 var(--display); letter-spacing: -.01em;
}
.title { margin: 0; font: 400 23px/1 var(--display); letter-spacing: -.01em; white-space: nowrap; }
.score { margin-left: auto; display: flex; gap: 12px; align-items: flex-end; }
.score span { display: flex; align-items: baseline; gap: 3px; }
.score b { font: 400 26px/1 var(--display); font-variant-numeric: tabular-nums; }
.score .best b { font-size: 17px; opacity: .75; }
.score small { font-size: 12px; opacity: .8; }
.score .streak b.pop { animation: pop .42s cubic-bezier(.3, 1.8, .5, 1); color: var(--tape); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.45); } 100% { transform: scale(1); } }
.snd {
  flex: none; width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; border-radius: 6px; background: rgba(255, 255, 255, .12); cursor: pointer;
}
.snd .on { display: none; }
.snd[aria-pressed="true"] .on { display: inline; }
.snd[aria-pressed="true"] .off { display: none; }

/* 도전장 받은 사람: 친구 기록 자 */
.rival[hidden] { display: none; }
.rival { flex: none; display: flex; align-items: center; gap: 10px; padding: 0 14px 8px; }
.rival-text { margin: 0; font-size: 13px; font-weight: 700; white-space: nowrap; }
.rival-ruler {
  position: relative; flex: 1; height: 14px; border-radius: 2px;
  background: var(--tape) repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 8px);
  background-size: 100% 6px; background-repeat: repeat-x; background-position: 0 0;
  box-shadow: inset 0 -1px 0 var(--tape-deep);
}
.rival-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(20, 42, 92, .28); transition: width .4s; }
.rival-flag { position: absolute; top: -6px; width: 2px; height: 22px; background: var(--red); }
.rival-flag::after { content: ""; position: absolute; left: 2px; top: 0; border: 5px solid transparent; border-left: 8px solid var(--red); border-top-width: 4px; border-bottom-width: 4px; }

/* ── 보드 ─────────────────────────────── */
.board {
  flex: 1; min-height: 0; display: grid; gap: 0;
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
  padding: 0 12px 12px;
}
.card {
  position: relative; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(92px, 33%, 150px); gap: 14px; align-items: center;
  padding: 16px 16px 16px 20px; border-radius: 3px;
  background: var(--paper); color: var(--ink); cursor: pointer; user-select: none;
  box-shadow: 0 2px 0 rgba(10, 24, 60, .25), 0 12px 24px -14px rgba(5, 15, 40, .6);
  transition: transform .18s ease, box-shadow .18s ease;
  overflow: hidden;
}
/* 도면 테두리: 안쪽 가는 선 + 모서리 맞춤표 */
.card::before {
  content: ""; position: absolute; inset: 6px; border: 1px solid rgba(20, 42, 92, .35); pointer-events: none;
}
.card::after {
  content: ""; position: absolute; inset: 2px; pointer-events: none;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 0 / 9px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 0 0 / 1.5px 9px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 100% 100% / 9px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 100% 100% / 1.5px 9px no-repeat;
}
.board[data-state="ask"] .card:hover { transform: translateY(-2px); box-shadow: 0 2px 0 rgba(10, 24, 60, .25), 0 18px 28px -14px rgba(5, 15, 40, .7); }
.board[data-state="ask"] .card:active { transform: translateY(1px) scale(.99); }
.board:not([data-state="ask"]) .card { cursor: default; }
.card.swap .face { animation: swapin .32s ease both; }
@keyframes swapin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.face { display: contents; }
.ico {
  grid-column: 2; grid-row: 1; display: grid; place-items: center; border-radius: 2px;
  background:
    linear-gradient(rgba(20, 42, 92, .08) 1px, transparent 1px) 0 0 / 8px 8px,
    linear-gradient(90deg, rgba(20, 42, 92, .08) 1px, transparent 1px) 0 0 / 8px 8px,
    #fff;
  border: 1px solid rgba(20, 42, 92, .2);
  aspect-ratio: 1; justify-self: center; width: 100%;
}
.ico svg { width: 78%; height: 78%; }
.ico .f { fill: var(--tape); }
.ico .w { fill: #fff; }
.ico .k { fill: var(--ink); stroke: none; }
.txt { grid-column: 1; grid-row: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.name { margin: 0; font-size: clamp(18px, 5.4vw, 23px); font-weight: 800; line-height: 1.3; letter-spacing: -.02em; text-wrap: balance; }
.num { align-self: stretch; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; row-gap: 2px; min-height: 40px; }
.val { position: relative; white-space: nowrap; font: 400 clamp(28px, 9vw, 42px)/1.08 var(--display); letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.val.q { color: var(--ink-soft); }
.val .u { font-family: var(--body); font-weight: 900; font-size: .78em; margin-left: .04em; }
.val.long { font-size: clamp(24px, 7.4vw, 34px); }
.val.xlong { font-size: clamp(21px, 6.2vw, 28px); }
.sub { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.meta { display: none; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--ink-soft); }
.revealed .meta { display: flex; }
.yr { font-weight: 700; color: var(--ink); }
.est { padding: 1px 5px 0; border: 1.5px solid var(--red); border-radius: 3px; color: var(--red); font-weight: 800; font-size: 11.5px; transform: rotate(-3deg); }
.src { color: var(--ink-soft); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgba(20, 42, 92, .35); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src:hover { color: var(--ink); }
.note { display: none; margin: 0; font-size: 13px; line-height: 1.45; color: var(--ink-soft); }
.revealed .note { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.revealed .note.open { -webkit-line-clamp: unset; display: block; cursor: auto; }

/* 내 선택: 줄자 조각 스티커 */
.pick-tag {
  position: absolute; right: 12px; top: 10px; z-index: 2; padding: 4px 8px 3px;
  background: var(--tape); color: var(--ink); font-size: 12px; font-weight: 800;
  box-shadow: 0 1px 0 var(--tape-deep); transform: rotate(3deg);
}
.picked { box-shadow: 0 0 0 3px var(--tape), 0 12px 24px -14px rgba(5, 15, 40, .6); }

/* 채점 색연필 */
.mark { position: absolute; pointer-events: none; overflow: visible; z-index: 3; }
.mark path { fill: none; stroke: var(--red); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; opacity: .92; }
.mark.draw path { animation: drawline .5s ease-out forwards; }
@keyframes drawline { to { stroke-dashoffset: 0; } }

/* ── 가운데 띠: 질문 / 줄자 / 판정 ─────── */
.band {
  position: relative; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto;
  align-items: center; column-gap: 10px; min-height: 150px; padding: 8px 0 6px;
}
.ask { grid-column: 1 / -1; grid-row: 1; text-align: center; transition: opacity .2s; }
.ask-q { margin: 0; font: 400 clamp(21px, 6vw, 27px)/1.2 var(--display); }
.ask-hint { margin: 4px 0 0; font-size: 13px; opacity: .85; }
.ask-hint:empty { display: none; }
.measure { grid-column: 1 / -1; grid-row: 2; height: 74px; margin: 2px -12px 0; }
.measure canvas { display: block; width: 100%; height: 100%; }
.readout { grid-column: 1; grid-row: 1; display: none; min-width: 0; }
.board[data-state="reveal"] .ask, .board[data-state="done"] .ask, .board[data-state="over"] .ask { display: none; }
.board[data-state="reveal"] .readout, .board[data-state="done"] .readout, .board[data-state="over"] .readout { display: block; }
.verdict { display: inline; margin: 0 8px 0 0; font: 400 22px/1 var(--display); }
.verdict.wrong { color: #ffd2cc; }
.ratio { display: inline; margin: 0; font: 400 clamp(26px, 7.4vw, 34px)/1.1 var(--display); color: var(--tape); font-variant-numeric: tabular-nums; }
.phrase { margin: 4px 0 0; font-size: 13.5px; line-height: 1.4; opacity: .95; min-height: 1.4em; }
.next {
  grid-column: 2; grid-row: 1; align-self: center; border: 0; cursor: pointer;
  padding: 12px 16px 10px; border-radius: 4px; background: var(--tape); color: var(--ink);
  font: 400 18px/1 var(--display); box-shadow: 0 4px 0 var(--tape-deep); white-space: nowrap;
}
.next:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tape-deep); }
.board.shake .measure { animation: shake .32s linear; }
@keyframes shake { 20% { transform: translateX(-4px); } 40% { transform: translateX(3px); } 60% { transform: translateX(-2px); } 80% { transform: translateX(1px); } }

/* ── 결과 시트 ─────────────────────────── */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8, 20, 50, .55);
}
.sheet-wrap[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92svh; overflow-y: auto;
  background: var(--paper); color: var(--ink); border-radius: 10px 10px 0 0;
  padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .35);
  animation: rise .34s cubic-bezier(.2, .9, .3, 1);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-kicker { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.sheet-title { margin: 2px 0 0; font: 400 46px/1.05 var(--display); }
.sheet-title span { color: var(--field); }
.sheet-best, .sheet-rival { margin: 6px 0 0; font-size: 15px; font-weight: 600; }
.sheet-rival { padding: 8px 10px; background: var(--tape); border-radius: 3px; font-weight: 800; }
.recap { margin: 14px 0 0; padding: 12px 12px; border: 1px solid rgba(20, 42, 92, .25); border-radius: 3px; font-size: 14px; line-height: 1.5; }
.recap h3 { margin: 0 0 6px; font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.recap p { margin: 0; }
.recap b { font-weight: 800; }
.recap .big { color: var(--red); }
.preview { display: none; }
.preview img { display: block; width: 100%; height: auto; border-radius: 3px; box-shadow: 0 6px 16px -8px rgba(0, 0, 0, .5); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.btn {
  border: 2px solid var(--ink); background: #fff; color: var(--ink); cursor: pointer;
  padding: 13px 10px 11px; border-radius: 4px; font-size: 15.5px; font-weight: 800;
}
.btn.primary { grid-column: 1 / -1; border-color: var(--ink); background: var(--tape); box-shadow: 0 4px 0 var(--ink); font: 400 21px/1 var(--display); padding: 15px 10px 13px; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.link { grid-column: 1 / -1; border: 0; background: none; color: var(--ink-soft); text-decoration: underline; cursor: pointer; padding: 4px; font-size: 14px; }
.link[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 14px; border-radius: 4px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 700;
  transition: opacity .2s, transform .2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 아래 본문(SEO) ─────────────────────── */
.guide {
  position: relative; max-width: 760px; margin: 0 auto; padding: 40px 18px 64px;
  color: var(--ink); background: var(--paper);
  content-visibility: auto; contain-intrinsic-size: auto 1700px;
  font-size: 16px; line-height: 1.7;
}
.guide::before { content: ""; position: absolute; inset: 8px; border: 1px solid rgba(20, 42, 92, .3); pointer-events: none; }
.guide h2 { margin: 0 0 10px; font: 400 26px/1.25 var(--display); }
.guide h3 { margin: 30px 0 8px; font-size: 18px; font-weight: 800; }
.guide p { margin: 0 0 10px; }
.steps { margin: 0; padding-left: 1.4em; }
.steps li { margin: 4px 0; }
.faq dt { margin: 16px 0 2px; font-weight: 800; }
.faq dd { margin: 0; color: #2c3e66; }
.more { margin: 0; padding: 0; list-style: none; }
.more li { margin: 8px 0; }
.more a { font-weight: 800; color: var(--field); margin-right: 6px; }

/* ── 넓은 화면: 카드 좌우, 줄자 아래 ────── */
@media (min-width: 900px) {
  .bar { height: 68px; padding: 0 32px; max-width: 1180px; width: 100%; margin: 0 auto; }
  .title { font-size: 28px; }
  .rival { padding: 0 24px 10px; max-width: 1180px; width: 100%; margin: 0 auto; }
  .board {
    grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; align-content: center;
    column-gap: 28px; padding: 8px 32px 24px; max-width: 1180px; width: 100%; margin: 0 auto;
  }
  #card0 { grid-column: 1; grid-row: 1; }
  #card1 { grid-column: 2; grid-row: 1; }
  .band { grid-column: 1 / -1; grid-row: 2; min-height: 150px; padding-top: 16px; }
  .measure { height: 84px; margin: 8px 0 0; }
  .card { grid-template-columns: 1fr; grid-template-rows: auto auto; align-content: center; justify-items: center; text-align: center; padding: 34px 32px 30px; gap: 20px; min-height: 440px; }
  .ico { grid-column: 1; grid-row: 1; width: 176px; }
  .txt { grid-column: 1; grid-row: 2; }
  .txt { align-items: center; justify-self: stretch; width: 100%; }
  .num { justify-content: center; }
  .meta { justify-content: center; }
  .name { font-size: 24px; }
  .val { font-size: 46px; }
  .val.long { font-size: 40px; }
  .val.xlong { font-size: 34px; }
  .ask { align-self: start; }
  .ask-q { font-size: 30px; }
  .ratio { font-size: 40px; }
  .phrase { font-size: 15px; }
  .next { font-size: 21px; padding: 14px 22px 12px; }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 8px; max-width: 760px; display: grid; grid-template-columns: 1fr 260px; column-gap: 24px; padding: 28px; }
  .sheet-head, .recap, .sheet-actions { grid-column: 1; }
  .preview { display: block; grid-column: 2; grid-row: 1 / span 3; align-self: start; }
}
@media (min-height: 780px) and (max-width: 899px) {
  .name { font-size: clamp(20px, 6vw, 25px); }
  .val { font-size: clamp(32px, 11vw, 48px); }
  .card { grid-template-columns: minmax(0, 1fr) clamp(116px, 41%, 172px); gap: 16px; }
  .txt { gap: 8px; }
  .val.q { font-size: clamp(36px, 12vw, 52px); }
}
@media (max-height: 700px) and (max-width: 899px) {
  .band { min-height: 116px; }
  .measure { height: 64px; }
  .band { min-height: 128px; }
  .card { padding: 10px 12px 10px 16px; gap: 10px; grid-template-columns: minmax(0, 1fr) clamp(80px, 26%, 110px); }
  .meta { font-size: 11.5px; }
  .revealed .note { -webkit-line-clamp: 1; }
  .revealed .note.open { -webkit-line-clamp: unset; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
