:root {
  --ink: #f4efe4;
  --dim: rgba(244, 239, 228, 0.62);
  --glass: rgba(14, 22, 24, 0.55);
  --line: rgba(255, 255, 255, 0.12);
  --warm: #ffcf86;
  --good: #9fe3b0;
  --warn: #ffb08a;
  --hp: #ef7b6b;
  --bat: #f2cf62;
  --fuel: #8fd0c0;
  --cache: #8fe9dc;
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  /* 노치·둥근 모서리를 피한 화면 가장자리 여백. 가로로 돌리면 노치가 왼쪽·오른쪽으로 온다. */
  --edge-t: max(14px, env(safe-area-inset-top));
  --edge-b: max(16px, env(safe-area-inset-bottom));
  --edge-l: max(16px, env(safe-area-inset-left));
  --edge-r: max(16px, env(safe-area-inset-right));
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1416; color: var(--ink); font-family: var(--font); }
body { word-break: keep-all; overflow-wrap: anywhere; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity 1.2s ease; }
body.ready canvas#game { opacity: 1; }
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.dim { color: var(--dim); }
button { font-family: inherit; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top { position: absolute; top: var(--edge-t); left: var(--edge-l); right: var(--edge-r); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 9px; padding: 8px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: 14px; white-space: nowrap; }
.pill .ico { color: var(--warm); }
.zones .bulb { width: 9px; height: 9px; border-radius: 50%; background: var(--warm); box-shadow: 0 0 10px 2px rgba(255, 207, 134, 0.7); }
/* 배전반 버튼: 변전소 출력 사용량. 차단된 구역이 있으면 붉게 깜박인다. */
button.pill { font-family: inherit; color: var(--ink); cursor: pointer; pointer-events: auto; }
button.pill:hover { border-color: rgba(255, 207, 134, 0.45); }
button.pill:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.power .bolt { width: 14px; height: 14px; color: var(--warm); flex: none; }
.power.alert { border-color: rgba(255, 150, 90, 0.7); animation: alertGlow 0.9s ease-in-out infinite; }
.power.alert .bolt { color: var(--warn); }
@keyframes alertGlow { 50% { box-shadow: 0 0 14px 2px rgba(255, 140, 80, 0.55); } }
body.calm .power.alert { animation: none; box-shadow: 0 0 10px 1px rgba(255, 140, 80, 0.5); }
.hud-buttons { margin-left: auto; display: flex; gap: 8px; pointer-events: auto; }
.chip { pointer-events: auto; cursor: pointer; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass); color: var(--dim); font-size: 12px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.chip:hover { color: var(--ink); }
.chip:focus-visible, .btn:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.chip:disabled { opacity: 0.45; cursor: default; }
.icon-chip { display: inline-flex; align-items: center; gap: 6px; }
.spk { width: 16px; height: 16px; flex: none; }
.spk .slash, .icon-chip.off .spk .waves { display: none; }
.icon-chip.off .spk .slash { display: inline; }
.fps { position: absolute; top: calc(var(--edge-t) + 44px); right: var(--edge-r); padding: 2px 8px; border-radius: 6px; background: rgba(10, 16, 18, 0.5); font-size: 11px; color: var(--dim); }

.hud-bottom { position: absolute; left: var(--edge-l); right: var(--edge-r); bottom: var(--edge-b); display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.stats { display: grid; gap: 7px; padding: 12px 14px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); width: 240px; }
.bar { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); }
.bar b { font-weight: 600; font-size: 10px; color: var(--dim); }
.bar b.on { color: var(--bat); }
.track { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.fill { height: 100%; width: 100%; transform-origin: left center; transition: transform 0.2s linear; border-radius: 4px; }
.hp .fill { background: var(--hp); }
.hp .fill.low { animation: pulse 0.8s ease-in-out infinite; }
.bat .fill { background: var(--bat); }
.bat.low .fill { animation: pulse 0.6s ease-in-out infinite; }
.fuel .fill { background: var(--fuel); }
.fuel.low .fill { animation: pulse 0.6s ease-in-out infinite; }
.load .fill { background: #ffc06a; }
.load.low .fill { background: #ff9a5a; animation: pulse 0.45s ease-in-out infinite; }
.load.tripped .fill { background: #ff7a5a; opacity: 0.6; }
.load.tripped .label { color: var(--warn); }
/* 설정에서 흔들림·점멸을 끄면 경고 막대도 깜박이지 않는다. */
body.calm .fill { animation: none !important; }
.inv { display: flex; gap: 14px; font-size: 12px; color: var(--dim); padding-top: 2px; }
.inv b { color: var(--ink); font-size: 14px; margin-left: 3px; }
.keys { font-size: 12px; color: var(--dim); text-align: right; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); max-width: 46ch; line-height: 1.6; }
@keyframes pulse { 50% { opacity: 0.35; } }

.prompt { position: absolute; left: 50%; bottom: 26%; transform: translateX(-50%); padding: 9px 16px 11px; border-radius: 12px; background: rgba(10, 16, 18, 0.72); border: 1px solid var(--line); font-size: 14px; text-align: center; min-width: 220px; max-width: calc(100vw - 32px); }
.prompt-bar { margin-top: 7px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#prompt-fill { height: 100%; width: 100%; background: var(--warm); transform: scaleX(0); transform-origin: left center; }

.toasts { position: absolute; top: 72px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; width: min(92vw, 560px); }
.toast { padding: 9px 16px; border-radius: 999px; background: rgba(10, 16, 18, 0.7); border: 1px solid var(--line); font-size: 14px; text-align: center; animation: toastIn 0.35s ease both; transition: opacity 0.5s ease, transform 0.5s ease; }
.toast.good { color: var(--good); }
.toast.warn { color: var(--warn); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.pointer { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.pointer .arrow { position: absolute; left: -14px; top: -14px; width: 28px; height: 28px; }
.pointer .arrow::before { content: ""; position: absolute; left: 6px; top: 6px; border-left: 18px solid #ff8a6a; border-top: 8px solid transparent; border-bottom: 8px solid transparent; filter: drop-shadow(0 0 6px rgba(255, 120, 90, 0.9)); }
.pointer span { position: absolute; left: -24px; top: 16px; width: 48px; text-align: center; font-size: 11px; color: #ffc2ae; text-shadow: 0 1px 3px #000; }

/* ---------- 화면 ---------- */
/* 내용이 화면보다 길면(가로로 눕힌 휴대폰) 스크롤한다. 카드의 margin: auto는 남는 공간이 있을 때만 가운데로 모아,
   넘칠 때 위쪽이 잘려 보이지 않게 한다. */
.screen { position: fixed; inset: 0; display: flex; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: var(--edge-t) var(--edge-r) var(--edge-b) var(--edge-l); background: radial-gradient(ellipse at center, rgba(8, 14, 16, 0.25), rgba(8, 14, 16, 0.7)); }
.screen > .card { margin: auto; }
#title { background: linear-gradient(180deg, rgba(8, 14, 16, 0.05), rgba(8, 14, 16, 0.55)); }
#settings { background: rgba(8, 14, 16, 0.6); }
.card { width: min(560px, 100%); text-align: center; padding: 34px 30px 26px; border-radius: 22px; background: rgba(12, 19, 21, 0.58); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); }
.card.small { width: min(420px, 100%); display: grid; gap: 10px; }
.eyebrow { margin: 0 0 8px; font-size: 11px; letter-spacing: 0.32em; color: var(--warm); opacity: 0.85; }
h1 { margin: 0; font-size: clamp(40px, 8vw, 64px); font-weight: 300; letter-spacing: 0.04em; text-shadow: 0 0 30px rgba(255, 207, 134, 0.35); }
h2 { margin: 0 0 4px; font-weight: 400; font-size: 26px; }
.tagline { color: var(--dim); line-height: 1.7; font-size: 15px; margin: 14px 0 22px; }
.btn { pointer-events: auto; cursor: pointer; border: 0; border-radius: 999px; padding: 13px 34px; font-size: 16px; font-weight: 600; color: #1c1408; background: linear-gradient(180deg, #ffd99b, #f4b45c); box-shadow: 0 0 0 1px rgba(255, 220, 160, 0.4), 0 8px 30px rgba(255, 180, 90, 0.35); transition: transform 0.15s ease, box-shadow 0.15s ease; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(255, 220, 160, 0.6), 0 10px 36px rgba(255, 180, 90, 0.5); }
.btn:disabled { cursor: progress; opacity: 0.55; transform: none; box-shadow: none; }
.btn.ghost { background: transparent; color: var(--dim); box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; }
/* 좁은 세로 화면(360~390px)에서 칩 4개가 한 줄에 안 들어가면 글자가 한 자씩 접히지 않고 칩째 다음 줄로 넘긴다. */
.title-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.title-links .chip { font-size: 13px; padding: 7px 16px; white-space: nowrap; }
.howto { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 8px; text-align: left; font-size: 13px; color: var(--dim); line-height: 1.55; }
.howto b { color: var(--ink); font-weight: 600; margin-right: 6px; }
.best { margin: 16px 0 0; font-size: 12px; color: var(--warm); opacity: 0.8; min-height: 1em; }

/* ---------- 공유 보급품 ---------- */
.online { margin-top: 14px; display: grid; gap: 8px; justify-items: center; }
.online-summary { margin: 0; font-size: 13px; color: var(--cache); min-height: 1em; }
.online-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.online-row .chip[aria-pressed="false"] { opacity: 0.7; }
.online-note { margin: 0; font-size: 11px; color: var(--dim); line-height: 1.5; max-width: 420px; }
.chip.drop { color: var(--cache); border-color: rgba(120, 230, 214, 0.35); }
.place { position: absolute; left: 50%; bottom: calc(var(--edge-b) + 4px); transform: translateX(-50%); pointer-events: auto; padding: 12px 14px; border-radius: 14px; background: rgba(10, 16, 18, 0.82); border: 1px solid rgba(120, 230, 214, 0.35); width: min(440px, 92vw); display: grid; gap: 10px; }
.place-title { margin: 0; font-size: 14px; color: var(--cache); text-align: center; }
.place-title .dim { font-size: 12px; }
.place-items { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.place-items button { cursor: pointer; padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--ink); font-size: 13px; }
.place-items button:not(:disabled):hover { border-color: rgba(120, 230, 214, 0.6); }
.place-items button:disabled { cursor: not-allowed; opacity: 0.4; }
.place-items b { display: block; margin-top: 3px; font-weight: 500; font-size: 11px; color: var(--dim); }
.place-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.place .key { display: inline-block; min-width: 1.4em; margin-right: 5px; padding: 0 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); font-size: 11px; color: var(--dim); }
.place.busy { opacity: 0.6; pointer-events: none; }
.notice { position: fixed; top: var(--edge-t); left: 50%; transform: translateX(-50%); z-index: 10; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 12px; background: rgba(40, 18, 14, 0.85); border: 1px solid rgba(255, 176, 138, 0.4); color: var(--warn); font-size: 14px; width: max-content; max-width: 92vw; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; }

/* ---------- 설정 ---------- */
.settings-card { width: min(800px, 100%); text-align: left; padding: 20px 24px 24px; -webkit-user-select: none; user-select: none; }
.settings-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.settings-head h2 { margin: 0; outline: none; }
.settings-head .chip { font-size: 13px; padding: 7px 16px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 6px 28px; align-items: start; }
.group { display: grid; gap: 10px; padding: 14px 0 6px; border-top: 1px solid var(--line); min-width: 0; }
.group h3 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: 0.26em; color: var(--warm); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; min-height: 30px; cursor: pointer; }
.row > span:first-child { min-width: 0; }
.row small { display: block; font-size: 11px; color: var(--dim); margin-top: 2px; }
.row.slider { display: grid; grid-template-columns: 6.5em minmax(0, 1fr) 3.2em; }
.row output { font-size: 12px; color: var(--dim); text-align: right; font-variant-numeric: tabular-nums; }
.hint { margin: 0; font-size: 12px; line-height: 1.6; color: var(--dim); }
.hint.strong { color: var(--ink); font-size: 13px; }
.hint.good { color: var(--good); }
.hint.warn { color: var(--warn); }
.hint:empty { display: none; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.row-btns:empty { display: none; }
.chip.danger { color: var(--warn); }
input[type="range"] { width: 100%; margin: 0; accent-color: #f4b45c; cursor: pointer; touch-action: pan-y; }
.switch { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 44px; height: 26px; margin: 0; border-radius: 13px; background: rgba(255, 255, 255, 0.16); cursor: pointer; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform 0.2s; }
.switch:checked { background: #f4b45c; }
.switch:checked::after { transform: translateX(18px); background: #1c1408; }
.switch:focus-visible, input[type="range"]:focus-visible { outline: 2px solid var(--warm); outline-offset: 3px; }
.seg { display: inline-flex; flex: none; border-radius: 999px; border: 1px solid var(--line); overflow: hidden; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 6px 13px; font-size: 13px; color: var(--dim); }
.seg input:checked + span { background: rgba(255, 207, 134, 0.24); color: var(--ink); }
.seg input:focus-visible + span { outline: 2px solid var(--warm); outline-offset: -2px; }
@media not all and (any-pointer: coarse) { .touch-only { display: none; } }

/* ---------- 옷장 ---------- */
/* 인물이 보이도록 화면 전체를 덮지 않고, 패널만 오른쪽(세로 화면은 아래)에 띄운다. */
.screen.closet { padding: var(--edge-t) max(var(--edge-r), 4vw) var(--edge-b) var(--edge-l); background: linear-gradient(90deg, rgba(8, 14, 16, 0) 35%, rgba(8, 14, 16, 0.55)); pointer-events: none; }
.screen.closet > .closet-panel { margin: auto 0 auto auto; }
.closet-panel { pointer-events: auto; touch-action: pan-y; width: min(400px, 100%); max-height: 100%; overflow-y: auto; text-align: left; padding: 22px 20px 18px; display: grid; gap: 14px; }
.closet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.closet-head h2 { margin: 0; font-size: 22px; }
.closet-count { font-size: 12px; color: var(--warm); }
.closet-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.closet-tabs .chip { font-size: 13px; padding: 7px 14px; }
.closet-tabs .chip.on { color: #1c1408; background: var(--warm); border-color: transparent; }
.closet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.closet-item { cursor: pointer; display: grid; justify-items: start; gap: 4px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--ink); text-align: left; font-size: 13px; }
.closet-item:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); }
.closet-item.on { border-color: var(--warm); box-shadow: inset 0 0 0 1px var(--warm); }
.closet-item.locked { cursor: default; opacity: 0.5; }
.closet-item .swatch { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25); }
.closet-item .swatch.empty { background: repeating-linear-gradient(45deg, transparent 0 4px, rgba(255, 255, 255, 0.2) 4px 5px); }
.closet-item.locked .swatch { filter: grayscale(0.6) brightness(0.7); }
.closet-item .note { min-height: 1em; font-size: 11px; color: var(--dim); }
.closet-item.on .note { color: var(--warm); }
.closet-note { margin: 0; font-size: 12px; line-height: 1.55; color: var(--dim); }
/* 목록이 길어 패널이 스크롤돼도 닫기 버튼은 늘 보이게 바닥에 붙인다. */
.closet-panel .btn { justify-self: center; position: sticky; bottom: 0; }
@media (max-height: 520px) {
  .closet-note { display: none; }
  .closet-panel { padding: 14px 14px 12px; gap: 10px; }
  .closet-item { padding: 8px; }
}
@media (orientation: portrait) {
  .screen.closet { padding: 16px var(--edge-r) var(--edge-b) var(--edge-l); background: linear-gradient(180deg, rgba(8, 14, 16, 0) 40%, rgba(8, 14, 16, 0.55)); }
  .screen.closet > .closet-panel { margin: auto 0 0; }
  .closet-panel { width: 100%; max-height: 50vh; max-height: 50dvh; padding: 16px 14px 14px; gap: 10px; }
  .closet-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
}

/* ---------- 터치 ---------- */
.touch { position: fixed; inset: 0; pointer-events: none; }
.stick-zone { position: absolute; left: 0; bottom: 0; width: 50%; height: 62%; pointer-events: auto; touch-action: none; }
.stick { position: fixed; width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(10, 16, 18, 0.25); opacity: 0; transition: opacity 0.15s; pointer-events: none; }
.stick.on { opacity: 1; }
.knob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(255, 230, 190, 0.55); }
.touch-btns { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: calc(var(--edge-b) + 4px); display: grid; grid-template-columns: auto auto; gap: 10px; pointer-events: auto; }
.touch-btns button { width: 74px; height: 74px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(10, 16, 18, 0.5); color: var(--ink); font-size: 13px; touch-action: none; }
.touch-btns button.big { grid-column: span 2; width: 100%; height: 64px; border-radius: 32px; background: rgba(255, 207, 134, 0.25); }
.touch-btns button.down { background: rgba(255, 207, 134, 0.5); }
/* 왼손 모드: 스틱은 오른쪽, 버튼은 왼쪽 */
.touch.lefty .stick-zone { left: auto; right: 0; }
.touch.lefty .touch-btns { right: auto; left: max(14px, env(safe-area-inset-left)); }

/* ---------- 터치·좁은 화면 공통 ---------- */
@media (pointer: coarse), (max-width: 720px) {
  .hud-bottom { bottom: auto; top: calc(var(--edge-t) + 46px); }
  .stats { width: 200px; padding: 9px 11px; }
  .keys { display: none; }
  .prompt { bottom: 34%; }
  .toasts { top: auto; bottom: 46%; }
  .place .key { display: none; }
  /* 위쪽 줄은 좁아서 두 줄로 넘치면 체력 상자에 가린다. 터치 버튼 묶음 바로 위에 띄운다(왼손 모드면 왼쪽). */
  .chip.drop { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: calc(var(--edge-b) + 168px); padding: 10px 14px; font-size: 13px; background: rgba(10, 16, 18, 0.6); }
  body:has(#touch.lefty) .chip.drop { right: auto; left: max(14px, env(safe-area-inset-left)); }
  .pill { font-size: 12px; padding: 6px 11px; }
}

/* 좁은 세로 화면: 맨 위 한 줄에 다 들어가게 줄인다. */
@media (max-width: 480px) {
  .wide-only, .icon-chip .chip-text { display: none; }
  .icon-chip { padding: 7px 10px; }
  .pill { gap: 7px; }
}

/* 세로 화면(휴대폰): 안내 토스트를 상태 창 아래로 올려 화면 가운데의 캐릭터를 가리지 않게 한다. */
@media (pointer: coarse) and (orientation: portrait), (max-width: 720px) and (orientation: portrait) {
  .toasts { bottom: auto; top: calc(var(--edge-t) + 46px + 120px); }
  /* 세로 화면에서는 알림이 위쪽에 뜨므로, 남기기 창은 '보급품 남기기' 버튼 위에 띄운다. */
  .place { bottom: calc(var(--edge-b) + 216px); }
}

/* 가로로 눕힌 휴대폰(낮은 화면): 위는 상태, 아래 양옆은 스틱·버튼, 가운데는 비워 둔다. */
@media (orientation: landscape) and (max-height: 540px) {
  :root { --edge-t: max(10px, env(safe-area-inset-top)); --edge-b: max(10px, env(safe-area-inset-bottom)); }
  .hud-bottom { top: calc(var(--edge-t) + 42px); }
  .stats { width: 184px; padding: 8px 10px; gap: 5px; }
  .bar { grid-template-columns: 66px 1fr; font-size: 11px; }
  .inv { gap: 10px; font-size: 11px; }
  .inv b { font-size: 13px; }
  .fps { top: calc(var(--edge-t) + 40px); }
  /* 토스트는 상태 창(왼쪽)과 겹치지 않는 폭으로 위 가운데에, 최근 3개까지만. */
  .toasts { top: calc(var(--edge-t) + 42px); bottom: auto; width: min(460px, calc(100vw - 2 * (max(var(--edge-l), var(--edge-r)) + 196px))); gap: 6px; }
  .toast { font-size: 13px; padding: 7px 14px; }
  .toast:nth-last-child(n + 4) { display: none; }
  .prompt { bottom: 22%; }
  .touch-btns { gap: 8px; }
  .touch-btns button { width: 64px; height: 64px; font-size: 12px; }
  .touch-btns button.big { height: 54px; }
  .stick-zone { height: 72%; }
  /* 타이틀: 왼쪽 제목·시작, 오른쪽 안내 두 단 */
  .title-card { width: min(880px, 100%); display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: center; gap: 0 30px; text-align: left; padding: 20px 26px; }
  .title-card h1 { font-size: 44px; }
  .title-card .tagline { margin: 10px 0 16px; font-size: 13.5px; line-height: 1.6; }
  .title-card .title-links { justify-content: flex-start; margin-top: 12px; }
  .title-card .howto { margin: 0; gap: 7px; font-size: 12.5px; }
  .title-card .best { margin-top: 12px; }
  .card { padding: 22px 26px 20px; }
  .card.small { padding: 18px 22px; gap: 8px; }
  .card.small .tagline { margin: 6px 0 10px; }
  .btn { padding: 11px 30px; }
  .settings-card { padding: 16px 22px 18px; }
}

/* ---------- 배전반 ---------- */
#grid { background: rgba(8, 14, 16, 0.6); }
.grid-card { width: min(680px, 100%); text-align: left; padding: 20px 24px 22px; display: grid; gap: 10px; }
.grid-card .settings-head { margin-bottom: 0; }
.grid-body { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 14px 24px; align-items: center; }
.grid-map-wrap { display: grid; place-items: center; height: 170px; }
/* 게임 화면과 같은 방향: 45도 돌리고 세로로 눌러 아이소메트릭 바닥처럼 보이게 한다(북서쪽 구역이 맨 위). */
.grid-map { display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); gap: 5px; transform: scaleY(0.64) rotate(45deg); }
.gcell { position: relative; border-radius: 6px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); cursor: pointer; transition: background 0.2s, box-shadow 0.2s; }
.gcell.dead { border-style: dashed; border-color: rgba(255, 130, 110, 0.35); background: rgba(255, 110, 90, 0.06); cursor: default; }
.gcell.off { background: rgba(159, 227, 176, 0.14); border-color: rgba(159, 227, 176, 0.35); }
.gcell.on, .gcell.home { background: rgba(255, 207, 134, 0.6); border-color: rgba(255, 220, 160, 0.8); box-shadow: 0 0 14px rgba(255, 190, 110, 0.55); }
.gcell.home { cursor: default; }
.gcell.tripped { background: rgba(255, 140, 70, 0.45); border-color: rgba(255, 150, 90, 0.9); animation: pulse 0.8s ease-in-out infinite; }
body.calm .gcell.tripped { animation: none; }
.gcell.here::after { content: ""; position: absolute; left: 50%; top: 50%; width: 11px; height: 11px; margin: -5.5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(14, 22, 24, 0.85), 0 0 10px rgba(255, 255, 255, 0.8); }
.grid-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; }
.zone-row { display: grid; gap: 2px; justify-items: start; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--ink); font-size: 13px; text-align: left; cursor: pointer; }
.zone-row:hover:not(:disabled) { border-color: rgba(255, 207, 134, 0.45); }
.zone-row:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.zone-row .zstate { font-size: 11px; color: var(--dim); }
.zone-row[aria-pressed="true"] { border-color: rgba(255, 207, 134, 0.55); background: rgba(255, 207, 134, 0.12); }
.zone-row[aria-pressed="true"] .zstate { color: var(--warm); }
.zone-row.tripped .zstate { color: var(--warn); }
.zone-row.home { opacity: 0.85; }
.zone-row.dead { opacity: 0.5; }
.zone-row:disabled { cursor: default; }
.zone-row.here .zname::after { content: " · 지금 여기"; font-size: 11px; color: var(--good); }
@media (max-width: 560px) {
  .grid-body { grid-template-columns: 1fr; }
  .grid-map-wrap { height: 140px; }
  .grid-list { grid-template-columns: 1fr 1fr; }
}

/* ---------- 이야기: 무전 장면 ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.toast.story { color: #b9e0ff; }
.pointer.story .arrow::before { border-left-color: #8fd0ff; filter: drop-shadow(0 0 6px rgba(120, 190, 255, 0.9)); }
.pointer.story span { color: #cfe8ff; }

.story-layer { position: fixed; inset: 0; z-index: 5; cursor: pointer; touch-action: none; }
.story-layer.leaving { pointer-events: none; }
.letterbox { position: absolute; left: 0; right: 0; height: min(11vh, 96px); background: rgba(3, 6, 7, 0.92); transition: transform 0.5s ease; }
.letterbox.top { top: 0; transform: translateY(-100%); }
.letterbox.bottom { bottom: 0; transform: translateY(100%); }
.story-layer.on .letterbox { transform: none; }
.story-fade { position: absolute; inset: 0; background: #020405; opacity: 0; transition: opacity 0.42s ease; pointer-events: none; }
.story-fade.on { opacity: 1; }
.story-skip { position: absolute; top: var(--edge-t); right: var(--edge-r); z-index: 1; font-size: 12px; }
.story-layer.leaving .story-skip { display: none; }
.story-box { position: absolute; left: 50%; bottom: calc(var(--edge-b) + 4px); transform: translateX(-50%); width: min(720px, calc(100vw - 24px)); min-height: 104px; padding: 14px 22px 18px; border-radius: 16px; background: rgba(8, 13, 15, 0.86); border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45); animation: storyIn 0.3s ease both; }
@keyframes storyIn { from { opacity: 0; transform: translate(-50%, 8px); } }
.story-who { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.18em; color: var(--ink); }
.story-box[data-who="gran"] .story-who { color: var(--warm); }
.story-box[data-who="me"] .story-who { color: #b9e0ff; }
.radio-wave { display: none; align-items: flex-end; gap: 2px; height: 12px; }
.story-box[data-who="other"] .story-who { color: #c9d4d0; }
.story-box[data-who="gran"] .radio-wave, .story-box[data-who="other"] .radio-wave { display: inline-flex; }
.radio-wave i { width: 3px; border-radius: 1px; background: currentColor; animation: wave 0.9s ease-in-out infinite; }
.radio-wave i:nth-child(1) { height: 5px; }
.radio-wave i:nth-child(2) { height: 11px; animation-delay: -0.3s; }
.radio-wave i:nth-child(3) { height: 7px; animation-delay: -0.6s; }
@keyframes wave { 50% { transform: scaleY(0.4); } }
.story-text { margin: 0; font-size: 17px; line-height: 1.7; min-height: 2.9em; white-space: pre-wrap; }
.story-box[data-who="nar"] .story-text { font-style: italic; color: #e9dfcd; text-align: center; padding-top: 6px; }
.story-next { position: absolute; right: 18px; bottom: 10px; font-size: 11px; color: var(--warm); opacity: 0; }
.story-next.on { opacity: 1; animation: pulse 1.1s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .letterbox, .story-fade { transition-duration: 0.2s; }
  .radio-wave i, .story-next.on { animation: none; }
}

/* ---------- 이야기: 기록 읽기 ---------- */
.doc { z-index: 6; background: rgba(4, 8, 9, 0.74); }
.doc-wrap { margin: auto; width: min(560px, 100%); display: grid; gap: 14px; justify-items: center; padding: 8px 0; }
.paper { width: 100%; text-align: left; padding: 24px 28px 22px; border-radius: 4px; background: #efe6d2; color: #2b2620; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5); transform: rotate(-0.6deg); font-family: "Nanum Myeongjo", "NanumMyeongjo", "AppleMyungjo", "Noto Serif KR", "Batang", serif; -webkit-user-select: text; user-select: text; }
.paper-where { margin: 0 0 6px; font-family: var(--font); font-size: 11px; letter-spacing: 0.2em; color: #8a7a62; }
.paper h2 { margin: 0 0 14px; font-size: 21px; font-weight: 700; line-height: 1.35; }
.paper-body p { margin: 0 0 9px; font-size: 15px; line-height: 1.75; white-space: pre-wrap; }
.paper-hand { margin: 12px 0 0; font-family: "Nanum Pen Script", "NanumPen", "Gaegu", cursive; font-size: 19px; color: #9a3b2a; transform: rotate(-2deg); }
.paper-hand:empty, .doc-note:empty { display: none; }
.doc-note { margin: 0; max-width: 46ch; text-align: center; font-size: 14px; line-height: 1.6; font-style: italic; color: var(--dim); }
.kind-clipboard { border-top: 18px solid #8a6a48; font-variant-numeric: tabular-nums; }
.kind-poster { background: #f1e6c8; }
.kind-poster .paper-body p:nth-child(3) { font-size: 17px; font-weight: 700; text-align: center; margin: 14px 0; }
.kind-poster .paper-body p:last-child { text-align: right; }
.kind-chalk { background: #24382d; color: #ecebe2; border: 10px solid #7a5a40; border-radius: 6px; font-family: var(--font); transform: rotate(0.5deg); }
.kind-chalk .paper-where { color: #a8b8a8; }
.kind-chalk .paper-body p:first-child { color: #a8b8a8; font-size: 13px; }
.kind-brass { background: linear-gradient(160deg, #caa452, #8f6a2b); color: #2e2110; text-align: center; border-radius: 6px; transform: none; letter-spacing: 0.03em; box-shadow: inset 0 0 0 3px rgba(60, 40, 10, 0.45), 0 24px 60px rgba(0, 0, 0, 0.5); }
.kind-brass .paper-where { color: #4d3816; }
.kind-brass .paper-body p:last-child { margin-top: 14px; font-weight: 700; font-size: 16px; }
.kind-diary { background: #f6f1e3; }
.kind-diary .paper-body p:nth-child(odd) { margin: 12px 0 2px; font-weight: 700; font-size: 13px; color: #6f6150; }
.kind-letter { background: #f3ecdd repeating-linear-gradient(transparent, transparent 27px, rgba(150, 130, 100, 0.25) 28px); }
.kind-letter .paper-body p:last-child { text-align: right; }
.kind-radio { background: #e4e9e6; font-family: var(--font); transform: none; }
.kind-radio .paper-body p { line-height: 1.65; }
.kind-radio .line b { margin-right: 4px; color: #8a5a20; font-size: 13px; }
.kind-radio .who-me b { color: #2f5a6a; }
.kind-radio .who-other b { color: #4e5a56; }
.kind-radio .who-nar { font-style: italic; color: #5b5a55; }

/* ---------- 이야기: 수첩 ---------- */
.journal-card { width: min(780px, 100%); text-align: left; padding: 20px 24px 22px; }
.journal-card .settings-head h2 { margin: 0; outline: none; }
.journal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 6px 28px; align-items: start; }
.journal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.jrow { width: 100%; display: grid; gap: 2px; text-align: left; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); color: var(--ink); font-size: 14px; }
button.jrow { cursor: pointer; }
button.jrow:hover { background: rgba(255, 207, 134, 0.1); }
button.jrow:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.jrow small { font-size: 11.5px; color: var(--dim); }
li.jrow.locked { opacity: 0.55; color: var(--dim); }
li.jrow.open small { color: #9fd6ff; }
.journal-foot { align-items: center; margin-top: 12px; }

@media (orientation: landscape) and (max-height: 540px) {
  .letterbox { height: 8vh; }
  .story-box { min-height: 78px; padding: 10px 18px 12px; bottom: 6px; width: min(680px, calc(100vw - 2 * (var(--edge-l) + 8px))); }
  .story-text { font-size: 14.5px; line-height: 1.6; min-height: 2.4em; }
  .paper { padding: 18px 22px 16px; }
  .paper-body p { font-size: 14px; line-height: 1.6; }
}
@media (max-width: 480px) {
  .story-box { padding: 12px 16px 16px; }
  .story-text { font-size: 15.5px; }
  .paper { padding: 20px 20px 18px; }
}
