/* Kintu's Road — 16-colour palette, pixel UI. */
@font-face { font-family: 'Press Start 2P'; src: url('/fonts/PressStart2P-Regular.ttf') format('truetype'); font-display: swap; }
:root {
  --ink: #1b1b2f; --panel: #2a2a44; --panel2: #3b3b5c; --line: #4a4a70;
  --lake: #2b6cb0; --lake2: #63b3ed; --gold: #d69e2e; --sand: #f6e05e;
  --forest: #2f855a; --leaf: #68d391; --stone: #718096; --snow: #edf2f7;
  --earth: #c05621; --brick: #9b2c2c; --text: #f7fafc; --muted: #a0aec0; --boss: #805ad5;
  --pixel: 'Press Start 2P', monospace; --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--ink); color-scheme: dark; }
body { margin: 0; background: var(--ink); color: var(--text); font-family: var(--body); font-size: 15px; line-height: 1.45; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--lake2); }
svg { shape-rendering: crispEdges; image-rendering: pixelated; }
.px { font-family: var(--pixel); font-size: 11px; line-height: 1.6; letter-spacing: 0; }
h1, h2, h3 { font-family: var(--pixel); font-weight: normal; margin: 0; line-height: 1.5; }
h1 { font-size: 14px; } h2 { font-size: 12px; color: var(--sand); } h3 { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.hidden { display: none !important; }

/* Pixel frame: crisp double border via box-shadow */
.frame { background: var(--panel); border: 2px solid var(--line); box-shadow: inset 0 0 0 1px rgba(255,255,255,.05); }
.btn { font-family: var(--pixel); font-size: 10px; padding: 10px 12px; background: var(--panel2); border: 3px solid var(--line); box-shadow: inset -3px -3px 0 rgba(0,0,0,.35), inset 3px 3px 0 rgba(255,255,255,.08); color: var(--text); }
.btn:active { box-shadow: inset 3px 3px 0 rgba(0,0,0,.35); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.gold { background: var(--gold); color: var(--ink); border-color: #b7791f; }
.btn.green { background: var(--forest); border-color: #276749; }
.btn.red { background: var(--brick); border-color: #742a2a; }
.btn.small { padding: 6px 8px; font-size: 8px; }

/* Header */
header.top { position: sticky; top: 0; z-index: 20; background: var(--ink); border-bottom: 3px solid var(--line); padding: 10px 12px; display: flex; align-items: center; gap: 12px; }
header.top h1 { color: var(--sand); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .gold { font-family: var(--pixel); font-size: 11px; color: var(--sand); white-space: nowrap; }
.coin { display: inline-block; width: 12px; height: 12px; background: var(--sand); box-shadow: inset -3px -3px 0 var(--gold); vertical-align: -1px; margin-right: 4px; }

main { max-width: 1100px; margin: 0 auto; padding: 12px; display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
main > *, .col-main > * { min-width: 0; }
.title, .card-head > div, .shop-item, .boss-card > div { min-width: 0; overflow-wrap: anywhere; }
@media (min-width: 900px) { main { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; } .col-main { grid-column: 1; } #card { grid-column: 2; position: sticky; top: 64px; } }
.col-main { display: grid; gap: 16px; }

/* Map */
#map-wrap { width: 100%; overflow-x: auto; overflow-y: hidden; padding: 6px; scroll-snap-type: x proximity; }
#map { display: block; height: 220px; min-width: 100%; }
@media (min-width: 700px) { #map { height: 260px; } }
#map .region { cursor: pointer; }
#map .region.locked .terrain { filter: saturate(.25) brightness(.6); }
#map .sign text { font-family: var(--pixel); font-size: 11px; fill: var(--text); }
#map .sign rect:last-of-type { fill: var(--ink); stroke: var(--line); stroke-width: 3; }
#map .region.current .sign rect { stroke: var(--sand); }
#map .lock text { font-family: var(--pixel); font-size: 9px; fill: var(--sand); }
#map .guardian.defeated { opacity: .45; filter: grayscale(1); }
#map .guardian.wounded { opacity: .75; }
.map-caption { padding: 8px 12px 10px; color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Quest log */
#quests header { padding: 12px 12px 8px; border-bottom: 3px solid var(--line); }
#quests header p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.boss-card { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: center; margin: 12px; padding: 10px; background: var(--ink); border: 3px solid var(--boss); }
.boss-card.defeated { border-color: var(--stone); } .boss-card.wounded { border-color: var(--gold); }
.boss-card .name { font-family: var(--pixel); font-size: 10px; color: var(--text); }
.boss-card .flav { color: var(--muted); font-size: 13px; margin: 4px 0; }
.hp { height: 12px; background: #000; border: 2px solid var(--line); position: relative; }
.hp > i { display: block; height: 100%; background: var(--brick); }
.hp > b { position: absolute; inset: 0; font-family: var(--pixel); font-size: 8px; line-height: 8px; text-align: center; color: var(--text); }
.subject { padding: 10px 12px 4px; }
.subject h3 { display: flex; justify-content: space-between; }
.subject h3 .stat { color: var(--sand); }
ul.items { list-style: none; margin: 0; padding: 0; }
li.item { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 2px solid var(--line); }
li.item .type { font-family: var(--pixel); font-size: 7px; line-height: 1; padding: 6px 4px; text-align: center; background: var(--panel2); color: var(--text); border: 2px solid var(--line); }
li.item .type.math { border-color: var(--earth); } li.item .type.science { border-color: var(--leaf); } li.item .type.grammar, li.item .type.language { border-color: var(--lake2); } li.item .type.history { border-color: var(--sand); } li.item .type.french { border-color: var(--boss); } li.item .type.typing { border-color: var(--snow); }
li.item .title { min-width: 0; }
li.item .title button.open { all: unset; cursor: pointer; display: block; color: var(--text); }
li.item .title button.open:hover { color: var(--lake2); }
li.item .meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
li.item .xp { font-family: var(--pixel); font-size: 9px; color: var(--sand); }
li.item.done .title button.open { color: var(--muted); text-decoration: line-through; }
li.item.boss { background: rgba(128, 90, 213, .12); }
.tick { width: 36px; height: 36px; background: var(--panel2); border: 3px solid var(--line); font-family: var(--pixel); font-size: 14px; color: var(--leaf); }
.tick.done { background: var(--forest); border-color: var(--leaf); color: var(--text); }
details.side { margin: 4px 12px 12px; } details.side summary { font-family: var(--pixel); font-size: 9px; color: var(--muted); cursor: pointer; padding: 8px 0; }
.locked-note { padding: 24px 12px; color: var(--muted); text-align: center; }
.empty { padding: 20px 12px; color: var(--muted); }

/* Character card */
#card { padding: 12px; }
.card-head { display: grid; grid-template-columns: 80px 1fr; gap: 12px; align-items: center; }
.card-head svg { width: 80px; height: 108px; padding: 6px; background: var(--ink); border: 3px solid var(--line); }
.card-head .lvl { font-family: var(--pixel); font-size: 9px; color: var(--sand); margin-top: 6px; }
.card-head .ttl { color: var(--muted); font-size: 13px; }
.bar { height: 14px; background: #000; border: 2px solid var(--line); margin-top: 4px; }
.bar > i { display: block; height: 100%; transition: width .3s ease; }
.stat-row { margin-top: 10px; }
.stat-row .lab { display: flex; justify-content: space-between; font-family: var(--pixel); font-size: 9px; }
.stat-row .lab span:last-child { color: var(--muted); }
.stat-row small { color: var(--muted); font-size: 12px; }
.stat-row.forge .bar > i { background: var(--earth); } .stat-row.alchemy .bar > i { background: var(--leaf); }
.stat-row.song .bar > i { background: var(--lake2); } .stat-row.lore .bar > i { background: var(--sand); }
.xpbar > i { background: var(--boss); }
.streak { display: flex; gap: 6px; align-items: center; margin-top: 12px; font-family: var(--pixel); font-size: 9px; }
.streak .pip { width: 14px; height: 14px; border: 2px solid var(--line); background: #000; } .streak .pip.on { background: var(--sand); }
#card-toggle { display: none; }
@media (max-width: 899px) {
  #card { position: fixed; inset: 0 0 0 auto; width: min(360px, 92vw); z-index: 30; overflow-y: auto; transform: translateX(105%); transition: transform .25s ease; box-shadow: -10px 0 0 rgba(0,0,0,.4); }
  #card.open { transform: none; }
  #card-toggle { display: inline-block; }
}
#card-close { float: right; }
@media (min-width: 900px) { #card-close { display: none; } }

/* Shop */
.shop-grid { display: grid; gap: 10px; padding: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.shop-item { background: var(--ink); border: 3px solid var(--line); padding: 10px; display: grid; gap: 6px; }
.shop-item .n { font-family: var(--pixel); font-size: 10px; display: flex; justify-content: space-between; gap: 8px; }
.shop-item .n .price { color: var(--sand); white-space: nowrap; }
.shop-item .tier { font-family: var(--pixel); font-size: 7px; color: var(--muted); text-transform: uppercase; }
.shop-item .tier.rare { color: var(--boss); } .shop-item .tier.uncommon { color: var(--lake2); } .shop-item .tier.consumable { color: var(--leaf); }
.shop-item p { margin: 0; color: var(--muted); font-size: 13px; }
.shop-item .why { color: var(--gold); font-size: 12px; }
.requests { padding: 0 12px 12px; } .requests li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 2px solid var(--line); font-size: 13px; }
.status { font-family: var(--pixel); font-size: 8px; padding: 4px 6px; background: var(--panel2); }
.status.scheduled { color: var(--sand); } .status.done { color: var(--leaf); } .status.refunded { color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal .frame { width: min(520px, 100%); padding: 16px; display: grid; gap: 12px; }
.modal textarea, .modal input, .parent input, .parent select { width: 100%; font: inherit; color: var(--text); background: var(--ink); border: 3px solid var(--line); padding: 10px; }
.modal .count { color: var(--muted); font-size: 12px; text-align: right; }
.modal .count.ok { color: var(--leaf); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal .links a { display: block; padding: 10px; border: 2px solid var(--line); margin-top: 6px; word-break: break-all; }
.modal .err { color: #fc8181; font-size: 13px; }

/* Toasts */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 6px; z-index: 50; pointer-events: none; }
.toast { font-family: var(--pixel); font-size: 10px; padding: 10px 14px; background: var(--ink); border: 3px solid var(--sand); color: var(--sand); animation: rise 2.4s ease forwards; }
.toast.err { border-color: #fc8181; color: #fc8181; }
@keyframes rise { 0% { opacity: 0; transform: translateY(12px); } 15% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-12px); } }

/* Parent page */
.parent main { grid-template-columns: 1fr; max-width: 1000px; }
.parent section { padding: 12px; display: grid; gap: 10px; }
.parent .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.parent table { width: 100%; border-collapse: collapse; font-size: 13px; }
.parent th, .parent td { text-align: left; padding: 6px 4px; border-top: 2px solid var(--line); vertical-align: top; }
.parent th { font-family: var(--pixel); font-size: 8px; color: var(--muted); }
.parent .note { color: var(--muted); white-space: pre-wrap; }
.parent .mint li { display: flex; justify-content: space-between; padding: 4px 0; }
.parent .tabs button.active { background: var(--gold); color: var(--ink); }
.parent .ok { color: var(--leaf); } .parent .warn { color: var(--gold); } .parent .muted { color: var(--muted); }
.parent .table-wrap { overflow-x: auto; }
.parent label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
