/* 멘델의 정원: '종이 위 그림' 틀 (studio/DESIGN.md, 2026-10-18 게임 틀)
   - 위 막대·실험 판·대화·창은 흰 종이와 잉크(_kit/paper.css 토큰과 부품). 정원 3D는 종이 위의 그림(#fig)이다.
   - 단추를 색으로 칠하지 않는다. 주 단추는 잉크 칠, 보조는 회색 테두리, 고른 상태는 굵은 글자와 칸 아래 3px 막대(.k-on).
   - 반경: 단추 var(--k-r), 판·그림·그래프·꼬리표·창 0. 맥박 치는 강조, 그림자, 둥근 카드, 알약 꼬리표를 쓰지 않는다.
   - 같은 대상은 같은 색: 씨(떡잎) 노랑·초록은 3D·씨 그림·그래프·글에서 같다(글자용은 짙은 값). 기대되는 비는 그래프와 글 모두 붉은 점선 */
@import "kit/paper.css";

:root {
  --yl: #e8c547;  --yl-p: #7a5d00;  /* 노란 떡잎: 칠(3D·그래프), 글자(흰 바탕 5.6:1) */
  --gn: #93c24c;  --gn-p: #3f6a1a;  /* 초록 떡잎 */
  --exp: #b4452f;                    /* 기대되는 비(그래프의 점선과 글의 점선 밑줄) */
  --ok-p: #237a36; --bad-p: #c92a2a;
  --hdr: 52px;
  --pw: clamp(min(320px, 46vw), 38%, 540px);
  font-family: var(--k-font);
  color: var(--k-ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--k-paper); }
body { touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
/* 줄바꿈: 한국어는 어절, 영어는 낱말, 일본어는 구절·금칙. 틀을 넘는 긴 낱말만 끊는다 */
html { overflow-wrap: break-word; -webkit-hyphens: none; hyphens: none; }
html:lang(ko) { word-break: keep-all; }
html:lang(ja) { word-break: auto-phrase; line-break: strict; }
/* 사파리(auto-phrase 없음): 문구에 넣은 U+200B(구절 경계, story.js는 이때만 넣는다)에서만 줄을 바꾼다 */
@supports not (word-break: auto-phrase) { html:lang(ja) { word-break: keep-all; } }
.nw { white-space: nowrap; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--k-ink); outline-offset: 2px; }
#side h1:focus, #side h2:focus, #card h2:focus, #card h1:focus { outline: none; }
.muted { color: var(--k-sub); }
svg.seed { vertical-align: -4px; }

/* ── 범례 낱말(.k-w)의 대상 색 ── */
.k-w.w-y { --w: var(--yl-p); }
.k-w.w-g { --w: var(--gn-p); }
.k-w.w-e { --w: var(--exp); text-decoration-style: dashed; }
.k-w { white-space: nowrap; } /* 범례 낱말은 짧다: 가운데서 끊지 않는다(사파리 일본어 포함) */

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--pw);
  grid-template-rows: var(--hdr) minmax(0, 1fr);
  grid-template-areas: "top top" "fig col";
  background: var(--k-paper);
}
#app.panel-open { --pw: clamp(min(360px, 50vw), 44%, 600px); }

/* ── 위 막대: 종이 위 글줄. 상자 없이 ── */
#top { grid-area: top; display: flex; align-items: center; gap: 6px; padding: 4px 10px 2px 6px; min-width: 0; }
.icon { flex: none; width: 40px; height: 40px; border: 0; border-radius: var(--k-r); background: transparent; color: var(--k-ink); display: grid; place-items: center; padding: 0; }
#chap { flex: 1; min-width: 0; padding: 0 8px; font-size: 16px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chTag { font-weight: 800; }
#chName { font-weight: 600; }
#chap .tag { font-weight: 600; color: var(--k-sub); }
#starsNow { flex: none; padding: 0 6px; font-size: 18px; color: var(--k-ink); white-space: nowrap; }
#starsNow:empty { display: none; }
#app[data-mode="title"] #btnMenu, #app[data-mode="title"] #starsNow { display: none; }
@media (hover: hover) { .icon:hover { background: var(--k-wash); } }

