:root {
  --ink: #2c2a26;
  --ink-soft: #6b665d;
  --paper: #f7f2e8;
  --card: #fffdf8;
  --line: #e6dccb;
  --accent: #3d5a80;
  --el-0: #4f9d69;
  --el-1: #e0603f;
  --el-2: #d4a23c;
  --el-3: #8e99a5;
  --el-4: #3d5a80;
  --radius: 18px;
  --serif: 'Gowun Batang', serif;
  --sans: 'Gowun Dodum', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* ---------- 입력 · 결과 ---------- */
#intro, #result {
  overflow-y: auto;
  padding: 32px 16px 48px;
  background:
    radial-gradient(circle at 15% 10%, rgba(79,157,105,.14), transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(224,96,63,.12), transparent 40%),
    radial-gradient(circle at 50% 95%, rgba(61,90,128,.14), transparent 45%),
    var(--paper);
}
#intro.active, #result.active { display: flex; justify-content: center; align-items: flex-start; }
.intro-card, .result-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 22px;
  box-shadow: 0 10px 40px rgba(60, 45, 20, .08);
}
.eyebrow { margin: 0 0 6px; letter-spacing: .2em; font-size: 12px; color: var(--ink-soft); }
h1 { font-family: var(--serif); font-size: 40px; margin: 0 0 8px; }
.lead { color: var(--ink-soft); line-height: 1.6; margin: 0 0 22px; }
form { display: grid; gap: 14px; }
form label { display: grid; gap: 6px; font-size: 14px; }
form label.check { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); }
.hint { color: var(--ink-soft); font-size: 12px; }
input[type=date], input[type=time], select {
  font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink);
}
details { font-size: 13px; color: var(--ink-soft); }
details summary { cursor: pointer; margin-bottom: 8px; }
.primary {
  border: 0; border-radius: 14px; padding: 14px 18px; font-size: 16px;
  background: var(--ink); color: #fff; font-family: var(--serif); font-weight: 700;
}
.ghost { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 18px; }
.link { border: 0; background: none; color: var(--ink-soft); text-decoration: underline; padding: 8px; }
.privacy { font-size: 12px; color: var(--ink-soft); text-align: center; margin: 18px 0 0; }

