/* 레이아웃: 위에서 아래로 — 상태 머리줄 / 도트 방 / 상태 막대 / 돌봄 버튼.
   태블릿 가로에서는 방(왼쪽)과 돌봄 패널(오른쪽)로 나뉜다.
   화면 테마 두 가지: 밤(기본, 짙은 가지색) / 아이보리(밝은 낮). <html data-skin="ivory">로 바꾼다.
   방(도트 그림)은 두 테마 모두 그대로 쓴다. */
:root {
  --ink: #18132a;
  --panel: #241d3c;
  --panel-2: #30284f;
  --line: #4a3e76;
  --line-hi: #6a5ca3;
  --shade: #120e22;
  --well: #120e22;
  --frame: #0d0a18;
  --text: #f4ecdc;
  --muted: #b3a8d1;
  --lamp: #ffb45e;
  --lamp-ink: #2b1a08;
  --lamp-text: #ffb45e;
  --portal: #7be3c8;
  --accent-text: #7be3c8;
  --mint-soft: #2b4a44;
  --rose: #ff8aa8;
  --good: #8fe08a;
  --warn: #ffd166;
  --bad: #ff7f7f;
  --bad-text: #ff7f7f;
  --badge-bg: #ee3f5c;
  --badge-fg: #ffffff;
  --bar-empty: #3a3160;
  --pick-on-bg: #ffb45e;
  --pick-on-fg: #2b1a08;
  --pick-on-line: #4a3e76;
  --chip-bg: #7be3c8;
  --chip-fg: #10302a;
  --tip-bg: #1d2f2c;
  --tip-fg: #d8f6ec;
  --crisis-bg: #3a2140;
  --backdrop: rgba(8, 6, 18, 0.62);
  --speech-bg: rgba(24, 19, 42, 0.94);
  --logo-shadow: #3d2f6b;
  --rarity-l: 70%;
  /* 상태 막대 항목 색 */
  --st-full: #ffb45e; --st-clean: #7cc8ff; --st-mood: #ff8aa8; --st-energy: #ffd166; --st-health: #8fe08a; --st-bond: #c8a2ff;
  --st-warm: #ff9f68; --st-hatch: #7be3c8; --st-talk: #c8a2ff;
  --font-display: 'Do Hyeon', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-body: 'Gowun Dodum', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-pixel: 'Silkscreen', ui-monospace, 'Courier New', monospace;
  --display-weight: 400;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2.25rem;
  --px: 3px;
  color-scheme: dark;
}
/* 아이보리: 아이보리 바탕, 흰 상태창·버튼에 회보라 테두리, 가지색 글자, 선택은 민트 */
:root[data-skin="ivory"] {
  --ink: #F7F4ED;
  --panel: #FFFDFA;
  --panel-2: #FFFDFA;
  --line: #D8D2E2;
  --line-hi: #C3B9D3;
  --shade: #CFC7DC;
  --well: #EFEBF4;
  --frame: #BDB3CF;
  --text: #352D47;
  --muted: #6F6684;
  --lamp-text: #B4650F;
  --accent-text: #1E8A72;
  --mint-soft: #E4F6F0;
  --bad-text: #C24634;
  --badge-bg: #D6304C;
  --good: #2E8B4A;
  --warn: #A8770A;
  --bar-empty: #ECE8F1;
  --pick-on-bg: #E4F6F0;
  --pick-on-fg: #1E6E5C;
  --pick-on-line: #5CC6AC;
  --chip-bg: #E4F6F0;
  --chip-fg: #1E6E5C;
  --tip-bg: #E8F6F1;
  --tip-fg: #24584C;
  --crisis-bg: #FBEAEE;
  --backdrop: rgba(53, 45, 71, 0.38);
  --speech-bg: rgba(255, 253, 250, 0.97);
  --logo-shadow: #D8D2E2;
  --rarity-l: 40%;
  --st-full: #E58A2E; --st-clean: #3B8FD0; --st-mood: #E0577F; --st-energy: #D49B12; --st-health: #3FA562; --st-bond: #8B63CF;
  --st-warm: #E57A45; --st-hatch: #2FA88A; --st-talk: #8B63CF;
  color-scheme: light;
}

