:root {
  --pine: #143026;
  --pine-2: #1c4032;
  --moss: #2c6b45;
  --moss-2: #3d8a59;
  --gold: #e2b45a;
  --paper: #f6efe2;
  --paper-2: #efe4d0;
  --ink: #241c14;
  --muted: #74685b;
  --roof: #b94a36;
  --line: rgba(36, 28, 20, 0.12);
  --good: #1c7a46;
  --bad: #9d3030;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  --nav-h: 58px;
  color-scheme: light;
  font-family: "SamsungOne", "Samsung Sans", "Noto Sans CJK KR", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(900px 420px at 50% -80px, #2d5644 0%, transparent 60%),
    var(--pine);
  color: var(--paper);
  word-break: keep-all;
  overscroll-behavior: none;
}
button, textarea { font: inherit; }
button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:disabled { cursor: default; }

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
}

header {
  padding: 10px 12px 4px;
}
.title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
}
.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--gold);
}
h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.dynasty {
  font-size: 12px;
  color: #d9c7a4;
  text-align: right;
}

.resources {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin-top: 8px;
}
.res {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 0;
  border-radius: 9px;
  background: rgba(8, 20, 16, 0.35);
  color: var(--paper);
  padding: 4px 2px 5px;
  min-width: 0;
}
.res span { font-size: 10px; color: #d9cbb6; }
.res b { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.res.is-full b { color: var(--gold); }
.res svg { display: block; }

.status, .queue-strip {
  margin: 0;
  padding: 2px 12px;
  font-size: 12px;
  color: #d7cbb8;
  line-height: 1.35;
}
.queue-strip { color: var(--gold); min-height: 1.2em; }

.advisor {
  margin: 4px 12px 6px;
  text-align: left;
  border: 0;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 10px;
  line-height: 1.4;
  box-shadow: var(--shadow);
}
.advisor span { font-size: 13.5px; }

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.view-map {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.map-scroll { flex: 1; min-height: 120px; overflow: auto; padding: 4px 10px 8px; }
.map {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  background: #1a3328;
  border-radius: 16px;
  padding: 8px;
  box-shadow: inset 0 0 0 2px #345444;
}
.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #6f9446;
  color: white;
}
.tile svg { display: block; width: 100%; height: 100%; }
.tile .nm {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font-size: 10px;
  line-height: 1.25;
  padding: 1px 2px 2px;
  background: rgba(18, 14, 10, 0.62);
}
.tile .lv {
  position: absolute;
  top: 3px; right: 3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile .need {
  position: absolute;
  top: 3px; left: 3px;
  font-size: 9px;
  font-style: normal;
  background: rgba(18, 14, 10, 0.7);
  color: #f6efe2;
  border-radius: 999px;
  padding: 1px 4px;
}
.tile .bar {
  position: absolute;
  left: 4px; right: 4px; bottom: 16px;
  height: 4px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.tile .bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--gold);
}
.tile.is-selected { outline: 2px solid var(--gold); outline-offset: -2px; }
.tile.is-hint { box-shadow: inset 0 0 0 2px #f2d48a; }
.tile.is-locked { filter: saturate(0.55) brightness(0.78); }
.tile.is-water { background: #4f86b5; }

.sheet {
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px 16px 0 0;
  padding: 12px 12px 10px;
  max-height: min(340px, 42vh);
  overflow: auto;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
}
.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.kicker { margin: 0 0 2px; color: var(--roof); font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); }
.blurb { margin: 0 0 8px; line-height: 1.45; }
.lines { margin: 0 0 8px; padding: 0; list-style: none; }
.lines li { padding: 2px 0; font-variant-numeric: tabular-nums; }
.costs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; padding: 0; list-style: none; }
.costs li {
  background: white;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 13px;
}
.costs li.short { color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }
.reason { min-height: 1.2em; margin: 0 0 8px; color: var(--bad); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  appearance: none;
  border: 0;
  background: var(--moss);
  color: #f6efe2;
  border-radius: 11px;
  padding: 11px 14px;
  font-weight: 700;
  min-height: 44px;
}
.btn:disabled { background: #d9d0c2; color: #6e655c; }
.btn.ghost { background: transparent; color: var(--moss); box-shadow: inset 0 0 0 1.5px var(--moss); }
.btn.warn { background: var(--roof); }
.btn.small { min-height: 36px; padding: 7px 10px; font-size: 13px; }

.page { flex: 1; overflow: auto; padding: 8px 12px 16px; }
.card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
}
.card h2, .card h3 { margin: 0 0 6px; }
.card h3 { font-size: 16px; }
.card p { margin: 0 0 8px; line-height: 1.45; }

.heroes, .pips, .choices { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 0;
  background: white;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 10px;
  min-height: 36px;
}
.chip.is-on { background: var(--moss); color: white; }
.pip {
  width: 8px; height: 8px; border-radius: 99px;
  background: #ddd4c6; display: inline-block;
}
.pip.on { background: var(--moss); }

.road { display: flex; flex-direction: column; gap: 8px; }
.stage {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
}
.dot {
  width: 12px; height: 12px; border-radius: 99px;
  background: #d9d0c2; margin-top: 16px;
  box-shadow: 0 14px 0 0 #d9d0c2;
}
.stage.is-clear .dot { background: var(--moss); }
.stage.is-next .dot { background: var(--gold); }
.stage.is-locked .card { opacity: 0.72; }

.bar-track { height: 8px; background: #e5dccb; border-radius: 99px; overflow: hidden; }
.bar-track i { display: block; height: 100%; background: var(--moss-2); width: 0; }

nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: #10241c;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.tab {
  border: 0;
  background: transparent;
  color: #d7cbb8;
  border-radius: 10px;
  min-height: 46px;
  font-weight: 700;
  font-size: 13px;
  position: relative;
}
.tab.is-on { background: var(--paper); color: var(--ink); }
#log-badge {
  position: absolute;
  top: 4px; right: 8px;
  background: var(--roof);
  color: white;
  border-radius: 99px;
  font-size: 10px;
  min-width: 16px;
  padding: 1px 4px;
  font-style: normal;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  background: #241c14;
  color: var(--paper);
  border-radius: 999px;
  padding: 10px 14px;
  max-width: min(92vw, 420px);
  z-index: 40;
  box-shadow: var(--shadow);
  text-align: center;
}
.toast[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 14, 12, 0.62);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 10px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(560px, 100%);
  max-height: min(86dvh, 760px);
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px 18px 12px 12px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin: 8px 0; font-size: 22px; }
.modal-card .lead { margin-top: 0; font-size: 15px; }
.warn-banner {
  background: #f3d7c8;
  border-radius: 10px;
  padding: 8px 10px;
  margin: 0 0 10px;
}
.gain-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.gain { background: white; border-radius: 10px; padding: 8px; }
.gain span { display: block; font-size: 12px; color: var(--muted); }
.gain b { font-size: 18px; color: var(--good); }
.gain.neg b { color: var(--bad); }
.modal-card ul { margin: 6px 0 10px; padding-left: 18px; }
.modal-card li { margin: 3px 0; }
.seal {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--roof);
  color: white;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 88px;
  border-radius: 10px;
  border: 1px solid #e0d5c4;
  background: white;
  color: var(--ink);
  padding: 8px;
  resize: vertical;
}
.check { margin: 0 0 4px; }
.check.ok { color: var(--good); }
.ach { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.ach.lock { opacity: 0.55; }

@media (max-width: 380px) {
  h1 { font-size: 18px; }
  .res b { font-size: 12px; }
  .res span { font-size: 9px; }
  .tile .nm { font-size: 9px; }
  .advisor span { font-size: 13px; }
  header { padding-top: 8px; }
}

@media (min-width: 760px) {
  .view-map {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.8fr);
    gap: 10px;
    padding: 0 12px 12px;
  }
  .map-scroll { padding: 0; height: 100%; }
  .sheet {
    height: auto;
    max-height: 100%;
    align-self: start;
    border-radius: 16px;
    box-shadow: none;
  }
  .modal { align-items: center; }
  .modal-card { border-radius: 18px; }
  .page { padding-left: 16px; padding-right: 16px; }
  .map { gap: 8px; padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
