:root {
  --night: #141c2b;
  --night-2: #1d2840;
  --frost: #c9d6ea;
  --snow: #eef2f8;
  --paper: #f3ead8;
  --paper-2: #e7dcc4;
  --ink: #2b241c;
  --ink-soft: #5d5244;
  --red: #9b2c2c;
  --red-soft: #c2574f;
  --gold: #c99a3a;
  --green: #4f7a4a;
  --cold: #4a6fa5;
  --radius: 12px;
  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--night-2), var(--night) 70%);
  background-color: var(--night);
  color: var(--snow);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100%;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* top bar */
.bar { display: flex; align-items: center; gap: 12px; padding: 12px 0 8px; min-height: 52px; }
.bar-title { font-family: var(--serif); font-size: 18px; letter-spacing: .04em; color: var(--frost); flex: 1; }
.bar-day { font-family: var(--serif); font-size: 15px; color: var(--frost); white-space: nowrap; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(201, 214, 234, .3);
  background: rgba(255, 255, 255, .04); display: grid; place-items: center; cursor: pointer; color: var(--frost);
}
.icon-btn:hover { background: rgba(255, 255, 255, .1); }
.icon-btn[aria-pressed="true"] { color: var(--red-soft); }

/* buttons */
.btn {
  display: block; width: 100%; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid rgba(201, 214, 234, .35); background: rgba(255, 255, 255, .05);
  cursor: pointer; font-size: 16px; text-align: center; transition: transform .08s, background .15s;
}
.btn:hover { background: rgba(255, 255, 255, .1); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--paper); color: var(--ink); border-color: var(--paper); font-weight: 600; }
.btn.primary:hover { background: #fff7e6; }
.btn.ghost { border-color: transparent; background: none; color: var(--frost); }
.btn.small { width: auto; display: inline-block; padding: 10px 18px; font-size: 15px; }
.btn .sub { display: block; font-size: 12px; opacity: .7; font-weight: 400; margin-top: 2px; }
.btn:focus-visible, .choice:focus-visible, .icon-btn:focus-visible, .vbtn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* title */
#titleScreen { text-align: center; padding-top: 8px; }
.title-art { margin: 0 auto; max-width: 360px; }
.village-svg { width: 100%; height: auto; display: block; }
.village-svg .snow { fill: var(--snow); opacity: .9; }
.village-svg .house path { fill: #2a3754; stroke: #44557a; stroke-width: 1.5; }
.village-svg .door { fill: #1a2235; }
.village-svg .win { fill: var(--gold); opacity: .85; }
.village-svg .moon { fill: var(--snow); opacity: .85; }
.title { font-family: var(--serif); font-weight: 400; font-size: clamp(38px, 10vw, 54px); margin: 12px 0 6px; letter-spacing: .02em; }
.tagline { color: var(--frost); line-height: 1.5; margin: 0 0 24px; font-size: 16px; }
.title-actions { display: grid; gap: 10px; max-width: 360px; margin: 0 auto; width: 100%; }

.ledger-box { margin: 26px auto 0; max-width: 420px; text-align: left; }
.ledger-box h3 { font-family: var(--serif); font-weight: 400; font-size: 16px; color: var(--frost); margin: 0 0 8px; text-align: center; }
.ledger-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.ledger-item { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, .04); border: 1px dashed rgba(201, 214, 234, .2); color: rgba(201, 214, 234, .5); }
.ledger-item.found { background: rgba(243, 234, 216, .1); border-style: solid; border-color: rgba(243, 234, 216, .35); color: var(--paper); }
.ledger-item .n { float: right; opacity: .6; }
.ledger-note { font-size: 12px; color: rgba(201, 214, 234, .6); text-align: center; margin-top: 8px; }

/* hud */
.hud { display: grid; grid-template-columns: 0.8fr 1fr 1fr; gap: 8px; margin-top: 4px; }
.res {
  position: relative; background: rgba(255, 255, 255, .05); border: 1px solid rgba(201, 214, 234, .18);
  border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.res-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--frost); opacity: .8; }
.res-val { font-family: var(--serif); font-size: 24px; line-height: 1; }
.pips { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; height: 14px; align-items: center; }
.pip { height: 10px; border-radius: 2px; background: rgba(255, 255, 255, .1); }
.fear .pip.on { background: var(--red-soft); }
.trust .pip.on { background: var(--gold); }
.fear .pip.on.hot { background: #e2554b; box-shadow: 0 0 6px rgba(226, 85, 75, .6); }
.delta {
  position: absolute; right: 8px; top: 6px; font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none;
}
.delta.show { animation: floatUp 1.4s ease-out forwards; }
.delta.up { color: #8fd18a; }
.delta.down { color: #ff8b80; }
@keyframes floatUp { 0% { opacity: 0; transform: translateY(6px); } 15% { opacity: 1; } 100% { opacity: 0; transform: translateY(-14px); } }
.res.flash { animation: flash .5s; }
@keyframes flash { 50% { background: rgba(255, 255, 255, .18); } }

.steward-line { font-size: 13px; color: var(--frost); margin: 8px 0 2px; min-height: 18px; }
.steward-line b { color: var(--paper); font-weight: 600; }
.steward-line.due b { color: #ffb4a8; }

/* villagers */
.villagers { list-style: none; padding: 0; margin: 10px 0 4px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.vbtn {
  width: 100%; background: rgba(255, 255, 255, .04); border: 2px solid transparent; border-radius: 12px;
  padding: 6px 2px 6px; cursor: default; display: flex; flex-direction: column; align-items: center; gap: 2px;
  position: relative; transition: border-color .15s, background .15s, transform .1s;
}
.vbtn .face { width: 100%; max-width: 64px; aspect-ratio: 1; display: block; }
.vname { font-size: 11px; line-height: 1.1; text-align: center; color: var(--frost); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.vstate { font-size: 10px; min-height: 12px; color: rgba(201, 214, 234, .7); }
.vbtn.focus { border-color: var(--paper); background: rgba(243, 234, 216, .1); }
.vbtn.weak .face { filter: saturate(.3) brightness(.85); }
.vbtn.weak .vstate { color: #ffb4a8; }
.vbtn.gone { opacity: .45; }
.vbtn.gone .face { filter: grayscale(1) brightness(.6); }
.vbtn.pulse { animation: pulse .8s; }
@keyframes pulse { 30% { transform: scale(1.08); } }
.mem { position: absolute; top: 2px; left: 2px; right: 2px; display: flex; justify-content: space-between; pointer-events: none; }
.mem span { font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px; display: grid; place-items: center; padding: 0 3px; }
.mem .k { background: var(--gold); color: var(--ink); }
.mem .c { background: var(--cold); color: #fff; }

/* night feeding mode */
.night .vbtn.here { cursor: pointer; border-color: rgba(201, 214, 234, .25); }
.night .vbtn.here:hover { background: rgba(255, 255, 255, .09); }
.night .vbtn.fed { border-color: var(--gold); background: rgba(201, 154, 58, .16); }
.night .vbtn.hungry-risk .vstate { color: #ffb4a8; font-weight: 600; }
.phase-hint { font-size: 13px; color: var(--frost); min-height: 18px; margin: 8px 0 8px; text-align: center; }

/* card */
.card {
  background: linear-gradient(var(--paper), var(--paper-2)); color: var(--ink); border-radius: 14px;
  padding: 18px 18px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); position: relative;
}
.card.enter { animation: cardIn .35s ease-out; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) rotate(-.4deg); } }
.card-tag { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.card-tag .recall { color: var(--red); font-weight: 700; }
.card-text { font-family: var(--serif); font-size: 18px; line-height: 1.5; margin: 0 0 14px; }
.card-notes { list-style: none; padding: 0; margin: -4px 0 14px; font-size: 14px; color: var(--ink-soft); }
.card-notes li { padding: 3px 0; }
.card-notes .bad { color: var(--red); }
.card-notes .good { color: var(--green); }
.choices { display: grid; gap: 8px; }
.choices > * { min-width: 0; }
.choice {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 12px 14px;
  border-radius: 10px; border: 1px solid rgba(43, 36, 28, .25); background: rgba(255, 255, 255, .55);
  color: var(--ink); cursor: pointer; font-size: 16px; line-height: 1.3; transition: background .12s, transform .08s;
}
.choice:hover { background: #fff; }
.choice:active { transform: scale(.985); }
.choice .key { flex: none; width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(43, 36, 28, .3); display: grid; place-items: center; font-size: 12px; color: var(--ink-soft); }
.choice .lbl { flex: 1; min-width: 0; }
.choice .hintcost { flex: 0 1 auto; max-width: 48%; font-size: 12px; line-height: 1.35; color: var(--ink-soft); text-align: right; }
.choice.cruel { border-left: 4px solid var(--red); }
.choice.kind { border-left: 4px solid var(--gold); }
.choice.go { background: var(--ink); color: var(--paper); border-color: var(--ink); justify-content: center; font-weight: 600; }
.choice.go .key { border-color: rgba(243, 234, 216, .4); color: var(--paper); }
.choice.go:hover { background: #3a3127; }
.choice[disabled] { opacity: .45; cursor: not-allowed; }

/* ending */
#endScreen { padding-top: 8px; }
.end-kicker { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--frost); text-align: center; }
.end-title { font-family: var(--serif); font-weight: 400; font-size: clamp(30px, 8vw, 42px); text-align: center; margin: 6px 0 8px; }
.end-text { text-align: center; color: var(--frost); font-family: var(--serif); font-size: 17px; line-height: 1.5; margin: 0 0 18px; }
.epilogue { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.epilogue li { display: flex; gap: 10px; align-items: center; background: rgba(255, 255, 255, .05); border-radius: 10px; padding: 8px 10px; font-size: 14px; line-height: 1.4; }
.epilogue .face { width: 42px; height: 42px; flex: none; }
.epilogue li.gone .face { filter: grayscale(1) brightness(.6); }
.end-stats { text-align: center; font-size: 13px; color: var(--frost); margin: 14px 0 0; }

/* coach */
.coach { position: fixed; inset: auto 0 0 0; display: flex; justify-content: center; padding: 0 12px calc(12px + env(safe-area-inset-bottom)); z-index: 20; pointer-events: none; }
.coach-box {
  pointer-events: auto; max-width: 520px; width: 100%; background: #0d1320; border: 1px solid var(--gold);
  border-radius: 14px; padding: 14px 16px; box-shadow: 0 -6px 30px rgba(0, 0, 0, .5); animation: cardIn .3s ease-out;
}
.coach-title { font-family: var(--serif); font-size: 17px; color: var(--paper); margin-bottom: 6px; }
.coach-body { font-size: 14px; line-height: 1.5; color: var(--frost); margin-bottom: 10px; }
.coach-body p { margin: 0 0 6px; }
.coach-body b { color: var(--paper); }
.coach-box .btn { float: right; }
.coach-box::after { content: ''; display: block; clear: both; }

@media (max-width: 420px) {
  .villagers { gap: 4px; }
  .vname { font-size: 10px; }
  .card { padding: 16px 14px 14px; }
  .card-text { font-size: 17px; }
  .res-val { font-size: 22px; }
  .hud { gap: 6px; }
  .res { padding: 7px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