/* ── 정원 그림: 카드 없이 종이 위에 ── */
#fig { grid-area: fig; position: relative; min-width: 0; min-height: 0; overflow: hidden; margin: 4px 8px 12px 16px; background: #cfe3f2; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
/* ── 오른쪽 칸(휴대폰은 아래): 실험 판, 대화, 옆 창 ── */
#col { grid-area: col; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 4px 16px 12px 8px; gap: 0; }
#col > [hidden] { display: none !important; }

/* 이 장에서 별을 받는 세 가지(넓은 화면, 판이 없을 때) */
#goals { flex: none; padding: 6px 0 10px; }
#goals h2 { margin: 0 0 6px; font-size: 18px; font-weight: 800; line-height: 1.3; }
#goals .gsub { margin: 0 0 4px; font-size: 13.5px; font-weight: 650; color: var(--k-sub); }
#goals ul { margin: 0; padding-left: 18px; font-size: 14.5px; line-height: 1.55; }
#app.panel-open #goals, #app.side-open #goals { display: none; }
/* 대화: 멘델의 말과 선택지. 상자 없이 종이 위 글. 칸 아래쪽에 붙여 판이 열려도 자리가 바뀌지 않는다 */
#dialog { flex: none; display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 4px 12px; padding: 8px 0 0; min-height: 0; margin-top: auto; }
#panel:not([hidden]) + #dialog { border-top: 1px solid var(--k-rule); margin-top: 8px; padding-top: 10px; }
.who { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.portrait { width: 48px; height: 48px; flex: none; }
.portrait svg { width: 100%; height: 100%; display: block; }
#whoName { font-size: 12.5px; font-weight: 700; color: var(--k-sub); text-align: center; line-height: 1.2; }
.body { min-width: 0; }
#say { margin: 0 0 8px; font-size: 16px; line-height: 1.55; min-height: 2.6em; -webkit-user-select: text; user-select: text; }
#say .fb { font-weight: 800; }   /* 맞힘·틀림(✓ ✗)은 다음 대화글 맨 앞에 남는다 */
#say .tyRest { visibility: hidden; } /* 쓰는 중: 남은 글자는 자리만 차지한다 */
#choices { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
#choices:empty { display: none; }
#choices .tag { margin-right: auto; font-size: 14px; font-weight: 800; color: var(--k-ink); }
#choices .hint { margin-right: auto; font-size: 13px; color: var(--k-sub); }
#choices .k-btn { min-width: 104px; }
.opts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; width: 100%; }
.opts.grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.opts.multi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opt {
  display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 6px; min-height: 42px; padding: 5px 12px; text-align: left;
  border: 1.5px solid var(--k-ctl); border-radius: var(--k-r); background: var(--k-paper); color: var(--k-ink); font-size: 15px; font-weight: 600; line-height: 1.3;
}
.opt .n { color: var(--k-sub); font-variant-numeric: tabular-nums; }
/* 여러 개 고르기: 네모 칸에 ✓(색만으로 구별하지 않는다) */
.opt .ck { width: 18px; height: 18px; border: 1.5px solid var(--k-ctl); display: grid; place-items: center; font-size: 13px; font-weight: 800; line-height: 1; }
.opt.k-on { border-color: var(--k-ink); }
.opt.k-on .ck { border-color: var(--k-ink); }
.opt.k-on .ck::after { content: "✓"; }
.opts.multi .opt { font-weight: 700; }
@media (hover: hover) { .opt:not(:disabled):hover { background: var(--k-wash); } }