/* 글씨체: 기본(도현 + 고운돋움) / 맑은 고딕 / Galmuri(못 불러오면 Noto Sans KR) */
:root[data-font="malgun"] {
  --font-display: 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  --font-body: 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  --display-weight: 700;
}
:root[data-font="galmuri"] {
  --font-display: 'Galmuri11', 'Noto Sans KR', sans-serif;
  --font-body: 'Galmuri11', 'Noto Sans KR', sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.55;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
img, canvas { max-width: 100%; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
h1, h2, h3 { font-family: var(--font-display); font-weight: var(--display-weight); text-wrap: balance; margin: 0; letter-spacing: 0.01em; }
:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

/* 픽셀 테두리: 모서리가 깎인 도트 상자 */
.px {
  box-shadow: 0 calc(-1 * var(--px)) 0 0 var(--line), 0 var(--px) 0 0 var(--line), calc(-1 * var(--px)) 0 0 0 var(--line), var(--px) 0 0 0 var(--line);
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1280px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ── 머리줄 ── */
.hud {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  grid-template-areas: "id dust skin menu" "meta dust skin menu";
  grid-template-rows: 26px 18px;
  align-items: center;
  column-gap: 10px;
  padding-block: 10px 8px;
}
.hud-id { grid-area: id; display: flex; align-items: center; gap: 8px; min-width: 0; height: 26px; }
.hud-name { font-family: var(--font-display); font-weight: var(--display-weight); font-size: var(--step-2); line-height: 26px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 세 줄 머리: 이름이 안 들어가는 좁은 화면(360px 이하, 또는 이름이 잘릴 때 JS가 붙인다)
   1줄 이름(가로 전체) / 2줄 단계 칩 / 3줄 나이·시각. 오른쪽 세 칸은 2~3줄(44px)과 위아래를 맞춘다 */
.hud.tall { grid-template-areas: "name name name name" "chip dust skin menu" "meta dust skin menu"; grid-template-rows: 30px 26px 18px; }
.hud.tall .hud-id { display: contents; }
.hud.tall .hud-name { grid-area: name; line-height: 30px; }
.hud.tall .chip { grid-area: chip; justify-self: start; align-self: center; }
.hud-meta { grid-area: meta; color: var(--muted); font-size: 12.5px; line-height: 18px; height: 18px; align-self: end; display: flex; gap: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; min-width: 0; }
:root[data-font="galmuri"] .hud-meta { font-size: 12px; } /* Galmuri11은 12px에서 가장 또렷하다 */
.hud-dust { grid-area: dust; display: flex; align-items: center; gap: 6px; height: 44px; min-width: 64px; justify-content: center; background: var(--panel); padding: 0 10px; font-family: var(--font-pixel); font-size: 0.9375rem; line-height: 1; font-variant-numeric: tabular-nums; box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line); }
.hud-dust img { image-rendering: pixelated; }
.chip {
  font-family: var(--font-display); font-weight: var(--display-weight);
  font-size: 0.875rem;
  line-height: 20px;
  background: var(--chip-bg);
  color: var(--chip-fg);
  box-shadow: 0 0 0 1px var(--pick-on-line);
  padding: 1px 8px;
  white-space: nowrap;
}
.icon-btn {
  grid-area: menu;
  width: 44px; height: 44px; padding: 0; box-sizing: border-box; align-self: center;
  display: grid; place-items: center;
  background: var(--panel-2);
  border: 0;
  cursor: pointer;
  font-size: 1.1rem;
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
}
.icon-btn:active { transform: translateY(1px); }
.icon-btn.skin { grid-area: skin; }
.icon-btn.skin img { width: 22px; height: 22px; image-rendering: pixelated; }
.burger, .burger::before, .burger::after { display: block; width: 18px; height: 3px; background: var(--text); position: relative; content: ""; }
.burger::before { position: absolute; top: -6px; }
.burger::after { position: absolute; top: 6px; }

/* ── 본문 ── */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-bottom: 12px;
}
.stage { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.scene-wrap {
  position: relative;
  align-self: center;
  line-height: 0;
  box-shadow: 0 -4px 0 0 var(--frame), 0 4px 0 0 var(--frame), -4px 0 0 0 var(--frame), 4px 0 0 0 var(--frame), 0 0 0 4px var(--line);
  touch-action: manipulation;
}
#scene { display: block; cursor: pointer; }
/* 알림 줄: 늘 한 줄. 상태 변화 같은 세부 내용은 '더보기'를 누르면 잠깐 펼쳐졌다가 저절로 사라진다 */
.ticker-row { position: relative; display: flex; justify-content: center; align-items: center; gap: 6px; min-width: 0; margin-top: 4px; min-height: 1.5em; }
.ticker { margin: 0; min-width: 0; font-size: var(--step--1); line-height: 1.5; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-inline: 4px; }
.ticker-more { flex: none; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.75rem; line-height: 1; color: var(--accent-text); background: var(--panel-2); border: 0; padding: 4px 8px; cursor: pointer; box-shadow: 0 0 0 1px var(--line); }
.ticker-more[aria-expanded="true"] { color: var(--text); }
.ticker-detail { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 4; display: grid; gap: 8px; padding: 10px 12px; background: var(--panel); box-shadow: 0 0 0 2px var(--line), 0 10px 18px rgba(0, 0, 0, 0.35); font-size: var(--step--1); line-height: 1.5; color: var(--text); text-align: left; }
.ticker-detail p { margin: 0; }
.ticker-detail.fading { animation: tickerFade 0.6s forwards; }
@keyframes tickerFade { to { opacity: 0; transform: translateY(-4px); } }
/* 휴대폰: 방과 상태창 사이를 절반으로. 방 테두리(4px 그림자)와 글이 겹치지 않게 방 아래 10px은 남긴다 */
@media (max-width: 600px) {
  .main { gap: 5px; }
  .stage { gap: 10px; }
  .ticker-row { margin-top: 0; min-height: 18px; }
  .ticker-more { padding: 3px 7px; font-size: 0.6875rem; }
  .ticker { line-height: 1.4; }
}

/* 말풍선 */
.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  max-width: min(78%, 280px);
  width: max-content;
  background: #fffaf0;
  color: #2a2140;
  font-family: var(--font-display); font-weight: var(--display-weight);
  font-size: 1.0625rem;
  line-height: 1.3;
  padding: 6px 10px;
  box-shadow: 0 -3px 0 0 #2a2140, 0 3px 0 0 #2a2140, -3px 0 0 0 #2a2140, 3px 0 0 0 #2a2140;
  pointer-events: none;
  animation: pop 0.18s steps(3) both;
}
.bubble::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -9px;
  width: 6px; height: 6px;
  background: #fffaf0;
  box-shadow: 0 3px 0 0 #2a2140, -3px 0 0 0 #2a2140, 3px 0 0 0 #2a2140;
  transform: translateX(-50%);
}
.bubble.guest { background: #e6fbf4; }
.bubble.guest::after { background: #e6fbf4; }
.shelf-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; background: #3a2a22; padding: 10px; }
.shelf-grid .tier { grid-column: 1 / -1; height: 4px; background: #6b4a33; }
.slot { aspect-ratio: 1; background: rgba(255, 255, 255, 0.06); border: 0; display: grid; place-items: center; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12); min-width: 0; }
.slot img { width: 60%; height: auto; image-rendering: pixelated; }
.slot.empty { cursor: default; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08); }
.slot.empty::after { content: "빈 칸"; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.75rem; color: rgba(255, 255, 255, 0.35); }
@keyframes pop { from { transform: translate(-50%, -88%) scale(0.85); opacity: 0; } to { transform: translate(-50%, -100%) scale(1); opacity: 1; } }

/* 방 왼쪽 위: 시계(시간 흐름) 버튼과 상태 칩. 칩은 누름을 방으로 흘려보낸다 */
.room-hud { position: absolute; left: 6px; top: 6px; right: 64px; display: flex; align-items: flex-start; gap: 6px; line-height: 1.2; pointer-events: none; }
.room-hud[hidden] { display: none !important; }
.speed-wrap { position: relative; pointer-events: auto; flex: none; }
.speed-btn { display: flex; align-items: center; gap: 4px; height: 26px; padding: 0 7px 0 4px; border: 0; cursor: pointer; background: rgba(24, 19, 42, 0.86); color: #f4ecdc; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.8125rem; box-shadow: 0 0 0 1px rgba(244, 236, 220, 0.25); }
.speed-btn img { width: 18px; height: 18px; image-rendering: pixelated; }
.speed-btn.fast { color: #ffd166; box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.6); }
.speed-btn:active { transform: translateY(1px); }
.speed-menu { position: absolute; left: 0; top: 30px; z-index: 3; min-width: 9.5em; background: #241d3c; box-shadow: 0 0 0 2px #4a3e76, 0 6px 14px rgba(0, 0, 0, 0.4); padding: 4px; display: grid; gap: 2px; }
.speed-menu button { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; border: 0; cursor: pointer; background: transparent; color: #f4ecdc; text-align: left; padding: 7px 8px; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; }
.speed-menu button small { font-family: var(--font-body); font-weight: 400; font-size: 0.75rem; color: #b3a8d1; }
.speed-menu button:hover { background: #30284f; }
.speed-menu button[aria-checked="true"] { background: #2b4a44; color: #7be3c8; }
.status-chips { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; padding-top: 3px; }
/* 이세계 파티 중: 위쪽에 함께한 친구 이름과 '돌아가기' */
.party-bar { position: absolute; left: 6px; right: 6px; top: 6px; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; line-height: 1.3; pointer-events: none; }
.party-bar[hidden] { display: none; }
.party-title { min-width: 0; background: rgba(24, 19, 42, 0.84); color: #ffe9b0; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.8125rem; padding: 3px 8px; }
.party-back { pointer-events: auto; flex: none; border: 0; cursor: pointer; background: var(--lamp); color: var(--lamp-ink); font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; padding: 5px 12px; box-shadow: 0 2px 0 0 #a8661f, 0 0 0 1px rgba(0, 0, 0, 0.25); }
.party-back:active { transform: translateY(1px); }
/* 파티 친구 고르기 */
.party-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.party-pick button { display: grid; justify-items: center; gap: 2px; padding: 6px 4px 8px; border: 0; cursor: pointer; background: var(--panel-2); color: var(--text); box-shadow: 0 0 0 2px var(--line); font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; line-height: 1.25; }
.party-pick button canvas { width: 72px; height: 72px; image-rendering: pixelated; }
.party-pick button small { font-family: var(--font-body); font-weight: 400; font-size: 0.6875rem; color: var(--muted); }
.party-pick button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent-text); background: var(--mint-soft); }
.party-pick button:disabled { opacity: 0.45; cursor: default; }
/* 방 그림 위에 얹히는 표시는 두 테마 모두 같은 어두운 바탕을 쓴다 */
.status-chips span { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.8125rem; padding: 1px 6px; background: rgba(24, 19, 42, 0.82); color: #f4ecdc; }
.status-chips .bad { color: #ff9a9a; }
.status-chips .warn { color: #ffd166; }
.status-chips .good { color: #7be3c8; }
.status-chips .info { color: #c8b8ff; }
.away-note {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: rgba(24, 19, 42, 0.88); color: #f4ecdc; padding: 6px 12px; line-height: 1.3;
  font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; white-space: nowrap;
}

/* ── 상태 막대 ── */
.panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  background: var(--panel);
  box-shadow: 0 0 0 2px var(--line);
  padding: 12px 14px;
}
.stat { display: grid; grid-template-columns: 4.2em 1fr minmax(2.2em, auto); align-items: center; gap: 8px; min-width: 0; }
.stat-label { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; color: var(--muted); white-space: nowrap; }
.stat-val { font-family: var(--font-pixel), var(--font-display); font-size: 0.75rem; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; height: 12px; }
.bar i { background: var(--bar-empty); }
.bar i.on { background: var(--c, var(--portal)); }
.stat.low .stat-label { color: var(--bad-text); }
.stat.low .bar i.on { background: var(--bad); }
.stat.low .bar { animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.55; } }

/* ── 돌봄 버튼 ── */
.actions { display: grid; grid-template-columns: repeat(var(--act-cols, 4), minmax(0, 1fr)); gap: 10px; padding: 3px; }
.act {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 70px;
  background: var(--panel-2);
  border: 0;
  cursor: pointer;
  font-family: var(--font-display); font-weight: var(--display-weight);
  font-size: 1rem;
  line-height: 1.1;
  padding: 8px 4px;
  box-shadow: 0 -3px 0 0 var(--line), 0 3px 0 0 var(--shade), -3px 0 0 0 var(--line), 3px 0 0 0 var(--line), inset 0 -4px 0 0 rgba(0, 0, 0, 0.12);
  position: relative;
}
.act img { width: 30px; height: 30px; image-rendering: pixelated; }
.act:active { transform: translateY(2px); box-shadow: 0 -3px 0 0 var(--line), 0 1px 0 0 var(--shade), -3px 0 0 0 var(--line), 3px 0 0 0 var(--line); }
.act[disabled] { opacity: 0.45; cursor: default; }
/* 알림 배지: 버튼 모서리에 걸친 느낌표. 장식 점으로 보이지 않게 크기와 테두리를 주고, 가끔 톡 튄다 */
.act .dot, .tile .dot {
  position: absolute; z-index: 1;
  display: grid; place-items: center;
  width: 18px; height: 18px;
  background: var(--badge-bg); color: var(--badge-fg);
  font: 700 0.8125rem/1 var(--font-pixel); font-style: normal;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink);
  animation: badgeHop 2.4s steps(1) infinite;
  pointer-events: none;
}
.act .dot::before, .tile .dot::before { content: '!'; }
.act .dot { top: -5px; right: -3px; }
@keyframes badgeHop { 0%, 12%, 24%, 100% { transform: translateY(0); } 6%, 18% { transform: translateY(-3px); } }
.act.primary { background: var(--lamp); color: var(--lamp-ink); }

/* ── 바텀 시트 ── */
.backdrop { position: fixed; inset: 0; background: var(--backdrop); z-index: 20; }
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 640px);
  max-height: min(82%, 720px);
  display: flex; flex-direction: column;
  background: var(--panel);
  z-index: 21;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -4px 0 0 var(--line-hi);
  animation: rise 0.2s steps(4) both;
}
@keyframes rise { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); }
.sheet-head h2 { font-size: var(--step-2); }
.sheet-body { overflow-y: auto; padding: 4px max(16px, env(safe-area-inset-right, 0px)) 20px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 10px; }
.sheet-note { color: var(--muted); font-size: var(--step--1); margin: 0; }

.opt {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border: 0;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
}
.opt img, .opt canvas { width: 40px; height: 40px; image-rendering: pixelated; }
.opt-title { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.0625rem; line-height: 1.25; display: block; }
.opt-desc { font-size: var(--step--1); color: var(--muted); display: block; line-height: 1.45; }
.opt-side { font-family: var(--font-pixel); font-size: 0.75rem; color: var(--lamp-text); white-space: nowrap; }
.opt[disabled] { opacity: 0.45; cursor: default; }
.opt-group { display: flex; flex-direction: column; gap: 10px; }
.group-title { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1rem; color: var(--accent-text); margin: 8px 0 0; letter-spacing: 0.02em; }

/* 상자 버튼 고르기(먹이·돌봄·놀기·상점): 상자를 한 번 누르면 바로 실행된다. 마우스를 올리거나 길게 누르면 아래 설명 칸에 설명이 나온다 */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; padding: 2px; }
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 5px;
  min-height: 78px; min-width: 0;
  padding: 10px 3px 7px;
  border: 0; cursor: pointer;
  background: var(--panel-2); color: var(--text);
  font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; line-height: 1.2; text-align: center; word-break: keep-all;
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
}
.tile img { flex: none; width: 32px; height: 32px; image-rendering: pixelated; }
.tile-name { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.tile-side { font-family: var(--font-pixel); font-size: 0.6875rem; line-height: 1; color: var(--lamp-text); white-space: nowrap; }
.tile .tile-side { position: absolute; top: 4px; right: 4px; }
.tile .dot { top: -4px; left: -3px; }
.tile { touch-action: manipulation; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } /* 길게 눌러 설명을 볼 때 글자 선택·그림 메뉴가 뜨지 않게 */
.tile img { pointer-events: none; }
.tile.off > img, .tile.off > .tile-name, .tile.off > .tile-side { opacity: 0.42; }
.tile:active { transform: translateY(1px); }
.tile.peek { box-shadow: 0 -3px 0 0 var(--accent-text), 0 3px 0 0 var(--accent-text), -3px 0 0 0 var(--accent-text), 3px 0 0 0 var(--accent-text); } /* 설명 칸에 나와 있는 상자: 두 테마 모두에서 보이는 민트 테두리(밤 테마의 --pick-on-line은 여느 테두리와 같은 색이다) */
.sheet:has(.tiles) { max-height: min(90%, 720px); } /* 상자가 여러 줄이라 조금 더 높이 연다 */
/* 설명 칸: 시트 아래에 붙어 있어서, 목록이 길어도 설명이 늘 보인다. 글이 바뀌어도 시트 높이가 들썩이지 않게 두세 줄 높이를 잡아 둔다 */
.pick-bar { position: sticky; bottom: -8px; z-index: 1; display: flex; align-items: center; gap: 12px; min-height: 76px; margin: 6px -4px -8px; padding: 10px 4px 2px; background: var(--panel); box-shadow: 0 -2px 0 0 var(--line); }
.pick-bar::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 12px; background: var(--panel); } /* 시트 바닥까지만 덮는다(더 길면 내용이 다 보여도 스크롤 막대가 생긴다) */
.pick-info { flex: 1 1 auto; min-width: 0; }
.pick-info b { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.0625rem; line-height: 1.25; margin-right: 8px; }
.pick-info p { margin: 3px 0 0; font-size: var(--step--1); line-height: 1.45; color: var(--muted); }
.pick-info em { font-style: normal; color: var(--lamp-text); }
.pick-bar .pick-hint { margin: 0; font-size: var(--step--1); line-height: 1.45; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.pick {
  font-family: var(--font-display); font-weight: var(--display-weight);
  font-size: 1rem;
  background: var(--panel-2);
  border: 0;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
}
.pick[aria-pressed="true"] { background: var(--pick-on-bg); color: var(--pick-on-fg); box-shadow: 0 -2px 0 0 var(--pick-on-line), 0 2px 0 0 var(--pick-on-line), -2px 0 0 0 var(--pick-on-line), 2px 0 0 0 var(--pick-on-line); }

.field { display: flex; gap: 8px; }
.field input, .field textarea {
  flex: 1; min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--ink);
  border: 0;
  padding: 10px 12px;
  border-radius: 0;
  box-shadow: 0 -2px 0 0 var(--line-hi), 0 2px 0 0 var(--line-hi), -2px 0 0 0 var(--line-hi), 2px 0 0 0 var(--line-hi);
}
.field textarea { resize: vertical; min-height: 3.2em; }
.btn {
  font-family: var(--font-display); font-weight: var(--display-weight);
  font-size: 1.0625rem;
  border: 0;
  cursor: pointer;
  padding: 10px 18px;
  background: var(--lamp);
  color: var(--lamp-ink);
  box-shadow: 0 -3px 0 0 #a8661f, 0 3px 0 0 #7a4a14, -3px 0 0 0 #a8661f, 3px 0 0 0 #a8661f;
  white-space: nowrap;
}
.btn.ghost { background: var(--panel-2); color: var(--text); box-shadow: 0 -3px 0 0 var(--line), 0 3px 0 0 var(--shade), -3px 0 0 0 var(--line), 3px 0 0 0 var(--line); }
.btn.portal { background: var(--portal); color: #0f2f28; box-shadow: 0 -3px 0 0 #3fa78d, 0 3px 0 0 #2b7766, -3px 0 0 0 #3fa78d, 3px 0 0 0 #3fa78d; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; }
/* 기록 옮기기(설정): 코드 칸은 고정폭 글씨로, 긴 코드가 칸 안에서 꺾이게. 글씨 크기는 줄이지 않는다(휴대폰에서 칸을 누를 때 화면이 확대되지 않게) */
.field .move-code { font-family: ui-monospace, 'Cascadia Mono', Consolas, 'Courier New', monospace; line-height: 1.4; word-break: break-all; min-height: 4.6em; }
.btn-row.move-row { justify-content: flex-start; margin: 3px; }
/* 기록 옮기기는 처음 화면(.screen, z-index 30) 위에서도 열린다: 시트와 확인 창을 그 위로 올린다(친구의 아이 화면·공유 창·토스트보다는 아래) */
body.move-top .backdrop { z-index: 31; }
body.move-top .sheet { z-index: 32; }
body.move-top .modal-wrap { z-index: 33; }

/* 대화 응답 */
.reply { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: start; background: var(--panel-2); padding: 12px; }
.reply canvas { width: 72px; height: 72px; }
.reply .act-line { color: var(--muted); font-size: var(--step--1); margin: 0 0 4px; }
.reply .say-line { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.1875rem; line-height: 1.4; margin: 0; }
.crisis { background: var(--crisis-bg); padding: 12px; font-size: var(--step--1); line-height: 1.6; }
.crisis strong { color: var(--rose); font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1rem; }

/* ── 모달 ── */
.modal-wrap { z-index: 24; display: grid; place-items: center; padding: 16px max(16px, env(safe-area-inset-right, 0px)) 16px max(16px, env(safe-area-inset-left, 0px)); }
.modal {
  width: min(100%, 460px);
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 -4px 0 0 var(--line-hi), 0 4px 0 0 var(--line-hi), -4px 0 0 0 var(--line-hi), 4px 0 0 0 var(--line-hi);
  animation: pop2 0.2s steps(4) both;
}
@keyframes pop2 { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal .eyebrow { font-family: var(--font-pixel); font-size: 0.6875rem; letter-spacing: 0.12em; color: var(--accent-text); text-transform: uppercase; margin: 0; }
.modal h3 { font-size: var(--step-2); line-height: 1.2; }
.modal p { margin: 0; }
.modal .art { display: flex; justify-content: center; gap: 10px; align-items: flex-end; background: var(--well); padding: 8px; }
.modal .eyebrow.rarity { color: hsl(var(--h) 75% var(--rarity-l)); }
.modal .art canvas { width: 160px; height: 160px; }
.modal .art canvas.small { width: 96px; height: 96px; }
.modal .art canvas.pair { width: min(124px, 36vw); height: auto; aspect-ratio: 1; }
.modal .art .arrow { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.5rem; color: var(--muted); align-self: center; }
.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice { text-align: left; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.0625rem; line-height: 1.3; }
.tip { background: var(--tip-bg); color: var(--tip-fg); padding: 10px 12px; font-size: var(--step--1); line-height: 1.6; }
.tip b { font-family: var(--font-display); font-weight: var(--display-weight); color: var(--accent-text); display: block; font-size: 0.9375rem; }
.changes { display: flex; flex-wrap: wrap; gap: 6px; }
.changes span { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; padding: 2px 8px; background: var(--panel-2); }
.changes .up { color: var(--good); }
.changes .down { color: var(--bad-text); }
.list { margin: 0; padding-left: 1.1em; display: flex; flex-direction: column; gap: 4px; font-size: var(--step--1); }

/* ── 토스트 ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  background: #fffaf0;
  color: #2a2140;
  font-family: var(--font-display); font-weight: var(--display-weight);
  font-size: 1rem;
  line-height: 1.35;
  padding: 8px 14px;
  z-index: 40;
  box-shadow: 0 -3px 0 0 #2a2140, 0 3px 0 0 #2a2140, -3px 0 0 0 #2a2140, 3px 0 0 0 #2a2140;
  animation: rise2 0.18s steps(3) both;
  pointer-events: none; /* 알림일 뿐이다. 그 아래에 있는 버튼(바로 다시 연 시트의 버튼 등)을 가리더라도 누를 수는 있게 한다 */
}
@keyframes rise2 { from { transform: translate(-50%, 10px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ── 툴팁 ── 버튼에 마우스를 올리면 뜨는 한 줄 설명(ui.js의 Tip). 토스트와 같은 크림색 상자라 두 테마 모두에서 잘 보인다 */
.tip-pop {
  position: fixed; left: 0; top: 0; z-index: 60;
  max-width: min(280px, calc(100vw - 16px));
  padding: 6px 10px;
  background: #fffaf0; color: #2a2140;
  font-family: var(--font-body); font-size: var(--step--1); line-height: 1.45; word-break: keep-all;
  box-shadow: 0 -2px 0 0 #2a2140, 0 2px 0 0 #2a2140, -2px 0 0 0 #2a2140, 2px 0 0 0 #2a2140, 0 6px 12px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  animation: tipIn 0.12s steps(2) both;
}
@keyframes tipIn { from { opacity: 0; } to { opacity: 1; } }

/* ── 그리드(앨범·보물함) ── */
.grid-cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.cell {
  background: var(--panel-2); border: 0; padding: 8px; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
  min-width: 0;
}
.cell canvas, .cell img { width: 100%; max-width: 96px; height: auto; aspect-ratio: 3 / 2; image-rendering: pixelated; }
.cell img.icon { aspect-ratio: 1; max-width: 48px; }
.cell span { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; line-height: 1.2; overflow-wrap: anywhere; }
.cell small { color: var(--muted); font-size: 0.6875rem; }
.cell.locked { opacity: 0.35; cursor: default; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; font-size: var(--step--1); }

.info-head { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: center; }
.info-head canvas { width: 120px; height: 120px; background: var(--well); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: var(--step--1); margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.meter { height: 10px; background: var(--bar-empty); position: relative; }
.meter i { position: absolute; inset: 0 auto 0 0; background: var(--st-hatch); }
.timeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.timeline span { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.75rem; text-align: center; padding: 4px 0; background: var(--panel-2); color: var(--muted); }
.timeline span.done { background: var(--mint-soft); color: var(--accent-text); }
.timeline span.now { background: var(--chip-bg); color: var(--chip-fg); box-shadow: inset 0 0 0 2px var(--pick-on-line); }
.log-item { display: grid; grid-template-columns: 3.4em 1fr; gap: 10px; font-size: var(--step--1); padding: 6px 0; border-bottom: 1px dashed var(--line); }
.log-item time { font-family: var(--font-pixel); font-size: 0.6875rem; color: var(--muted); padding-top: 2px; }
.log-item.milestone p { color: var(--accent-text); }
.log-item.gift p { color: var(--lamp-text); }
.log-item.warn p { color: var(--bad-text); }
.log-item p { margin: 0; }
.letter { background: #f6ecd6; color: #3a2a1a; padding: 16px; font-size: var(--step-0); line-height: 1.8; box-shadow: 0 -3px 0 0 #b49b74, 0 3px 0 0 #b49b74, -3px 0 0 0 #b49b74, 3px 0 0 0 #b49b74; }

/* ── 로딩 화면: 처음 들어올 때 방이 다 놓일 때까지 ── */
.loading { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--ink); color: var(--text); font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.25rem; line-height: 1.3; text-align: center; transition: opacity 0.25s; }
.loading p { margin: 0; }
.loading.done { opacity: 0; pointer-events: none; }
.loading-egg { animation: loadingEgg 1.1s steps(6) infinite; transform-origin: 50% 90%; }
.loading-dots i { font-style: normal; animation: loadingDot1 1.2s steps(1) infinite; } /* 점이 하나씩 늘어난다 */
.loading-dots i:nth-child(2) { animation-name: loadingDot2; }
.loading-dots i:nth-child(3) { animation-name: loadingDot3; }
@keyframes loadingEgg { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
@keyframes loadingDot1 { 0% { opacity: 0; } 25%, 100% { opacity: 1; } }
@keyframes loadingDot2 { 0% { opacity: 0; } 50%, 100% { opacity: 1; } }
@keyframes loadingDot3 { 0% { opacity: 0; } 75%, 100% { opacity: 1; } }

/* ── 전체 화면(인트로·작별·앨범·카드) ── */
.screen {
  position: fixed; inset: 0; z-index: 30;
  background: var(--ink);
  overflow-y: auto;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; align-items: center;
}
.screen.clear { background: transparent; pointer-events: none; justify-content: flex-end; }
.screen.clear > * { pointer-events: auto; }
.screen-inner { width: min(100%, 560px); display: flex; flex-direction: column; gap: 18px; align-items: stretch; margin-block: auto; }
.title-art { align-self: center; width: min(100%, 360px); height: auto; aspect-ratio: 4 / 3; }
.logo { font-family: var(--font-display); font-weight: var(--display-weight); font-size: clamp(2.6rem, 11vw, 4.2rem); line-height: 1; text-align: center; color: var(--text); text-shadow: 4px 4px 0 var(--logo-shadow); }
.logo small { display: block; font-family: var(--font-pixel); font-size: 0.75rem; letter-spacing: 0.24em; color: var(--accent-text); text-shadow: none; margin-top: 10px; }
.story { display: flex; flex-direction: column; gap: 10px; font-size: var(--step-1); line-height: 1.7; text-align: center; color: var(--text); margin: 0; }
.story p { margin: 0; }
.story .note { font-family: var(--font-display); font-weight: var(--display-weight); background: #f6ecd6; color: #3a2a1a; padding: 14px; text-align: left; font-size: 1.0625rem; line-height: 1.6; }
.center { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.eggs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.egg-card {
  background: var(--panel); border: 0; padding: 12px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; min-width: 0;
  box-shadow: 0 -3px 0 0 var(--line), 0 3px 0 0 var(--line), -3px 0 0 0 var(--line), 3px 0 0 0 var(--line);
}
.egg-card canvas { width: 72px; height: 84px; }
.egg-card span { font-size: var(--step--1); color: var(--muted); line-height: 1.45; }
.egg-card[aria-pressed="true"] { background: var(--pick-on-bg); box-shadow: 0 -3px 0 0 var(--pick-on-line), 0 3px 0 0 var(--pick-on-line), -3px 0 0 0 var(--pick-on-line), 3px 0 0 0 var(--pick-on-line); }
.egg-card[aria-pressed="true"] span { color: var(--pick-on-fg); }
.egg-card:hover canvas { animation: wob 0.5s steps(2) infinite; }
@keyframes wob { 50% { transform: rotate(4deg); } }

.speech-panel {
  width: min(100%, 560px);
  background: var(--speech-bg);
  padding: 18px 18px 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 -4px 0 0 var(--line-hi), 0 4px 0 0 var(--line-hi), -4px 0 0 0 var(--line-hi), 4px 0 0 0 var(--line-hi);
  cursor: pointer;
}
.speech-panel .who { font-family: var(--font-display); font-weight: var(--display-weight); color: var(--accent-text); font-size: 1rem; }
.speech-panel .line { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.3125rem; line-height: 1.45; min-height: 2.9em; }
.speech-panel .hint { font-family: var(--font-pixel); font-size: 0.625rem; color: var(--muted); text-align: right; letter-spacing: 0.1em; }

.album-page { position: relative; display: flex; flex-direction: column; gap: 12px; }
.album-skip { align-self: flex-end; margin-bottom: -10px; border: 0; background: transparent; cursor: pointer; padding: 6px 2px; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.album-skip:hover, .album-skip:focus-visible { color: var(--text); }
.album-skip.gone { visibility: hidden; pointer-events: none; }
.album-page canvas { width: 100%; height: auto; aspect-ratio: 3 / 2; background: var(--well); }
.album-page .meta { display: flex; justify-content: space-between; gap: 8px; font-family: var(--font-pixel); font-size: 0.6875rem; line-height: 1.3; color: var(--muted); letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; }
/* 제목은 한 줄(좁으면 글자를 줄이고, 그래도 넘치면 말줄임) */
.album-page h3 { font-size: clamp(1.125rem, 5.6vw, 1.5rem); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 글은 늘 두 줄 높이. 넘치는 글은 다음 누름에 이어서 보여 준다(▼) */
.album-text { position: relative; margin: 0; font-size: var(--step-1); line-height: 1.7; height: 3.4em; overflow: hidden; padding-right: 1.2em; }
.album-text.probe { position: absolute; left: 0; right: 0; height: auto; visibility: hidden; pointer-events: none; }
.album-more { position: absolute; right: 0; bottom: 0.2em; font-size: 0.75rem; line-height: 1; color: var(--lamp-text); animation: albumMore 1s steps(2) infinite; }
.album-more[hidden] { display: none; }
@keyframes albumMore { 50% { transform: translateY(2px); } }
.dots { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.dots i { width: 8px; height: 8px; background: var(--line); }
.dots i.on { background: var(--lamp); }
.nav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card-img { width: 100%; height: auto; aspect-ratio: 2 / 3; image-rendering: auto; background: var(--well); }
/* 그동안의 일기(장 글은 길이가 제각각이라 높이를 고정하지 않는다) */
.diary-lead { margin: 0; font-size: var(--step-1); line-height: 1.7; }
.diary-lines { display: flex; flex-direction: column; gap: 8px; font-size: var(--step-0); line-height: 1.7; }
.diary-lines p { margin: 0; }
.diary-lines details { color: var(--muted); font-size: var(--step--1); }
.diary-lines summary { cursor: pointer; padding: 4px 0; }
.album-page canvas.ritual-stage { image-rendering: pixelated; }
/* 전당에서 연 아이의 카드 목록 */
.card-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.card-thumbs .cell canvas { aspect-ratio: 1; max-width: 56px; }

/* ── 태블릿 가로·넓은 화면 ── */
@media (min-width: 900px) and (orientation: landscape), (min-width: 1100px) {
  .main { flex-direction: row; align-items: stretch; gap: 24px; }
  .stage { flex: 1.5; justify-content: center; }
  .panel { flex: 1; max-width: 440px; justify-content: center; }
  .stats { grid-template-columns: 1fr; }
  .act { min-height: 84px; }

  /* 시트: 넓은 화면(웹)에서는 아래에서 올라오지 않고 화면 가운데에 큰 창으로 뜬다.
     읽고 고르는 시트(메뉴·설정·도감·앨범·보물함…)는 크게, 바로 실행하는 시트(먹이·돌봄·놀기·상점·마음…)는 조금 작게 */
  .sheet {
    left: 50%; top: 50%; bottom: auto;
    transform: translate(-50%, -50%);
    width: min(calc(100% - 48px), 960px);
    max-height: min(calc(100% - 48px), 880px);
    padding-bottom: 0;
    box-shadow: 0 -4px 0 0 var(--line-hi), 0 4px 0 0 var(--line-hi), -4px 0 0 0 var(--line-hi), 4px 0 0 0 var(--line-hi), 0 28px 60px rgba(0, 0, 0, 0.45);
    animation: sheetPop 0.2s steps(4) both;
  }
  .sheet:has(.tiles) { max-height: min(calc(100% - 48px), 880px); }
  .sheet:is([data-key="feed"], [data-key="care"], [data-key="play"], [data-key="shop"], [data-key="heart"], [data-key="party"], [data-key="shelf"], [data-key="move"]) { width: min(calc(100% - 48px), 720px); }
  /* 탭이 있는 시트는 높이를 잡아 둔다(탭마다 내용 길이가 달라도 창이 들썩이지 않게) */
  .sheet:is([data-key="dex"], [data-key="guide"]) { height: min(calc(100% - 48px), 880px); }
  .sheet-head { padding: 20px 28px 12px; }
  .sheet-head h2 { font-size: 1.75rem; }
  .sheet-body { padding: 6px 28px 28px; gap: 12px; }
  .sheet-note { max-width: 76ch; } /* 창이 넓어도 글줄이 너무 길어지지 않게 */
  /* 큰 창에서는 칸과 그림도 키운다 */
  .sheet .grid-cells { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 12px; }
  .sheet .cell { padding: 10px 6px; }
  .sheet .cell canvas, .sheet .cell img { max-width: 120px; }
  .sheet .cell img.icon { max-width: 64px; }
  .sheet .cell span { font-size: 1rem; }
  .sheet .cell small { font-size: 0.75rem; }
  .sheet .dex-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .sheet .dex-grid .cell .dex-art { width: 64px; height: 64px; max-width: 64px; }
  .sheet .dex-grid .cell canvas.dex-art.pix { width: 70px; height: 60px; max-width: 70px; }
  .sheet .tiles { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
  .sheet .tile { min-height: 96px; font-size: 1rem; padding-top: 12px; }
  .sheet .tile img { width: 40px; height: 40px; }
  /* 메뉴와 장소 목록은 두 줄로 놓아 스크롤 없이 한눈에 본다 */
  .sheet[data-key="menu"] .sheet-body, .sheet[data-key="places"] .opt-group { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start; }
  .sheet[data-key="places"] .sheet-body { gap: 14px; }
  .sheet .info-head { grid-template-columns: 180px 1fr; gap: 24px; }
  .sheet .info-head canvas { width: 180px; height: 180px; }
  .sheet .kv { font-size: var(--step-0); gap: 6px 16px; }
  .sheet .log-item { font-size: var(--step-0); padding: 8px 0; }
}
@keyframes sheetPop { from { transform: translate(-50%, -50%) scale(0.94); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@media (min-width: 640px) and (orientation: portrait) {
  .act { min-height: 84px; font-size: 1.0625rem; }
  .act img { width: 36px; height: 36px; }
  .stats { padding: 14px 18px; }
}
/* 좁은 휴대폰: 상태창은 두 줄 배치를 그대로 두고(한 줄로 늘이면 아래 버튼이 화면 밖으로 밀린다) 간격과 글자만 줄인다 */
@media (max-width: 360px) {
  .stats { gap: 6px 12px; padding: 10px 12px; }
  /* 이름 칸은 가장 긴 이름('포만감')에 딱 맞춘다: 기본 글씨 33px, 맑은 고딕·Galmuri 42px */
  .stat { grid-template-columns: var(--stat-label-w, 34px) 1fr minmax(1.9em, auto); gap: 4px; }
  :root[data-font="malgun"] .stat, :root[data-font="galmuri"] .stat { --stat-label-w: 43px; }
  .stat-label { font-size: 0.875rem; text-align: right; } /* 오른쪽 맞춤: 두 글자 이름도 막대 바로 옆에 붙는다 */
  .bar { gap: 1px; }
  .act { min-height: 62px; font-size: 0.9375rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
/* 카드 아래 버튼(공유하기 · 카드 저장 · 다음/닫기): 같은 크기로 한 줄 */
.card-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 12px; padding: 3px; }
.card-actions .btn { min-height: 48px; padding-inline: 4px; overflow: hidden; text-overflow: ellipsis; }
/* 공유하기 창: 카드 화면 위에 뜬다(휴대폰은 아래에 붙고, 넓은 화면은 가운데) */
.share-pop { position: fixed; inset: 0; z-index: 38; display: grid; align-items: end; justify-items: center; background: var(--backdrop); padding: 16px max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.share-box { width: min(100%, 420px); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 14px 16px 18px; background: var(--panel); box-shadow: 0 -3px 0 0 var(--line), 0 3px 0 0 var(--line), -3px 0 0 0 var(--line), 3px 0 0 0 var(--line); animation: sharePop 0.18s steps(3) both; }
@keyframes sharePop { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.share-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.share-head h3 { font-size: var(--step-2); margin: 0; }
.share-card { align-self: center; flex: none; height: min(34vh, 252px); width: auto; aspect-ratio: 2 / 3; background: var(--well); box-shadow: 0 0 0 2px var(--line); }
.share-what { margin: -4px 0 -6px; text-align: center; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; color: var(--accent-text); }
.share-text { margin: 0; padding: 10px 12px; background: var(--well); font-size: var(--step--1); line-height: 1.6; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 4px; }
.share-text span { white-space: pre-line; }
.share-text .share-link { color: var(--muted); font-size: 0.75rem; line-height: 1.4; word-break: break-all; user-select: all; }
/* 보낼 곳: 상자 버튼을 가로 한 줄로 */
.share-tiles { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; padding: 2px; }
.share-tile { justify-content: center; gap: 7px; min-height: 76px; padding: 10px 2px 8px; text-decoration: none; }
.share-tile svg { flex: none; width: 28px; height: 28px; }
@media (hover: hover) { .share-tile:hover { background: var(--pick-on-bg); color: var(--pick-on-fg); } }
.share-box .sheet-note:empty { display: none; }
@media (min-width: 700px) { .share-pop { align-items: center; } }
@media (prefers-reduced-motion: reduce) { .share-box { animation: none; } }
.link-input { width: 100%; padding: 8px; background: var(--well); color: var(--text); border: 2px solid var(--line); font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ── 오늘의 계획(탐험 / 놀이 / 휴식 / 모험) ── */
.plan-card { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px 10px; background: var(--panel); box-shadow: 0 0 0 2px var(--line); }
.plan-label { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.8125rem; color: var(--accent-text); white-space: nowrap; }
.plan-now { flex: 1; min-width: 0; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-btns { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.plan-btn {
  min-height: 36px; padding: 4px 6px; border: 0; cursor: pointer; white-space: nowrap; color: var(--text);
  font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem;
  background: var(--panel-2);
  box-shadow: 0 -2px 0 0 var(--line), 0 2px 0 0 var(--line), -2px 0 0 0 var(--line), 2px 0 0 0 var(--line);
}
.plan-btn:active { transform: translateY(1px); }
.plan-btn.tired { opacity: 0.62; }
.plan-btns.picked { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr); align-items: center; }
/* 탐험이 쉬는 중일 때는 글자가 길다("쉬는 중 62%"): 그 칸만 글자만큼 넓힌다 */
.plan-btns.tired { grid-template-columns: auto repeat(3, minmax(0, 1fr)); }
.plan-btns.tired.picked { grid-template-columns: auto minmax(0, 2fr) minmax(0, 1fr); }
/* 모험: 청년기 전에는 잠겨 있다(자물쇠 그림과 흐린 글자) */
.plan-btn.locked { color: var(--muted); }
.plan-btn.locked::before { content: ''; display: inline-block; width: 10px; height: 11px; margin-right: 4px; vertical-align: -1px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 11'%3E%3Cpath fill-rule='evenodd' d='M2 2h1V1h4v1h1v3h1v6H1V5h1zM4 3v2h2V3z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 11'%3E%3Cpath fill-rule='evenodd' d='M2 2h1V1h4v1h1v3h1v6H1V5h1zM4 3v2h2V3z'/%3E%3C/svg%3E") center / contain no-repeat; }
/* 모험(미니 게임)을 띄우는 틀: 화면 전체 */
.adventure-screen { position: fixed; inset: 0; z-index: 90; background: #17142B; }
.adventure-screen iframe { display: block; width: 100%; height: 100%; border: 0; }
body.adventuring #app { visibility: hidden; }
.plan-btn.glow { background: var(--portal); color: #0f2f28; box-shadow: 0 -2px 0 0 #3fa78d, 0 2px 0 0 #2b7766, -2px 0 0 0 #3fa78d, 2px 0 0 0 #3fa78d; animation: blink 1.6s steps(2) infinite; }
@media (max-width: 360px) {
  .plan-card { padding: 6px 8px; gap: 6px; }
  .plan-label { display: none; }
  .plan-btn { font-size: 0.875rem; min-height: 34px; }
}

/* ── 성향 막대: 가운데가 0, 양쪽에 단어 ── */
.axes { display: grid; gap: 6px; }
.axis-row { display: grid; grid-template-columns: 3.2em 1fr 3.2em; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; color: var(--muted); }
.axis-row .axis-neg { text-align: right; }
.axis-row .on { color: var(--text); }
.axis-bar { position: relative; height: 10px; background: var(--bar-empty); }
.axis-bar i { position: absolute; top: 0; bottom: 0; background: var(--lamp); }
.axis-bar b { position: absolute; left: calc(50% - 1px); top: -3px; bottom: -3px; width: 2px; background: var(--text); }

/* ── 발견물 줄(탐험 결과·일기 장) ── */
.finds-row { display: flex; flex-wrap: wrap; gap: 8px; }
.find { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; width: 76px; padding: 6px 4px; background: var(--panel-2); box-shadow: 0 0 0 2px hsl(var(--h, 210) 35% 45%); text-align: center; }
.find .dex-art { width: 40px; height: 40px; image-rendering: pixelated; }
.find small { font-size: 0.6875rem; line-height: 1.25; color: var(--text); overflow-wrap: anywhere; }
.find em { position: absolute; top: -6px; right: -4px; font-style: normal; font-family: var(--font-pixel); font-size: 0.5625rem; padding: 1px 4px; background: var(--lamp); color: var(--lamp-ink); }

/* ── 도감 ── */
.dex-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.dex-grid .cell .dex-art { width: 48px; height: 48px; max-width: 48px; aspect-ratio: 1; image-rendering: pixelated; }
.dex-grid .cell small.rarity { color: hsl(var(--h) 75% var(--rarity-l)); }
.dex-unknown { display: grid; place-items: center; width: 48px; height: 48px; background: var(--well); font-family: var(--font-pixel); font-size: 1.25rem; color: var(--muted); }
.modal .art img.dex-art { width: 96px; height: 96px; image-rendering: pixelated; }
.dex-by { display: flex; align-items: center; gap: 10px; font-size: var(--step--1); color: var(--muted); }
.dex-by canvas { width: 48px; height: 48px; flex: none; background: var(--well); }
.card-thumbs .cell { cursor: pointer; }
.card-thumbs .cell[aria-current] { cursor: default; background: var(--pick-on-bg); color: var(--pick-on-fg); box-shadow: 0 -3px 0 0 var(--pick-on-line), 0 3px 0 0 var(--pick-on-line), -3px 0 0 0 var(--pick-on-line), 3px 0 0 0 var(--pick-on-line); }
.card-thumbs .cell[aria-current] small { color: inherit; }

/* ── 친구의 아이 화면: 다른 화면 위에 덮는다 ── */
.friend-screen { z-index: 35; }
.friend-screen .eyebrow { font-family: var(--font-pixel); font-size: 0.75rem; letter-spacing: 0.16em; color: var(--accent-text); text-align: center; margin: 0; }
/* 키가 작은 폰: 오늘의 계획 줄이 들어간 만큼 간격을 줄인다 */
@media (max-height: 700px) and (max-width: 600px) {
  .panel { gap: 8px; }
  .plan-card { padding: 5px 8px; }
  .plan-btn { min-height: 32px; }
  .stats { padding: 8px 12px; gap: 5px 14px; }
}

/* == 화면 배치: 휴대폰·세로 태블릿 / 가로 태블릿(예전 두 열 그대로) / 데스크톱 ==
   새 칸들(성장 길, 칸 머리, 오늘의 일기, 추억 카드, 왼쪽 열)은 기본으로 숨기고, 아래 두 배치에서만 켠다.
   - 휴대폰·세로 태블릿: 위에서 아래로 머리줄+성장 길 / 방(알림 줄은 방 안 위쪽) / 오늘의 계획 / 상태 | 일기·카드 / 행동 한 줄
   - 데스크톱(가로 1180px·세로 620px 이상): 왼쪽 계획·이야기 / 가운데 방과 행동 / 오른쪽 상태·일기·카드
   어느 쪽도 화면 전체는 스크롤하지 않는다. 길어지는 칸만 제 안에서 스크롤하고, 세로가 모자라면 방이 줄어든다(main.js의 fit) */
.desk-only, .col-left, .box-head, .box-diary, .box-cards, .stat-ico, .growth-track, .icon-btn.dex { display: none; }
.side, .box-stats { display: contents; }
.scrollbox { overflow-y: auto; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* ── 두 배치가 함께 쓰는 부품(보이고 말고는 아래 배치가 정한다) ── */
.icon-btn.dex { grid-area: dex; }
.icon-btn.dex img { width: 22px; height: 22px; image-rendering: pixelated; }
/* 성장 길: 전체는 점선, 지금 단계까지는 실선 */
.growth-track { grid-area: track; grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr)); align-items: end; position: relative; width: 100%; justify-self: center; }
.growth-track::before, .growth-track::after { content: ""; position: absolute; bottom: var(--line-y, 40px); left: calc(50% / var(--n, 6)); }
.growth-track::before { right: calc(50% / var(--n, 6)); border-top: 3px dashed var(--line); }
.growth-track::after { width: calc(100% * var(--i, 0) / var(--n, 6)); border-top: 3px solid var(--portal); }
.node { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; color: var(--muted); min-width: 0; }
.node canvas { width: 40px; height: 40px; display: block; }
.node.future canvas { opacity: 0.3; }
:root[data-skin="ivory"] .node.future canvas { filter: brightness(0); opacity: 0.2; } /* 밝은 바탕에서는 어두운 실루엣 */
.node.now canvas { width: 50px; height: 50px; }
.node-q { display: grid; place-items: center; width: 34px; height: 34px; margin: 5px 0; background: var(--panel-2); color: var(--muted); font-family: var(--font-pixel); font-size: 1rem; box-shadow: 0 0 0 2px var(--line); }
.node .dot { width: 12px; height: 12px; margin: 2px 0 4px; background: var(--line); box-shadow: 0 0 0 3px var(--ink); }
.node.past .dot { background: var(--portal); }
.node.now .dot { background: var(--lamp); box-shadow: 0 0 0 3px var(--ink), 0 0 0 6px var(--lamp); }
.node b { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; line-height: 1.15; white-space: nowrap; }
.node.now b { color: var(--text); font-size: 1.0625rem; }
.node.past b { color: var(--text); }
.node small { font-family: var(--font-pixel); font-size: 0.625rem; line-height: 1.4; color: var(--muted); }
.node.now small { font-family: var(--font-display); font-size: 0.75rem; color: var(--lamp-text); }
/* 칸과 칸 머리 */
.box-head { align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.box-head h2 { font-size: 1.25rem; line-height: 1.2; white-space: nowrap; }
.box-head .more, .box-head .count { border: 0; background: none; padding: 2px 4px; color: var(--muted); font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; white-space: nowrap; }
.box-head .more { cursor: pointer; }
.box-head .more:hover { color: var(--text); }
.box-cards .box-head .count { margin-right: auto; }
.box-head .more.share { color: var(--accent-text); }
/* 글자는 작아도 누르는 자리는 넉넉하게(배치는 그대로) */
.box-head .more.share { position: relative; }
.box-head .more.share::after { content: ""; position: absolute; inset: -10px -6px; }
@media (max-width: 340px) { .box-cards .box-head .count { display: none; } } /* 아주 좁은 화면: 장수는 접는다 */
/* 오늘의 일기 */
.today-diary { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px; align-items: start; }
.today-diary canvas { width: 100%; height: auto; aspect-ratio: 3 / 2; background: var(--well); box-shadow: 0 0 0 2px var(--line); }
.today-diary > .sheet-note { grid-column: 1 / -1; }
.today-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.today-text b { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1rem; line-height: 1.3; color: var(--lamp-text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.today-text p { margin: 0; font-size: var(--step--1); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.today-text small { align-self: flex-end; font-family: var(--font-pixel); font-size: 0.625rem; color: var(--muted); }
/* 추억 카드 일곱 자리 */
.card-strip { display: grid; grid-template-columns: 28px minmax(0, 1fr) 28px; align-items: center; gap: 6px; }
.rail-btn { height: 56px; border: 0; background: none; color: var(--text); font-family: var(--font-display); font-size: 1.75rem; line-height: 1; cursor: pointer; padding: 0; }
.rail-btn:hover { color: var(--lamp-text); }
.card-rail { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; padding: 3px; position: relative; }
.card-rail::-webkit-scrollbar { display: none; }
.rail-card { flex: 0 0 84px; scroll-snap-align: start; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px 8px; border: 0; cursor: pointer; background: var(--panel-2); color: var(--text); box-shadow: 0 0 0 2px var(--line); }
.rail-card:hover:not(.locked) { box-shadow: 0 0 0 2px var(--lamp); }
.rail-card canvas { width: 64px; height: 64px; background: var(--well); }
.rail-card .node-q { width: 64px; height: 64px; margin: 0; }
.rail-card b { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; line-height: 1.2; white-space: nowrap; }
.rail-card small { font-family: var(--font-pixel); font-size: 0.625rem; color: var(--muted); }
.rail-card.locked { cursor: default; opacity: 0.5; }
.stat-val.num::after { content: "%"; }
.stat-ico { width: 22px; height: 22px; image-rendering: pixelated; }

/* ══ 휴대폰·세로 태블릿 ══ (가로 태블릿의 두 열 배치와 데스크톱을 뺀 나머지) */
@media (max-width: 899.98px), (max-width: 1099.98px) and (orientation: portrait) {
  /* 머리줄: 이름·단계 | 날짜·시각 / 별가루·도감·테마·메뉴, 그 아래 성장 길 */
  .hud, .hud.tall {
    grid-template-columns: minmax(0, 1fr) auto auto auto auto;
    grid-template-areas: "id meta meta meta meta" "id dust dex skin menu" "track track track track track";
    grid-template-rows: 16px 36px auto;
    row-gap: 4px; column-gap: 6px;
    padding-block: 8px 6px;
  }
  .hud .hud-id, .hud.tall .hud-id { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px; height: auto; align-self: center; }
  .hud .hud-name, .hud.tall .hud-name { grid-area: auto; font-size: 1.375rem; line-height: 1.15; max-width: 100%; }
  .hud.tall .chip { grid-area: auto; justify-self: auto; align-self: flex-start; }
  .hud-meta { justify-self: end; align-self: center; height: 16px; line-height: 16px; font-size: 0.75rem; }
  #ageText, #dateSep { display: none; } /* 나이는 성장 길과 개체 정보에서 본다 */
  .hud-dust { height: 36px; min-width: 52px; padding: 0 8px; font-size: 0.8125rem; gap: 4px; }
  .hud-dust img { width: 16px; height: 16px; }
  .icon-btn { width: 36px; height: 36px; }
  .icon-btn.dex { display: grid; }
  .growth-track:not([hidden]) { display: grid; margin-top: 4px; --line-y: 30px; }
  .node canvas { width: 28px; height: 28px; }
  .node.now canvas { width: 36px; height: 36px; }
  .node-q { width: 22px; height: 22px; margin: 3px 0; font-size: 0.6875rem; }
  .node .dot { width: 8px; height: 8px; margin: 1px 0 3px; box-shadow: 0 0 0 2px var(--ink); }
  .node.now .dot { box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--lamp); }
  .node b { font-size: 0.75rem; }
  .node.now b { font-size: 0.8125rem; }
  .node small { font-size: 0.5rem; line-height: 1.5; }
  .node.now small { font-size: 0.625rem; }

  /* 본문: 방은 위에 그대로, 정보 칸만 제 안에서 스크롤, 행동 줄은 아래에 붙는다 */
  .main { overflow: hidden; gap: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
  .stage { flex: none; position: relative; gap: 0; }
  /* 알림 줄은 방 안 위쪽에 겹쳐 놓는다 */
  .ticker-row { position: absolute; z-index: 3; top: 8px; left: 50%; transform: translateX(-50%); width: calc(var(--scene-w, 100%) - 16px); max-width: calc(100% - 16px); margin: 0; min-height: 0; padding: 3px 4px 3px 6px; justify-content: space-between; background: rgba(24, 19, 42, 0.86); }
  .ticker-row { cursor: pointer; animation: tickerIn 0.18s steps(3) both; }
  .ticker-row.empty, .ticker-row.seen { display: none; } /* seen: 읽을 만큼 떠 있다가 물러난 뒤(ui.js의 hideTicker) */
  .ticker-row.leaving { animation: tickerLeave 0.4s forwards; }
  .ticker { color: #f4ecdc; text-align: left; flex: 1 1 auto; }
  .room-hud { top: 38px; }
  .panel { flex: 1 1 0; min-height: 0; gap: 8px; }
  .plan-card { flex: none; padding: 5px 8px; }
  .plan-btn { min-height: 34px; }
  .side { flex: 1 1 0; min-height: 0; overflow-y: auto; scrollbar-width: none; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "stats diary" "stats cards"; grid-template-rows: auto 1fr; align-content: start; gap: 8px; padding: 2px; }
  .side::-webkit-scrollbar { display: none; }
  .box-stats, .box-diary, .box-cards { display: block; min-width: 0; background: var(--panel); box-shadow: 0 0 0 2px var(--line); padding: 8px 10px 10px; }
  .box-stats { grid-area: stats; }
  .box-diary { grid-area: diary; }
  .box-cards { grid-area: cards; }
  .box-head { display: flex; margin-bottom: 6px; gap: 4px; }
  .box-head h2 { font-size: 1rem; }
  .box-head .more, .box-head .count { font-size: 0.75rem; padding: 2px 0; }
  /* 상태: 그림 + 이름 + 막대 + % 한 줄씩 */
  .box-stats .stats { grid-template-columns: 1fr; gap: 7px; background: none; box-shadow: none; padding: 0; }
  .box-stats .stat { grid-template-columns: 18px 2.9em minmax(0, 1fr) minmax(2.3em, auto); gap: 5px; }
  .box-stats .stat-ico { display: block; width: 18px; height: 18px; }
  .box-stats .stat-label { font-size: 0.8125rem; color: var(--text); text-align: left; }
  .box-stats .stat-val { font-size: 0.625rem; }
  .box-stats .bar { height: 10px; gap: 1px; }
  .today-diary { grid-template-columns: 56px minmax(0, 1fr); gap: 8px; }
  .today-text { gap: 2px; }
  .today-text b { font-size: 0.8125rem; -webkit-line-clamp: 1; }
  .today-text p { font-size: 0.75rem; line-height: 1.45; }
  .today-text p + p { display: none; }
  .card-strip { grid-template-columns: 14px minmax(0, 1fr) 14px; gap: 3px; }
  .rail-btn { font-size: 1.25rem; height: 44px; }
  .card-rail { gap: 6px; }
  .rail-card { flex-basis: 54px; padding: 4px 2px 5px; }
  .rail-card canvas, .rail-card .node-q { width: 40px; height: 40px; }
  .rail-card b { font-size: 0.75rem; }
  .rail-card small { display: none; }
  /* 알림은 행동 줄 바로 위에 뜬다(버튼을 가리지 않게) */
  .toast { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
  /* 행동: 한 줄 */
  .actions { flex: none; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 5px; padding: 3px; }
  .act { min-height: 58px; font-size: 0.75rem; padding: 6px 1px; gap: 3px; white-space: nowrap; }
  .act img { width: 26px; height: 26px; }
  .act .dot { top: -6px; right: -2px; width: 16px; height: 16px; font-size: 0.75rem; }
}
/* 폭이 넉넉한 휴대폰 가로·세로 태블릿: 글자와 버튼을 키운다 */
@media (min-width: 560px) and (max-width: 899.98px), (min-width: 560px) and (max-width: 1099.98px) and (orientation: portrait) {
  .hud, .hud.tall { grid-template-rows: 18px 44px auto; column-gap: 10px; padding-block: 10px 8px; }
  .hud .hud-name, .hud.tall .hud-name { font-size: 1.75rem; }
  .hud-meta { font-size: 0.8125rem; }
  .hud-dust { height: 44px; min-width: 64px; font-size: 0.9375rem; }
  .icon-btn { width: 44px; height: 44px; }
  .growth-track:not([hidden]) { --line-y: 36px; }
  .node canvas { width: 36px; height: 36px; }
  .node.now canvas { width: 46px; height: 46px; }
  .node .dot { width: 10px; height: 10px; }
  .node b { font-size: 0.875rem; }
  .node.now b { font-size: 1rem; }
  .node small { font-size: 0.5625rem; }
  .main, .panel, .side { gap: 12px; }
  .box-stats, .box-diary, .box-cards { padding: 12px 14px 14px; }
  .box-head { margin-bottom: 10px; }
  .box-head h2 { font-size: 1.25rem; }
  .box-head .more, .box-head .count { font-size: 0.875rem; }
  .box-stats .stats { gap: 10px; }
  .box-stats .stat { grid-template-columns: 22px 3.4em minmax(0, 1fr) minmax(2.6em, auto); gap: 8px; }
  .box-stats .stat-ico { width: 22px; height: 22px; }
  .box-stats .stat-label { font-size: 0.9375rem; }
  .box-stats .stat-val { font-size: 0.75rem; }
  .box-stats .bar { height: 12px; gap: 2px; }
  .today-diary { grid-template-columns: 104px minmax(0, 1fr); gap: 12px; }
  .today-text { gap: 4px; }
  .today-text b { font-size: 1rem; -webkit-line-clamp: 2; }
  .today-text p { font-size: var(--step--1); }
  .card-strip { grid-template-columns: 24px minmax(0, 1fr) 24px; gap: 6px; }
  .rail-btn { font-size: 1.75rem; height: 56px; }
  .rail-card { flex-basis: 76px; padding: 6px 4px 8px; }
  .rail-card canvas, .rail-card .node-q { width: 56px; height: 56px; }
  .rail-card b { font-size: 0.875rem; }
  .rail-card small { display: block; font-size: 0.5625rem; }
  .toast { bottom: calc(106px + env(safe-area-inset-bottom, 0px)); }
  .plan-card { padding: 8px 10px; }
  .plan-btn { min-height: 40px; font-size: 1rem; }
  .actions { gap: 10px; }
  .act { min-height: 78px; font-size: 1rem; gap: 5px; padding: 8px 4px; }
  .act img { width: 34px; height: 34px; }
  .ticker-row { padding: 5px 6px 5px 10px; }
  .room-hud { top: 46px; }
}
/* 키가 작은 휴대폰: 성장 길을 접어 방과 정보 칸에 자리를 준다 */
@media (max-height: 699.98px) and (max-width: 899.98px) {
  .growth-track:not([hidden]) { display: none; }
}
/* 아주 좁은 휴대폰 */
@media (max-width: 374.98px) {
  .act { font-size: 0.6875rem; }
  .act img { width: 24px; height: 24px; }
  .actions { gap: 4px; }
  .box-stats .stat { grid-template-columns: 16px 2.9em minmax(0, 1fr) minmax(2.2em, auto); gap: 4px; }
  .box-stats .stat-ico { width: 16px; height: 16px; }
  .plan-label { display: none; }
}

/* ══ 데스크톱 ══ */
@media (min-width: 1180px) and (min-height: 620px) {
  .desk-only { display: revert; }
  .app { max-width: 1720px; padding-inline: max(28px, env(safe-area-inset-left, 0px)); }

  /* 머리줄: 이름 | 성장 길 | 날짜·별가루·버튼 */
  .hud, .hud.tall {
    grid-template-columns: minmax(170px, auto) minmax(0, 1fr) auto auto auto auto;
    grid-template-areas: "id track meta meta meta meta" "id track dust dex skin menu";
    grid-template-rows: minmax(20px, auto) minmax(44px, auto);
    row-gap: 8px; column-gap: 12px;
    padding-block: 12px 12px;
    box-shadow: 0 3px 0 0 var(--line);
  }
  .hud .hud-id, .hud.tall .hud-id { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 8px; height: auto; align-self: center; }
  .hud .hud-name, .hud.tall .hud-name { grid-area: auto; font-size: 2rem; line-height: 1.1; overflow: visible; }
  .hud.tall .chip { grid-area: auto; align-self: flex-start; }
  .hud-meta { justify-self: end; font-size: 0.8125rem; overflow: visible; }
  .icon-btn.dex { display: grid; }
  .growth-track:not([hidden]) { display: grid; max-width: 880px; }

  /* 본문: 세 열. 가운데 열은 방의 크기(--scene-w, main.js가 정한다)에 맞춘다 */
  .main {
    display: grid;
    grid-template-columns: var(--side-w, 300px) minmax(0, 1fr) var(--side-w, 300px);
    grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr);
    grid-template-areas: "left . right" "left stage right" "left acts right" "left . right";
    gap: 0 22px;
    overflow: hidden;
    padding: 16px 0 18px;
  }
  .panel { display: contents; }
  .panel > .plan-card { display: none; }
  .stage { grid-area: stage; flex: none; align-items: center; gap: 6px; }
  .ticker-row { width: var(--scene-w, 640px); max-width: 100%; margin-top: 8px; }
  .actions { grid-area: acts; justify-self: center; width: calc(var(--scene-w, 640px) + 8px); max-width: 100%; margin-top: 10px; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
  .act { min-height: 78px; }
  /* 돌봄 네 개와 나머지 네 개 사이의 구분선 */
  .actions .act:nth-child(5) { margin-left: 12px; }
  .actions .act:nth-child(5)::before { content: ""; position: absolute; left: -13px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }

  .col-left, .side { display: flex; flex-direction: column; gap: 14px; min-width: 0; min-height: 0; padding: 2px; }
  .col-left { grid-area: left; padding-bottom: 60px; } /* 아래는 알림(토스트)이 뜨는 자리 */
  .side { grid-area: right; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
  .box, .box-stats { display: block; background: var(--panel); box-shadow: 0 0 0 2px var(--line); padding: 12px 14px 14px; min-width: 0; }
  .box-head { display: flex; }

  /* 왼쪽: 오늘의 계획 */
  .box-plan { flex: none; }
  .box-plan .plan-card { flex-wrap: wrap; padding: 0; background: none; box-shadow: none; gap: 8px; }
  .box-plan .plan-card[hidden] { display: none; }
  .box-plan .plan-label { flex: 1 1 100%; font-size: 1.25rem; color: var(--text); }
  .box-plan .plan-now { flex: 1 1 100%; white-space: normal; padding: 8px 10px; background: var(--panel-2); box-shadow: 0 0 0 2px var(--lamp); color: var(--lamp-text); }
  .box-plan .plan-btn { min-height: 40px; font-size: 1rem; }
  .news-line { margin: 10px 0 0; font-size: var(--step--1); line-height: 1.5; color: var(--muted); }
  .box-plan .plan-card[hidden] + .news-line { margin-top: 0; }

  /* 왼쪽: 오늘의 이야기(시각 순). 가장 최근 일이 "지금" */
  .box-story { flex: 1 1 0; display: flex; flex-direction: column; min-height: 160px; }
  .story-list { flex: 1 1 0; margin: 0; padding: 2px 6px 2px 2px; list-style: none; display: flex; flex-direction: column; gap: 4px; position: relative; }
  .story-empty { color: var(--muted); font-size: var(--step--1); padding: 12px 4px; }
  .story-item { display: grid; grid-template-columns: 46px 26px minmax(0, 1fr); align-items: center; gap: 8px; padding: 6px 8px 6px 18px; position: relative; color: var(--muted); }
  /* 왼쪽의 세로 길과 점 */
  .story-item::before { content: ""; position: absolute; left: 3px; top: 0; bottom: -4px; width: 2px; background: var(--line); }
  .story-item:last-child::before { bottom: 50%; }
  .story-item::after { content: ""; position: absolute; left: 0; top: calc(50% - 4px); width: 8px; height: 8px; background: var(--line-hi); }
  .story-item time { font-family: var(--font-pixel); font-size: 0.6875rem; font-variant-numeric: tabular-nums; }
  .story-item img { width: 26px; height: 26px; image-rendering: pixelated; }
  .story-item p { margin: 0; font-size: var(--step--1); line-height: 1.4; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .story-item.mark p { color: var(--lamp-text); }
  .story-item.mark::after { background: var(--lamp); }
  .story-item.now { background: var(--panel-2); box-shadow: 0 0 0 2px var(--line-hi); }
  .story-item.now::after { background: var(--lamp); left: -1px; top: calc(50% - 5px); width: 10px; height: 10px; }
  .story-item.now time { color: var(--lamp-text); }
  .story-word { flex: none; display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px 12px; background: var(--rose); color: #2a1030; }
  .story-word[hidden] { display: none; }
  .story-word canvas { width: 56px; height: 56px; flex: none; margin: -6px 0 -2px; }
  .story-word p { margin: 0; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1rem; line-height: 1.35; min-width: 0; overflow-wrap: anywhere; }
  .story-word small { display: block; font-size: 0.8125rem; opacity: 0.75; }

  /* 오른쪽: 상태·오늘의 일기·추억 카드 */
  .box-stats, .box-diary, .box-cards { flex: none; }
  .box-diary, .box-cards { display: block; }
  .box-stats .stats { grid-template-columns: 1fr; gap: 9px; background: none; box-shadow: none; padding: 0; }
  .box-stats .stat { grid-template-columns: 22px 3.4em 1fr minmax(2.6em, auto); gap: 8px; }
  .box-stats .stat-ico { display: block; }
  .box-stats .stat-label { color: var(--text); }
  .box-stats .bar { height: 12px; }

  /* 알림은 왼쪽 아래에 */
  /* 왼쪽 열 아래에 맞춘다. 화면이 앱 폭(1720px)보다 넓으면 앱 틀의 왼쪽 끝을 따라간다(화면 구석에 떨어져 있으면 눈에 띄지 않는다) */
  .toast { left: max(30px, calc(50vw - 860px + 28px)); bottom: 22px; transform: none; animation: rise3 0.18s steps(3) both; }
  @keyframes rise3 { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
}

/* 넓지만 키가 작은 창: 오른쪽 열이 한 화면에 들어오게 간격을 줄인다 */
@media (min-width: 1180px) and (min-height: 620px) and (max-height: 820px) {
  .main { padding: 12px 0 14px; }
  .col-left, .side { gap: 10px; }
  .box, .box-stats { padding: 10px 12px 12px; }
  .box-head { margin-bottom: 6px; }
  .box-head h2 { font-size: 1.125rem; }
  .box-stats .stats { gap: 6px; }
  .today-diary { grid-template-columns: 96px minmax(0, 1fr); }
  .today-text p + p { display: none; }
  .rail-card { flex-basis: 72px; padding: 4px 4px 6px; }
  .rail-card canvas, .rail-card .node-q { width: 48px; height: 48px; }
  .act { min-height: 70px; }
  .box-plan .plan-btn { min-height: 36px; }
}

/* 탐험 중: 탐험지 ↔ 방 보기 전환 */
.trip-toggle { position: absolute; z-index: 2; right: 6px; top: 6px; border: 0; cursor: pointer; padding: 4px 9px; line-height: 1.3; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.8125rem; background: rgba(24, 19, 42, 0.86); color: #f4ecdc; box-shadow: 0 0 0 2px rgba(244, 236, 220, 0.35); }
.trip-toggle:hover { color: #ffb45e; }
@media (max-width: 899.98px), (max-width: 1099.98px) and (orientation: portrait) { .trip-toggle { top: 38px; } }
@media (min-width: 560px) and (max-width: 899.98px), (min-width: 560px) and (max-width: 1099.98px) and (orientation: portrait) { .trip-toggle { top: 46px; } }
/* 휴대폰에서는 알림 줄이 방 위쪽을 덮으므로, 파티 줄('돌아가기')도 그 아래로 내린다.
   알림 줄이 없을 때(비었거나 읽고 물러난 뒤)는 방 위쪽의 것들(시계·상태 칩, 방 보기, 파티 줄)이 모두 제자리로 올라간다 */
@keyframes tickerIn { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes tickerLeave { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -6px); } }
@media (max-width: 899.98px), (max-width: 1099.98px) and (orientation: portrait) {
  .party-bar { top: 38px; z-index: 3; }
  .room-hud, .trip-toggle, .party-bar { transition: top 0.2s; }
  .stage:has(.ticker-row:is(.empty, .seen)) :is(.room-hud, .trip-toggle, .party-bar) { top: 6px; }
}
@media (min-width: 560px) and (max-width: 899.98px), (min-width: 560px) and (max-width: 1099.98px) and (orientation: portrait) {
  .party-bar { top: 46px; }
}
@media (prefers-reduced-motion: reduce) { .act .dot, .tile .dot { animation: none; } .ticker-row, .ticker-row.leaving { animation: none; } .room-hud, .trip-toggle, .party-bar { transition: none; } }

/* 같이 찾기(탐험 미니게임): 진행 표시(방 왼쪽 아래)와 갈림길(방 아래쪽 가운데) */
.trip-hud { position: absolute; z-index: 2; left: 6px; bottom: 6px; display: flex; align-items: center; gap: 6px; padding: 3px 8px; line-height: 1.3; background: rgba(24, 19, 42, 0.86); color: #f4ecdc; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.8125rem; pointer-events: none; }
.trip-hud b { font-weight: var(--display-weight); color: #7be3c8; }
.trip-hud span { color: #ffd166; letter-spacing: 1px; }
.trip-hud small { color: #b3a8d1; font-size: 0.75rem; }
.trip-fork { position: absolute; z-index: 3; left: 50%; top: 36%; transform: translate(-50%, -50%); width: min(92%, 420px); display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px; line-height: 1.3; background: rgba(24, 19, 42, 0.92); box-shadow: 0 0 0 2px #ffb45e; }
.trip-fork p { grid-column: 1 / -1; margin: 0; color: #f4ecdc; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.9375rem; text-align: center; }
.trip-fork .plan-btn { white-space: normal; min-height: 44px; font-size: 0.875rem; line-height: 1.25; padding: 4px 6px; }
@media (max-width: 374.98px) { .trip-hud small { display: none; } }

/* ── 탐험 미니게임 ── */
/* 타이밍 맞추기: 오가는 표시와 밝은 칸 */
.tg-bar { position: relative; height: 34px; background: var(--well); box-shadow: 0 0 0 2px var(--line); cursor: pointer; touch-action: manipulation; }
.tg-zone { position: absolute; top: 0; bottom: 0; background: var(--portal); opacity: 0.85; }
.tg-mark { position: absolute; top: -5px; bottom: -5px; width: 6px; margin-left: -3px; background: var(--lamp); box-shadow: 0 0 0 2px var(--ink); }
.tg-pips { display: flex; justify-content: center; gap: 8px; }
.tg-pips i { width: 14px; height: 14px; background: var(--bar-empty); box-shadow: 0 0 0 2px var(--line); }
.tg-pips i.hit { background: var(--good); }
.tg-pips i.miss { background: var(--bad); }
.tg-msg { margin: 0; min-height: 1.5em; text-align: center; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.0625rem; }
.tg-row { justify-content: center; }
.btn.tg-go { min-width: 60%; min-height: 56px; font-size: 1.375rem; touch-action: manipulation; }
/* 순서 기억하기: 네 칸 */
.sq-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(100%, 260px); margin: 0 auto; }
.sq-pad { aspect-ratio: 1.5; border: 0; cursor: pointer; display: grid; place-items: center; background: var(--panel-2); opacity: 0.7; box-shadow: 0 0 0 2px var(--line); touch-action: manipulation; }
.sq-pad img { width: 40px; height: 40px; image-rendering: pixelated; }
.sq-pad.p0 { --pc: #ffd166; } .sq-pad.p1 { --pc: #ff8aa8; } .sq-pad.p2 { --pc: #7cc8ff; } .sq-pad.p3 { --pc: #8fe08a; }
.sq-pad.lit { opacity: 1; background: var(--pc); box-shadow: 0 0 0 3px #fffaf0, 0 0 14px 2px var(--pc); }
.sq-grid.showing .sq-pad { cursor: default; }
/* 겨루기 */
.modal .art canvas.duel-opp, .modal .art img.duel-opp { width: 112px; height: 96px; image-rendering: pixelated; }
.modal .art canvas.dex-art.pix { width: 140px; height: 120px; }
.modal .art canvas.dex-art.pix.duel-opp { width: 98px; height: 84px; align-self: flex-end; }
.modal .art canvas.duel-me { transform: scaleX(-1); } /* 상대를 마주 보게 */
.dex-grid .cell canvas.dex-art.pix, .find canvas.dex-art.pix { aspect-ratio: 7 / 6; }
.duel-gauges { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 6px 10px; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 0.875rem; color: var(--muted); }
.duel-mom { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; height: 14px; }
.duel-mom i { background: var(--bar-empty); }
.duel-mom i.mid { background: var(--line-hi); }
.duel-mom i.me { background: var(--lamp); }
.duel-mom i.opp { background: var(--bad); }
.duel-fr { color: var(--rose); letter-spacing: 3px; font-size: 1rem; line-height: 1; }
.duel-fr em { font-style: normal; color: var(--bar-empty); }
.duel-log { margin: 0; color: var(--muted); font-size: var(--step--1); }
.duel-hint { margin: 0; padding: 8px 10px; background: var(--tip-bg); color: var(--tip-fg); font-size: var(--step-0); line-height: 1.5; }
.duel-moves { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.duel-moves .plan-btn { min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; white-space: normal; line-height: 1.2; touch-action: manipulation; }
.duel-moves .plan-btn small { font-size: 0.6875rem; color: var(--muted); }

/* 카드 화면의 오른쪽 위 닫기(✕): 스크롤해도 제자리에 있다 */
.screen-close { position: fixed; z-index: 2; top: max(12px, env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); width: 44px; height: 44px; color: var(--text); font-size: 1.25rem; line-height: 1; }
.screen-close ~ .screen-inner .card-title { padding-inline: 48px; } /* 제목이 ✕ 밑으로 들어가지 않게 */

/* 다이어리 목록(시트) */
.diary-item { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; background: var(--panel-2); box-shadow: 0 0 0 2px var(--line); }
.diary-item small { font-family: var(--font-pixel); font-size: 0.6875rem; color: var(--muted); }
.diary-item b { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.0625rem; color: var(--lamp-text); }
.diary-item p { margin: 0; font-size: var(--step--1); line-height: 1.55; }