.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 18px; }
.pillar { text-align: center; }
.pillar .cap { font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.pillar .ch {
  display: grid; place-items: center; height: 64px; border-radius: 14px; margin-bottom: 6px;
  font-family: var(--serif); font-size: 30px; color: #fff; position: relative;
}
.pillar .ch small { position: absolute; bottom: 4px; font-size: 11px; font-family: var(--sans); opacity: .85; }
.pillar .ch.empty { background: #eee8dc; color: var(--ink-soft); font-size: 14px; }
.bars { display: grid; gap: 8px; margin-bottom: 18px; }
.bar { display: grid; grid-template-columns: 44px 1fr 28px; align-items: center; gap: 8px; font-size: 14px; }
.bar-track { height: 10px; background: #f0e9dc; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transition: width .8s ease; }
.bar.lacking .bar-name { font-weight: 700; }
.verdict { border-radius: 16px; padding: 18px; color: #fff; margin-bottom: 12px; line-height: 1.6; }
.verdict h2 { font-family: var(--serif); margin: 4px 0 6px; font-size: 24px; }
.verdict .avatar { font-size: 15px; opacity: .95; }
.meta { font-size: 12px; color: var(--ink-soft); line-height: 1.5; }
.actions { display: grid; gap: 10px; margin-top: 16px; }

/* ---------- 마을 HUD ---------- */
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floater {
  position: absolute; left: 0; top: 0; font-weight: 700; font-size: 16px; white-space: nowrap;
  text-shadow: 0 1px 0 #fff, 0 0 6px rgba(255,255,255,.9);
}
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 0; pointer-events: none;
}
.place { display: grid; gap: 2px; background: rgba(255,253,248,.88); padding: 10px 14px; border-radius: 14px; backdrop-filter: blur(6px); }
.place strong { font-family: var(--serif); font-size: 18px; }
.place span { font-size: 12px; color: var(--ink-soft); }
.hud-buttons { display: flex; gap: 6px; pointer-events: auto; }
.chip-btn { border: 0; background: rgba(255,253,248,.92); padding: 9px 12px; border-radius: 12px; font-size: 13px; backdrop-filter: blur(6px); }
.hud-chips { position: absolute; top: calc(env(safe-area-inset-top) + 76px); left: 16px; display: grid; gap: 6px; pointer-events: none; }
.chip { justify-self: start; background: rgba(255,253,248,.85); padding: 6px 10px; border-radius: 10px; font-size: 12px; }
.chip.hot { background: var(--accent); color: #fff; }
.gauge {
  position: absolute; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 92px);
  max-width: 420px; margin: 0 auto; background: rgba(255,253,248,.9); border-radius: 14px; padding: 10px 14px; pointer-events: none;
}
.gauge-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.gauge-track { height: 10px; background: #ece4d4; border-radius: 6px; overflow: hidden; }
.gauge-fill { height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width .6s ease; }
.gauge.pulse { animation: pulse .5s ease; }
@keyframes pulse { 50% { transform: scale(1.03); } }

.actionbar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: safe center; gap: 6px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 14px); overflow-x: auto; scrollbar-width: none;
}
.act {
  flex: 0 0 auto; display: grid; justify-items: center; gap: 2px; min-width: 60px; white-space: nowrap;
  border: 0; border-radius: 16px; padding: 9px 10px; background: rgba(255,253,248,.94);
  box-shadow: 0 4px 14px rgba(0,0,0,.08); font-size: 11px;
}
.act .ic { font-size: 22px; line-height: 1; }
.act.on { background: var(--accent); color: #fff; }
.act:disabled { opacity: .45; }

#toasts { position: absolute; top: calc(env(safe-area-inset-top) + 76px); right: 16px; display: grid; gap: 6px; justify-items: end; pointer-events: none; max-width: 70%; }
.toast {
  background: rgba(44,42,38,.88); color: #fff; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4;
  animation: toast-in .3s ease;
}
.toast.good { background: var(--accent); }
@media (max-width: 639px) {
  #toasts { top: calc(env(safe-area-inset-top) + 140px); left: 16px; right: 16px; max-width: none; justify-items: center; }
  .act { min-width: 56px; padding: 8px; font-size: 10.5px; }
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 72%; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 22px 18px calc(env(safe-area-inset-bottom) + 22px);
  box-shadow: 0 -10px 40px rgba(0,0,0,.15); max-width: 520px; margin: 0 auto; animation: sheet-in .25s ease;
  z-index: 10;
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } }
.sheet[hidden] { display: none; }
.sheet-close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 26px; color: var(--ink-soft); }
.sheet h3 { font-family: var(--serif); margin: 0 0 4px; font-size: 21px; }
.sheet .sub { color: var(--ink-soft); font-size: 13px; margin: 0 0 14px; }
.sheet h4 { margin: 18px 0 8px; font-size: 14px; }
.sheet .rel { padding: 10px 12px; border-radius: 12px; background: #f4eee2; font-size: 14px; line-height: 1.5; }
.sheet .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.sheet .row button { flex: 1; }
.items { display: grid; gap: 6px; padding: 0; margin: 0; list-style: none; }
.items li { display: flex; justify-content: space-between; font-size: 14px; padding: 8px 10px; border-radius: 10px; background: #f7f2e8; }
.items li.got { background: #e9f3ea; }
.items li .need { color: var(--ink-soft); font-size: 12px; }
.stones { display: grid; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.progress { height: 10px; background: #ece4d4; border-radius: 6px; overflow: hidden; margin: 10px 0 6px; }
.progress div { height: 100%; border-radius: 6px; background: var(--accent); }
.rare { font-style: normal; font-size: 10px; background: #d4a23c; color: #fff; border-radius: 6px; padding: 1px 5px; margin-left: 4px; vertical-align: middle; }
textarea { width: 100%; min-height: 70px; font: inherit; border-radius: 12px; border: 1px solid var(--line); padding: 10px; resize: vertical; }
.notes { font-size: 13px; color: var(--ink-soft); display: grid; gap: 4px; margin-top: 8px; }

/* ---------- 집 안 ---------- */
#game.room .hud-top:not(.room-top), #game.room .hud-chips, #game.room .gauge,
#game.room .actionbar, #game.room .proto-badge { display: none; }
#room-ui[hidden] { display: none; }
#room-ui .room-top { z-index: 2; }
.room-score {
  position: absolute; left: 16px; top: calc(env(safe-area-inset-top) + 76px); width: 210px;
  background: rgba(255,253,248,.92); border-radius: 14px; padding: 10px 12px; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.06);
}
.rs-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 13px; color: var(--ink-soft); }
.rs-head strong { font-family: var(--serif); font-size: 26px; color: var(--ink); }
.rs-row { display: grid; grid-template-columns: 18px 1fr 46px; align-items: center; gap: 6px; font-size: 12px; margin-top: 4px; }
.rs-el { font-family: var(--serif); font-weight: 700; }
.rs-track { height: 7px; background: #ece4d4; border-radius: 4px; overflow: hidden; }
.rs-track div { height: 100%; border-radius: 4px; transition: width .5s ease; }
.rs-num { text-align: right; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.rs-foot { margin-top: 6px; font-size: 11px; color: var(--ink-soft); line-height: 1.4; }
.room-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
.room-actions { display: flex; justify-content: center; gap: 8px; padding: 10px 12px 14px; }
.room-actions .act { min-width: 110px; }
.toolbar {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; margin: 0 auto; max-width: 720px;
}
.sel-name { flex: 1; font-size: 13px; background: rgba(255,253,248,.92); padding: 8px 10px; border-radius: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sel-name.hint { color: var(--ink-soft); font-size: 12px; }
.tool { border: 0; border-radius: 10px; padding: 9px 12px; background: rgba(255,253,248,.95); font-size: 13px; box-shadow: 0 2px 8px rgba(0,0,0,.08); white-space: nowrap; }
.primary-tool { background: var(--ink); color: #fff; }
.tray {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px 14px; scrollbar-width: none;
  background: linear-gradient(to top, rgba(255,253,248,.95), rgba(255,253,248,.75));
  border-radius: 18px 18px 0 0;
}
.card {
  position: relative; flex: 0 0 auto; width: 96px; display: grid; justify-items: center; gap: 2px; text-align: center;
  border: 1px solid var(--line); border-radius: 14px; background: #fff; padding: 8px 6px; margin-top: 8px;
}
.card.locked { opacity: .5; background: #f4efe4; }
.c-emoji { font-size: 26px; line-height: 1.1; }
.c-name { font-size: 11.5px; line-height: 1.25; min-height: 2.5em; display: flex; align-items: center; }
.c-meta { font-size: 10px; color: var(--ink-soft); display: flex; align-items: center; gap: 3px; }
.c-meta i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.c-count { position: absolute; top: -6px; right: -4px; background: var(--accent); color: #fff; font-size: 10px; border-radius: 9px; padding: 1px 6px; }
.card-preview { width: 100%; max-width: 260px; display: block; margin: 0 auto; border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.15); }
@media (max-width: 639px) {
  .room-score { width: auto; right: 16px; top: calc(env(safe-area-inset-top) + 70px); padding: 8px 10px; }
  .rs-head strong { font-size: 22px; }
}

/* ---------- 멍 모드 ---------- */
.hud-top, .hud-chips, .gauge, .actionbar, #toasts { transition: opacity 1.2s ease; }
#game.mung .hud-top, #game.mung .hud-chips, #game.mung .gauge, #game.mung .actionbar,
#game.mung #toasts, #game.mung .proto-badge { opacity: 0; pointer-events: none; }
.letterbox { position: absolute; left: 0; right: 0; height: 0; background: #0b0d14; transition: height 1.6s ease; pointer-events: none; }
.letterbox.top { top: 0; }
.letterbox.bottom { bottom: 0; }
#game.mung .letterbox { height: 9vh; }
#mung { position: absolute; inset: 0; cursor: pointer; }
#mung[hidden] { display: none; }
#mung-line {
  position: absolute; left: 16px; right: 16px; top: calc(9vh + 24px); margin: 0; text-align: center;
  font-family: var(--serif); font-size: 18px; color: #fff; text-shadow: 0 1px 12px rgba(0,0,0,.45);
  opacity: 0; transition: opacity 1.4s ease;
}
#mung-line.show { opacity: 1; }
.mung-foot {
  position: absolute; left: 0; right: 0; bottom: 0; height: 9vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; color: rgba(255,255,255,.85);
}
#mung-timer { font-family: var(--serif); font-size: 15px; letter-spacing: .08em; }
.mung-hint { font-size: 11px; color: rgba(255,255,255,.45); }

.proto-badge {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 6px);
  font-size: 10px; letter-spacing: .05em; color: rgba(44,42,38,.55); pointer-events: none; display: none;
}
@media (min-width: 640px) { .proto-badge { display: block; } }
.tag { display: inline-block; font-family: var(--sans); font-size: 11px; font-weight: 400; vertical-align: middle; padding: 2px 7px; border-radius: 8px; background: #ece6da; color: var(--ink-soft); margin-left: 4px; }
.tag.real { background: #ffe7c2; color: #8a5a12; }