/* ── 실험 판 ── */
#panel { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; padding-top: 2px; }
.ptitle { flex: none; font-weight: 800; font-size: 16px; margin: 2px 0 4px; }
.phint { flex: none; margin: 0 0 8px; font-size: 14px; color: var(--k-sub); line-height: 1.45; }
/* 수확 판: 왼쪽 묶음(.hl)·오른쪽 묶음(.hr)은 보통 풀어서 원래 순서(order)로 쌓는다 */
.hl, .hr { display: contents; }
.o1 { order: 1; } .o2 { order: 2; } .o3 { order: 3; } .o4 { order: 4; } .o5 { order: 5; } .o6 { order: 6; }
.o7 { order: 7; } .o8 { order: 8; } .o9 { order: 9; } .o10 { order: 10; } .o11 { order: 11; }
/* 1장: 화분 네 개 */
.pots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.potcard { display: flex; flex-direction: column; gap: 6px; padding: 8px 0 10px; border-top: 1px solid var(--k-rule); min-width: 0; }
.potcard .ph { display: flex; align-items: center; gap: 6px; font-size: 14px; min-height: 22px; }
.potcard .fromtxt { font-size: 13px; color: var(--k-sub); margin-top: -4px; }
.potcard .harv { width: 100%; height: auto; min-height: 40px; white-space: normal; line-height: 1.2; padding: 4px 8px; }
.cnt { display: flex; gap: 8px; font-size: 14px; font-weight: 800; align-items: center; margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.verd { display: flex; width: 100%; }
.verd > button { flex: 1 1 0; min-width: 0; padding: 2px 4px; font-size: 13.5px; white-space: normal; }
/* 수확 */
.hbtns { flex: none; display: flex; gap: 8px; }
.hcol { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.hb { flex-direction: column; height: auto; min-height: 50px; padding: 4px 6px; gap: 0; white-space: normal; line-height: 1.2; }
.hb b { font-size: 14px; }
.hb small { font-size: 12.5px; font-weight: 600; color: var(--k-sub); }
.hb10 { white-space: normal; line-height: 1.15; padding: 0 6px; }
body.busy .hb, body.busy .hb10, body.busy .harv { opacity: 0.45; pointer-events: none; }
.chart { flex: none; margin-top: 8px; }
.chart canvas { width: 100%; display: block; }
canvas.bars { height: 120px; }
canvas.spread:not(.trait) { height: 150px; }
canvas.spread.trait { height: 106px !important; } /* 형질별 막대(두 줄)는 줄이지 않는다 */
.ratio, .totals { flex: none; font-size: 13.5px; line-height: 1.5; margin-top: 4px; }
.ratio b, .totals b { margin-right: 4px; }
.rr { font-weight: 800; white-space: nowrap; }
.rnote { flex: none; font-size: 13px; margin: 2px 0 0; }
.luck { flex: none; margin: 6px 0 0; font-size: 13px; line-height: 1.4; color: var(--k-ink-2); }
.luck b { color: var(--exp); }
.need { flex: none; font-size: 13.5px; color: var(--k-sub); margin: 6px 0 0; line-height: 1.4; }
.need.met { color: var(--ok-p); font-weight: 700; }
.need.met::before { content: "✓ "; font-weight: 800; }
.adv { font-weight: 600; color: var(--k-sub); }
/* 퍼넷 사각형 */
.pgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; max-width: 360px; width: 100%; margin: 0 auto; }
.pcorner { display: flex; align-items: center; justify-content: center; gap: 2px; font-size: 12.5px; color: var(--k-sub); text-align: center; line-height: 1.2; }
.pc { min-height: 52px; border: 1.5px dashed var(--k-ctl); border-radius: var(--k-r); background: var(--k-paper); font-size: 22px; font-weight: 800; color: var(--k-ink); }
.pc.hd { background: var(--k-wash); }
.pc.f { border-style: solid; border-color: var(--k-rule); }
.pc.f:disabled { opacity: 1; }
.pc.sel { border: 2.5px solid var(--k-ink); box-shadow: inset 0 -3px 0 var(--k-ink); }
.pc.rnd { background: #fbf3d0; }
.pc.wrk { background: #e7f0d6; }
.pc.shake { animation: shake 0.4s; border-color: var(--bad-p); }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.pcards { display: flex; gap: 8px; justify-content: center; margin-top: 10px; min-height: 48px; align-items: center; }
.card-btn { min-width: 64px; font-size: 20px; }
.pfoot { display: flex; justify-content: space-between; gap: 4px 8px; flex-wrap: wrap; font-size: 13.5px; margin-top: 8px; color: var(--k-sub); }
.pres { color: var(--k-ink); font-weight: 700; }
/* 교배 가까이 보기(꽃 그림): 그림은 그대로, 틀만 종이 */
.xsvg { display: block; width: 100%; height: auto; max-height: 250px; margin: 2px auto 0; touch-action: none; -webkit-user-select: none; user-select: none; }
.xsvg .xback { fill: #e3eed3; }
.xsvg .petal { fill: #ffffff; stroke: #c7b48a; stroke-width: 2; }
.xsvg .petal.wing { fill: #fbf7ee; }
.xsvg .keel { fill: #eef2da; stroke: #c8cf9e; stroke-width: 1.4; }
.xsvg .sepal { fill: #6fa84a; stroke: #4e7f33; stroke-width: 1.2; }
.xsvg .ovary { fill: #8cc45e; stroke: #4e7f33; stroke-width: 1.4; }
.xsvg .style { fill: none; stroke: #6aa84f; stroke-width: 4; stroke-linecap: round; }
.xsvg .stigma { fill: #a6d47a; stroke: #4e7f33; stroke-width: 1.6; }
.xsvg .fil { stroke: #c4b06a; stroke-width: 3; stroke-linecap: round; }
.xsvg .stub { stroke: #b9a96e; stroke-width: 3; stroke-linecap: round; }
.xsvg .anther { fill: #ecd05a; stroke: #8f6d10; stroke-width: 1.5; }
.xsvg .anther.ripe { fill: #f2a91c; stroke: #8a560a; }
.xsvg .pdot { fill: #ffd84d; stroke: #b98a10; stroke-width: 0.6; }
.xsvg .stamen { cursor: pointer; transition: transform 0.55s ease-in, opacity 0.55s ease-in; transform-box: fill-box; transform-origin: 50% 100%; }
.xsvg .stamen.gone { transform: translate(var(--dx), -70px) rotate(var(--rot)); opacity: 0; pointer-events: none; }
.xsvg .xlab text { paint-order: stroke; stroke: #ffffff; stroke-width: 3px; fill: var(--k-ink); }
.xsvg .xlab .lt { font: 800 13px var(--k-font); }
.xsvg .xlab .ls { font: 600 12px var(--k-font); fill: var(--k-sub); }
.xsvg .xlab path { fill: none; stroke: var(--k-ink-2); stroke-width: 1.2; stroke-dasharray: 3 2; }
.xsvg .tweez path { fill: none; stroke: #6b7280; stroke-width: 3; stroke-linecap: round; }
.xsvg .tweez { pointer-events: none; transition: opacity 0.2s; }
.xsvg .xhit { fill: transparent; cursor: pointer; pointer-events: all; }
.xsvg .xhit:focus { outline: none; }
.xsvg .xhit:focus-visible { stroke: var(--k-ink); stroke-width: 3; stroke-dasharray: 5 3; }
/* 꽃가루를 묻힐 곳: 점선 고리(깜빡이지 않는다), 묻힌 뒤에는 실선 */
.xsvg .xring { fill: none; stroke: var(--k-ink); stroke-width: 2; stroke-dasharray: 4 3; opacity: 0.8; pointer-events: none; }
.xsvg .xring.on { stroke-dasharray: none; stroke-width: 3; opacity: 1; }
.xsvg .brush { pointer-events: none; transition: transform 0.6s ease-in-out; }
.xsvg .brush .handle { stroke: #8b5a2b; stroke-width: 4; stroke-linecap: round; }
.xsvg .brush .tuft { fill: #f4e1a6; stroke: #a9874a; stroke-width: 1; transition: fill 0.3s; }
.xsvg .brush.loaded .tuft { fill: #f2b81c; }
.xwho { display: flex; align-items: flex-start; gap: 6px; font-size: 13.5px; line-height: 1.35; }
.xwho svg.seed { flex: 0 0 auto; margin-top: 1px; }
.xlabels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-top: 2px; }
.xstat { margin-top: 6px; min-height: 2.8em; font-size: 14px; font-weight: 700; line-height: 1.4; color: var(--k-ink); }
.xstat.ok { color: var(--ok-p); }
.xstat.ok::before { content: "✓ "; }
.xrow { display: flex; justify-content: flex-end; }

/* 판이 칸에 다 들어가지 않으면 덜 중요한 줄부터 접는다(main.js fitCol, 세로 휴대폰은 그림을 먼저 줄인다) */
#col.f1 .phint, #col.f1 .rnote, #col.f1 .potcard .fromtxt, #col.f1 .bars2, #col.f1 .ratio .muted { display: none; }
#col.f2 canvas.spread:not(.trait) { height: 96px; }
#col.f2 canvas.bars { height: 70px; }
#col.f2 .xsvg { max-height: 150px; }
#col.f2 .pc { min-height: 40px; font-size: 18px; }
#col.f2 .pcards { margin-top: 6px; }
#col.f3 #panel:not([hidden]) + #dialog .who { display: none; }
#col.f3 #panel:not([hidden]) + #dialog { grid-template-columns: 1fr; padding-top: 6px; margin-top: 6px; }
#col.f3 #say { font-size: 14px; line-height: 1.4; }
#col.f3 .ptitle { font-size: 14px; }
#col.f4 canvas.spread:not(.trait) { height: 84px; }
#col.f4 canvas.bars { height: 58px; }
#col.f4 .xsvg { max-height: 120px; }
#col.f4 .hb { min-height: 40px; }
#col.f4 .hb small { display: none; }
#col.f5 .ratio { display: none; }
#col.f5 canvas.spread:not(.trait) { height: 76px; }
#col.f5 canvas.bars { height: 52px; }
#col.f6 .ptitle, #col.f6 .luck, #panel.review .ratio { display: none; }
#col.f6 .chart { margin-top: 2px; }
#col.f6 canvas.spread.trait { height: 100px !important; }
#col.f6 .need, #col.f6 .luck { font-size: 12.5px; line-height: 1.35; margin-top: 2px; }
#col.f6 .totals, #col.f6 .ratio { font-size: 12px; }
/* 다 한 판(돌아보기): 수확 단추·조건 안내를 접는다. 퍼넷은 카드 줄을 접는다 */
#panel.review .hbtns, #panel.review .need, #panel.review .luck, #panel.review .rnote, #panel.review .phint, #panel.review .pcards { display: none; }
/* 세로 휴대폰에서 그림을 다 접은 경우(fitCol 마지막 단계) */
#app[style*="--figS: 0px"] #fig { display: none; }

/* ── 창 두 가지(studio/DESIGN.md '창') ──
   옆 창 #side(처음 화면, 장 결과): 막 없이 오른쪽 칸(휴대폰은 아래)에. 가운데 창 #modal(장 고르기, 마무리): 뒤를 --k-dim으로 */
.card { display: flex; flex-direction: column; background: var(--k-paper); color: var(--k-ink); border-radius: 0; }
.card h2 { margin: 0 0 6px; font-size: 18px; font-weight: 800; line-height: 1.3; }
.card h2 .tag { font-size: 14px; font-weight: 650; color: var(--k-sub); }
.card p { margin: 6px 0; font-size: 15px; line-height: 1.55; }
.card p.q { margin: 12px 0 4px; font-size: 19px; font-weight: 750; line-height: 1.4; }
.card .cb { flex: 0 1 auto; min-height: 0; overflow: auto; }
.acts2 { flex: none; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.acts2 .k-btn { height: 44px; padding: 0 16px; }
.acts2 .k-primary, .acts2 .k-link + .k-btn { margin-left: auto; }
#side { flex: 1 1 auto; min-height: 0; padding: 4px 0 0; }
#side .k-start { flex: 1; min-height: 0; height: 100%; padding: 6px 2px 4px 6px; }
#side .k-start .k-q { margin: 0; }
#side .k-start h1.k-q { font-weight: 800; }
#side .k-start p.k-q { font-weight: 700; }
#side .k-start .k-note { margin-top: auto; }
#side .k-start .k-link { white-space: nowrap; }
#side .k-start .k-modes { grid-template-columns: minmax(0, 1fr); }
.k-stage .k-t .adv { color: var(--k-sub); font-weight: 600; }
/* 결과: 별 세 줄과 기준 */
.res { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
.res li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 6px; align-items: start; font-size: 15px; line-height: 1.4; }
.res .s { font-size: 20px; line-height: 1.1; }
.card .bigstars { margin: 2px 0 4px; font-size: 30px; }
.insight { padding-top: 8px; border-top: 1px solid var(--k-rule); }
.insight b { display: block; }
#modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--k-dim); padding: 12px; }
#modal .card { width: min(560px, 100%); max-height: calc(100vh - 24px); padding: 20px 22px 18px; }
.levels { list-style: none; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.lvrow {
  display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 6px; width: 100%; min-height: 44px;
  padding: 6px 4px; border: 0; border-top: 1px solid var(--k-rule); background: none; text-align: left; font-size: 15px; color: var(--k-ink);
}
.levels li:last-child .lvrow { border-bottom: 1px solid var(--k-rule); }
.lvrow .n { color: var(--k-sub); font-variant-numeric: tabular-nums; }
.lvrow .t { font-weight: 650; line-height: 1.3; }
.lvrow .st { font-size: 15px; white-space: nowrap; }
.lvrow[aria-current="true"] { box-shadow: inset 0 -3px 0 var(--k-ink); }
@media (hover: hover) { .lvrow:hover { background: var(--k-wash); } }
.sub { margin: 0 0 6px; font-size: 14px; color: var(--k-sub); font-variant-numeric: tabular-nums; }
.endstars { display: flex; flex-wrap: wrap; gap: 2px 16px; margin: 4px 0; font-size: 18px; }
.endstars span { white-space: nowrap; }
.endstars .n { font-size: 13px; color: var(--k-sub); margin-right: 4px; }
.mquote { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 10px; align-items: start; }
.mquote .portrait { width: 40px; height: 40px; }
.mquote p { margin: 0; font-size: 14.5px; }
.sum { margin: 6px 0; padding-left: 20px; font-size: 14.5px; line-height: 1.5; }
/* 마무리를 두 쪽으로(낮은 화면) */
.pgP, .pgN { display: none !important; }
.card.paged:not(.pg2) .eB, .card.paged.pg2 .eA, .card.paged:not(.pg2) .pgB, .card.paged.pg2 .pgN { display: none !important; }
.card.paged:not(.pg2) .pgN, .card.paged.pg2 .pgP { display: inline-flex !important; }

/* ── 낮은 가로 화면(사이트 데스크톱 틀 830×466 등): 판·대화를 촘촘하게 ── */
@media (max-height: 560px) and (min-aspect-ratio: 11/10) {
  :root { --hdr: 46px; }
  #goals h2 { font-size: 16px; }
  #goals ul { font-size: 13.5px; line-height: 1.45; }
  #chap { font-size: 15px; }
  #say { font-size: 14.5px; line-height: 1.45; margin-bottom: 6px; min-height: 0; }
  .portrait { width: 40px; height: 40px; }
  #dialog { grid-template-columns: 40px minmax(0, 1fr); gap: 2px 10px; }
  .opt { min-height: 36px; font-size: 14px; padding: 3px 10px; }
  .ptitle { font-size: 15px; margin: 0 0 2px; }
  .phint { font-size: 13px; line-height: 1.35; margin-bottom: 6px; }
  .potcard { gap: 4px; padding: 6px 0; }
  .potcard .fromtxt { display: none; } /* 머리말의 씨 그림이 같은 정보 */
  canvas.bars { height: 84px; }
  canvas.spread:not(.trait) { height: 110px; }
  .ratio, .totals { font-size: 12.5px; line-height: 1.4; margin-top: 2px; }
  .chart { margin-top: 4px; }
  .xsvg { max-height: 200px; }
  .xsvg.x2 { max-height: 170px; }
  .pc { min-height: 44px; font-size: 20px; }
  .card p.q { font-size: 17px; margin-top: 8px; }
  .card p { font-size: 14px; line-height: 1.5; }
  .acts2 { margin-top: 8px; }
  .acts2 .k-btn { height: 40px; }
  .card .bigstars { display: none; }
  .res li { font-size: 14px; }
  .sum, .mquote p { font-size: 13.5px; line-height: 1.45; }
}

/* ── 세로 화면: 위 막대, 그림, 아래 칸(판 + 대화). 판이나 옆 창이 뜨면 그림을 줄인다(--figS, main.js fitCol) ── */
@media (max-aspect-ratio: 11/10) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--hdr) minmax(0, 1fr) auto; grid-template-areas: "top" "fig" "col"; }
  #app.panel-open, #app.side-open { grid-template-rows: var(--hdr) var(--figS, 30vh) minmax(0, 1fr); }
  #top { padding: 4px 4px 2px 2px; }
  #fig { margin: 2px 10px 0; }
  #col { padding: 6px 10px 10px; }
  #goals { display: none !important; }
  #dialog { grid-template-columns: 40px minmax(0, 1fr); gap: 2px 10px; }
  .portrait { width: 40px; height: 40px; }
  #modal { padding: 10px; }
  #modal .card { padding: 16px 14px 14px; }
}
@media (max-aspect-ratio: 11/10) and (max-width: 520px) {
  #starsNow { display: none; }
  #chap { font-size: 14px; line-height: 1.25; white-space: normal; overflow: visible; } /* 좁으면 두 줄 */
}
/* 세로 휴대폰(341×470~390×604) */
@media (max-aspect-ratio: 11/10) and (max-height: 640px) {
  :root { --hdr: 48px; }
  #say { font-size: 15px; line-height: 1.5; min-height: 0; margin-bottom: 6px; }
  #dialog { grid-template-columns: 1fr; gap: 4px; }
  .who { flex-direction: row; gap: 8px; }
  .portrait { width: 30px; height: 30px; }
  #whoName { font-size: 13px; }
  .opt { min-height: 40px; font-size: 14px; padding: 3px 10px; }
  .opts:not(.multi) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } /* 긴 보기도 두 단(대화가 판 자리를 덜 먹게) */
  .ptitle { font-size: 15px; margin: 0 0 2px; }
  .phint { font-size: 13px; line-height: 1.35; margin-bottom: 4px; }
  .potcard { gap: 4px; padding: 6px 0; }
  .potcard .fromtxt { display: none; }
  .cnt { font-size: 13px; gap: 6px; }
  canvas.bars { height: 80px; }
  canvas.spread:not(.trait) { height: 104px; }
  .ratio, .totals { font-size: 12.5px; line-height: 1.4; margin-top: 2px; }
  .chart { margin-top: 4px; }
  .xsvg { max-height: 180px; }
  .xsvg.x2 { max-height: 150px; }
  .xstat { min-height: 0; font-size: 13.5px; }
  .pc { min-height: 42px; font-size: 19px; }
  .card p.q { font-size: 17px; margin-top: 8px; }
  .card p { font-size: 14px; line-height: 1.5; }
  .card .bigstars { display: none; }
  .res { gap: 3px; margin: 6px 0; }
  .res li { font-size: 14px; line-height: 1.35; }
  .acts2 { gap: 6px; margin-top: 8px; }
  .acts2 .k-btn { height: 40px; padding: 0 10px; font-size: 14px; }
  .sum, .mquote p { font-size: 13.5px; line-height: 1.45; }
}
/* 아주 작은 틀(320×200 등): 판과 창 안 스크롤 허용, 얼굴 그림을 접는다 */
@media (max-height: 360px) {
  :root { --hdr: 40px; --pw: clamp(200px, 50%, 440px); }
  #app.panel-open, #app.side-open { --pw: clamp(220px, 60%, 520px); }
  #top { padding: 2px 6px 0 4px; }
  #chap { font-size: 13.5px; line-height: 1.2; white-space: normal; overflow: visible; } /* 좁으면 두 줄 */
  #fig { margin: 2px 6px 6px 10px; }
  #col { padding: 2px 8px 4px 4px; overflow: auto; }
  #goals { display: none !important; }
  #panel { overflow: visible; flex: none; }
  #side { flex: none; }
  #side .cb { overflow: visible; }
  .who { display: none; }
  #dialog { grid-template-columns: 1fr; }
  #say { font-size: 13.5px; line-height: 1.4; margin: 0 0 4px; min-height: 0; }
  .opt { min-height: 36px; font-size: 13px; padding: 2px 8px; }
  .opts:not(.multi) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .card .bigstars { display: none; }
  .card p.q { font-size: 15px; }
  .card p { font-size: 13px; margin: 3px 0; line-height: 1.4; }
  .card h2 { font-size: 15px; }
  .acts2 { margin-top: 6px; gap: 6px; }
  .acts2 .k-btn { height: 36px; padding: 0 10px; font-size: 13.5px; }
  .res { gap: 2px; margin: 4px 0; }
  .res li { font-size: 13px; }
  canvas.bars { height: 80px; }
  canvas.spread:not(.trait) { height: 100px; }
  .xsvg { max-height: 140px; }
  #modal .card { padding: 12px 14px; }
  .lvrow { min-height: 36px; padding: 2px 4px; font-size: 14px; }
  .levels { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 14px; }
  .levels li:nth-last-child(2) .lvrow { border-bottom: 1px solid var(--k-rule); }
}
/* 낮은 가로 화면(750×280 등, 320×200 제외): 칸 안 스크롤 없이. 판을 넓히고 두 단(왼쪽 조작·글, 오른쪽 그래프·그림)으로 */
@media (max-height: 360px) and (min-height: 241px) and (min-aspect-ratio: 11/10) {
  #col { overflow: hidden; }
  #panel { flex: 1 1 auto; overflow: hidden; }
  #side { flex: 1 1 auto; }
  #side .cb { overflow: auto; }
  #app.panel-open, #app.side-open { --pw: clamp(260px, 68%, 640px); }
  #panel:has(.hl), #panel:has(.pgrid), #panel:has(.xsvg) { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-content: start; column-gap: 12px; }
  #panel .hl, #panel .hr { display: block; min-width: 0; }
  #panel:has(.pgrid) > *, #panel:has(.xsvg) > * { grid-column: 1; }
  #panel > .xsvg, #panel > .pgrid { grid-column: 2; grid-row: 1 / span 6; margin-top: 0; }
  #panel .hr .chart:first-child { margin-top: 0; }
  #panel > .pots { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px 8px; }
  #panel .potcard .ph { flex-wrap: wrap; gap: 2px 6px; font-size: 13px; }
  #panel .cnt { font-size: 12.5px; gap: 4px; margin-left: 0; }
  #panel .xsvg { max-height: 170px; }
  #panel .potcard { padding: 4px 0; gap: 3px; }
  #panel .potcard .fromtxt, #panel .phint { display: none; }
  #panel .verd > button { font-size: 12.5px; line-height: 1.15; }
  .pc { min-height: 36px; font-size: 17px; }
  .pgrid { gap: 4px; }
  canvas.spread:not(.trait) { height: 130px; }
  canvas.bars { height: 76px; }
  #panel:not([hidden]) + #dialog { margin-top: 4px; padding-top: 4px; }
  #choices .k-btn { min-width: 80px; }
  /* 판이 열려 있을 때 대화는 글과 단추를 한 줄에(보기가 있으면 아래로) */
  #panel:not([hidden]) + #dialog .body:not(:has(.opts)) { display: flex; align-items: flex-end; gap: 10px; }
  #panel:not([hidden]) + #dialog .body:not(:has(.opts)) #say { flex: 1 1 auto; margin: 0; }
  #panel:not([hidden]) + #dialog .body:not(:has(.opts)) #choices { flex: none; }
  #col.f2 canvas.bars { height: 50px; }
  #col.f2 canvas.spread.trait { height: 100px !important; }
  .hb { min-height: 40px; padding: 2px 4px; }
  .hb small { display: none; } /* 씨 수는 그래프 아래 글자(8개, 400개)에 있다 */
  .need { font-size: 12.5px; line-height: 1.35; margin-top: 2px; }
  #panel .luck { display: none; }
  /* 4장 돌아보기: 질문(독립의 법칙)에 필요한 형질별 막대만 */
  #panel.review .hr:has(.o6) .o4 { display: none; }
}
@media (max-height: 240px) {
  #modal .card .cb { overflow: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .xsvg .stamen, .xsvg .brush { transition: none; }
  .pc.shake { animation: none; }
}

/* 썸네일(window.game.thumb): 장면만 화면 가득 */
#app.thumb { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "fig"; }
#app.thumb > :not(#fig) { display: none !important; }
#app.thumb #fig { margin: 0; }
