@font-face { font-family: "Fraunces"; src: url("../assets/fonts/fraunces-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("../assets/fonts/fraunces-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("../assets/fonts/fraunces-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Inter"; src: url("../assets/fonts/inter-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Inter"; src: url("../assets/fonts/inter-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Inter"; src: url("../assets/fonts/inter-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --paper: #efe6d4;
  --ink: #1c1712;
  --ink-2: #5a5148;
  --cream: #f6f0e4;
  --table: #2c241e;
  --table-2: #3a2f26;
  --brass: #c9a56a;
  --madder: #c14b3a;
  --moss: #6a8a55;
  --rule: #d9ccb4;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--table); color: var(--cream); font: 400 16px/1.45 var(--sans); }
body {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, .btn { font: inherit; color: inherit; }
#app { height: 100%; display: grid; }
.screen { display: none; height: 100%; }
.screen.on { display: grid; }
canvas { display: block; width: 100%; height: 100%; }

/* Title */
#screen-title { place-items: center; background: radial-gradient(ellipse at 50% 30%, #3f352c, #1c1612 70%); }
.title-card { text-align: center; padding: 24px; max-width: 420px; }
#title-moth { width: 220px; height: 120px; margin: 0 auto 8px; }
.kicker { letter-spacing: .16em; text-transform: uppercase; font-size: 11px; color: var(--brass); font-weight: 600; margin: 0; }
h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(44px, 10vw, 68px); margin: 0 0 6px; letter-spacing: -.03em; }
.lede { font-family: var(--serif); font-style: italic; color: #d7cbb8; margin: 0 0 22px; }
.btn {
  appearance: none; border: 1px solid var(--brass); background: var(--brass); color: #1c1712;
  border-radius: 999px; padding: 12px 26px; font-weight: 600; cursor: pointer;
  min-height: 48px; min-width: 48px;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; color: var(--cream); border-color: #6a5c4c; }
.btn.danger { background: var(--madder); border-color: var(--madder); color: #fff; }
.btn.good { background: var(--moss); border-color: var(--moss); color: #fff; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.fine { font-size: 12px; color: #9a8f82; margin-top: 28px; }

/* Yard (level select) */
#screen-yard { grid-template-rows: auto 1fr; background: var(--table); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid #4a3f35; }
.brand { font-family: var(--serif); font-weight: 500; font-size: 22px; }
.stat { color: var(--brass); font-weight: 600; }
.yard-body { overflow: auto; padding: 16px clamp(12px, 3vw, 28px) 32px; }
.yard-body h2 { font-family: var(--serif); font-weight: 500; margin: 8px 0 12px; }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.levels button {
  appearance: none; text-align: left; background: var(--table-2); border: 1px solid #4a3f35;
  border-radius: 14px; padding: 12px 12px 14px; color: var(--cream); cursor: pointer; min-height: 84px;
}
.levels button:hover:not(:disabled) { border-color: var(--brass); }
.levels button:disabled { opacity: .4; cursor: default; }
.levels .n { font-family: var(--serif); font-size: 20px; display: block; }
.levels .stars { color: var(--brass); letter-spacing: .15em; font-size: 13px; }
.workshop { margin-top: 28px; display: grid; gap: 10px; }
.perk {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  border: 1px solid #4a3f35; border-radius: 12px; padding: 12px 14px; background: var(--table-2);
}
.perk p { margin: 0; color: #c9bfb2; font-size: 13px; }
.perk b { font-family: var(--serif); font-weight: 500; }

/* Battle */
#screen-battle { grid-template-rows: auto 1fr auto; min-height: 0; }
#stage { min-height: 0; position: relative; }
#board { width: 100%; height: 100%; }
.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: #241c17; border-bottom: 1px solid #4a3f35; font-size: 14px;
}
.hud b { color: var(--brass); font-variant-numeric: tabular-nums; }
.caption {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: rgba(28,23,18,.86); color: var(--cream); padding: 8px 14px; border-radius: 999px;
  font-size: 14px; pointer-events: none; max-width: 90%; text-align: center;
}
.dock {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: #241c17; border-top: 1px solid #4a3f35;
}
.shop { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.shop .tw {
  appearance: none; flex: 0 0 auto; width: 72px; min-height: 64px; border-radius: 12px;
  border: 1px solid #4a3f35; background: var(--table-2); color: var(--cream); cursor: pointer; padding: 6px 4px;
  font-size: 11px;
}
.shop .tw.on { border-color: var(--brass); background: #4a3c2c; }
.shop .tw:disabled { opacity: .35; }
.shop .tw .name { display: block; font-weight: 600; font-size: 12px; }
.shop .tw .cost { color: var(--brass); }
.inspect {
  display: none; grid-column: 1 / -1; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center;
  padding: 6px 2px 2px; font-size: 13px;
}
.inspect.on { display: grid; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; background: rgba(14,10,8,.62); display: none; place-items: center; padding: 20px; z-index: 20;
}
.overlay.on { display: grid; }
.sheet {
  background: var(--cream); color: var(--ink); border-radius: 18px; padding: 22px 22px 18px;
  max-width: 420px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.4);
}
.sheet h2 { font-family: var(--serif); font-weight: 500; margin: 0 0 8px; font-size: 28px; }
.sheet p { margin: 0 0 10px; color: var(--ink-2); }
.stars-big { color: #9a6b20; letter-spacing: .2em; font-size: 22px; margin: 4px 0 12px; }
.sheet .row { margin-top: 14px; }
.notice { font-size: 12px; color: #7a7168; margin-top: 18px; }

#ad-wait { z-index: 40; background: rgba(14,10,8,.78); color: var(--cream); }
#ad-wait p { font-family: var(--serif); font-style: italic; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px);
  background: var(--ink); color: var(--cream); padding: 8px 14px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .2s ease; z-index: 30; font-size: 14px;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 620px) {
  .inspect { grid-template-columns: 1fr 1fr; }
  .shop .tw { width: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.sheet .btn.ghost { color: var(--ink); border-color: #b8ab95; background: transparent; }
@media (max-width: 620px) {
  .dock { grid-template-columns: 1fr; }
  #btn-go { width: 100%; }
  .inspect { grid-template-columns: 1fr 1fr; }
}
