/* Pagesworn — base styles, theme tokens, non-battle screens. */

@font-face {
  font-family: 'Cinzel';
  src: url('../fonts/cinzel-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  /* palette */
  --parchment: #f4e7c5;
  --parchment-2: #e9d6a6;
  --parchment-edge: #c8ac70;
  --ink: #2a1f14;
  --ink-soft: #5a4630;
  --gold: #c9a227;
  --gold-bright: #f2cf5b;
  --gold-deep: #8a6a12;
  --forest: #1e4620;
  --forest-2: #2f6a2e;
  --forest-3: #4f8f43;
  --stone: #6c7177;
  --stone-2: #9aa1a8;
  --stone-dark: #3e4246;
  --blood: #a3231b;
  --hp-good: #3fa34d;
  --hp-low: #d9452b;
  --sky: #9fd0e6;
  --white: #fffdf6;

  /* roles — themes swap these */
  --bg: var(--forest);
  --bg-2: var(--forest-2);
  --scene-ground: var(--forest-3);
  --scene-sky: var(--sky);
  --panel: var(--parchment);
  --panel-2: var(--parchment-2);
  --panel-edge: var(--parchment-edge);
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --accent: var(--gold);
  --accent-bright: var(--gold-bright);
  --accent-deep: var(--gold-deep);
  --chrome: var(--stone-dark);
  --chrome-text: var(--parchment);

  --font-head: 'Cinzel', 'Trajan Pro', Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --radius: 14px;
  --tap: 52px;
  --gap: 10px;
  --shadow: 0 3px 0 rgba(0,0,0,.25);
}

.theme-lair {
  --bg: #1a0707;
  --bg-2: #3a0d0b;
  --scene-ground: #2b0f0c;
  --scene-sky: #5c1410;
  --panel-edge: #7a1f17;
  --accent: #d9542b;
  --accent-bright: #ff9a4a;
  --accent-deep: #6d1b10;
  --chrome: #120404;
  --chrome-text: #f7d9c4;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--forest);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

#app {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  transition: background-color .6s;
}

[hidden] { display: none !important; }

h1, h2, h3, .head { font-family: var(--font-head); font-weight: 700; letter-spacing: .02em; }

button {
  font: inherit;
  color: inherit;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  overflow: hidden;
}

.scroll-y {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ---------- buttons ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  min-width: 48px;
  padding: 10px 18px;
  border: 3px solid var(--accent-deep);
  border-radius: var(--radius);
  background: linear-gradient(var(--accent-bright), var(--accent));
  color: var(--ink);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn[disabled] { filter: grayscale(.8) brightness(.9); opacity: .6; cursor: default; }
.btn.secondary { background: var(--panel); border-color: var(--panel-edge); }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.35); color: var(--chrome-text); box-shadow: none; }
.btn.wide { width: 100%; }
.btn.big { min-height: 60px; font-size: 21px; }
.icon-btn {
  width: 52px; height: 52px; min-width: 52px;
  display: grid; place-items: center;
  border-radius: 14px; border: 2px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25); color: var(--chrome-text);
  font-size: 24px; cursor: pointer;
}
.icon-btn svg { width: 26px; height: 26px; }

:focus-visible { outline: 3px solid var(--accent-bright); outline-offset: 2px; }

/* ---------- panels ---------- */
.parchment {
  background: var(--panel);
  color: var(--text);
  border: 3px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35), 0 4px 0 rgba(0,0,0,.25);
}

/* ---------- title ---------- */
#screen-title {
  align-items: center;
  justify-content: space-between;
  justify-content: safe space-between;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background:
    radial-gradient(ellipse at 50% 120%, var(--forest-3) 0 40%, transparent 41%),
    linear-gradient(var(--sky) 0 46%, var(--forest-2) 46% 100%);
}
.title-top { padding-top: 6vh; text-align: center; }
.title-logo {
  margin: 0;
  font-size: clamp(38px, 12vw, 56px);
  color: var(--gold-bright);
  text-shadow: 0 3px 0 var(--gold-deep), 0 6px 0 rgba(0,0,0,.35);
  -webkit-text-stroke: 1px var(--gold-deep);
}
.title-sub { margin: 6px 0 0; font-family: var(--font-head); color: var(--forest); font-size: 15px; letter-spacing: .12em; }
.title-hero { width: min(62vw, 260px); flex: 0 0 auto; }
.title-hero svg { width: 100%; height: auto; display: block; }
.title-actions { width: 100%; max-width: 420px; padding: 0 20px 24px; display: grid; gap: 12px; }
.version-tag { margin: 10px 0 0; text-align: center; font-size: 18px; font-weight: 700; letter-spacing: .02em; color: var(--forest); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--chrome);
  color: var(--chrome-text);
  border-bottom: 3px solid var(--accent-deep);
  flex: 0 0 auto;
}
.topbar .who { flex: 1; min-width: 0; line-height: 1.15; }
.topbar .who b { font-family: var(--font-head); display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .who small { opacity: .8; font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 999px; background: rgba(0,0,0,.3); font-size: 14px; font-weight: 700; }
.pill svg { width: 18px; height: 18px; }

/* ---------- map: themed lands, scrolled, a few fights then a stage boss ---------- */
#screen-map { background: var(--forest); padding-bottom: 0; }
.world { flex: 1; min-height: 0; padding: 8px 0 12px; }
.land {
  position: relative; overflow: hidden;
  margin: 8px 12px; padding: 12px 12px 14px; border-radius: 18px;
  border: 3px solid rgba(0,0,0,.35);
}
.land-head, .land-nodes { position: relative; z-index: 1; }
.land-sky { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.land-sky i {
  position: absolute; bottom: 8px; width: 4px; height: 4px; border-radius: 50%;
  background: #efe2c4; opacity: .7;
  animation: dust-drift 3.6s linear infinite;
}
.land.theme-greenwood .land-sky i {
  background: #8fd48a; box-shadow: 0 0 6px #d7f0c8; border-radius: 0 8px 0 8px;
  animation-name: ember-rise;
}
.land.theme-hunt .land-sky i {
  background: #f4e4c1; box-shadow: 0 0 6px #fff2a8;
  animation-name: ember-rise;
}
.land.theme-lake .land-sky i {
  background: #d7f4ff; box-shadow: 0 0 6px #fff; border-radius: 50%;
  animation-name: ember-rise;
}
.land.theme-frost .land-sky i {
  width: 3px; height: 3px; background: #fff; box-shadow: 0 0 4px #fff; border-radius: 50%;
  animation-name: snow-fall;
}
.land.theme-crown .land-sky i {
  background: #ffe680; box-shadow: 0 0 8px #e2b52c; border-radius: 50%;
  animation-name: ember-rise;
}
.land-head h2 { margin: 0; font-size: 22px; color: #fff; text-shadow: 0 2px 0 #000; }
.land-head p { margin: 4px 0 12px; color: #fff; font-size: 15px; line-height: 1.35; text-shadow: 0 1px 2px #000; }
.land-nodes { display: flex; flex-wrap: wrap; gap: 12px 8px; }
.land.theme-road { background: linear-gradient(#3e8f48, #1e5228); }
.land.theme-greenwood { background: linear-gradient(#146b38, #0c3320); }
.land.theme-hunt { background: linear-gradient(#6a4a22, #2e2416); }
.land.theme-lake { background: linear-gradient(#2a7494, #143848); }
.land.theme-frost { background: linear-gradient(#8aa4b4, #3c4e5c); }
.land.theme-crown { background: linear-gradient(#6a3058, #241028); }
.land.locked { filter: saturate(.45) brightness(.85); }
.land.cleared { box-shadow: inset 0 0 0 2px rgba(242,207,91,.7); }
.map-node {
  position: relative;
  width: 84px;
  min-width: 56px; min-height: 56px;
  padding: 0;
  border: 0;
  background: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer;
}
.map-node .disc {
  width: 56px; height: 56px; border-radius: 16px;
  display: grid; place-items: center;
  background: var(--parchment); border: 4px solid var(--gold-deep);
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
}
.map-node .disc svg { width: 40px; height: 40px; }
.map-node.done .disc { background: var(--gold-bright); }
.map-node.boss .disc { border-width: 5px; box-shadow: 0 0 0 3px rgba(242,207,91,.45), 0 4px 0 rgba(0,0,0,.35); }
.map-node.locked { cursor: default; }
.map-node.locked .disc { background: var(--stone-2); border-color: var(--stone-dark); filter: saturate(.3); }
.map-node.next .disc { animation: pulse 1.6s ease-in-out infinite; }
.map-node .lbl {
  font-family: var(--font-head); font-size: 12px; color: var(--white);
  text-shadow: 0 1px 2px #000, 0 0 4px #000; text-align: center; line-height: 1.15;
  max-width: 84px;
}
.map-you { position: absolute; top: -8px; right: 0; width: 26px; pointer-events: none; }
.map-you svg { width: 100%; height: auto; display: block; }
.map-foot { padding: 10px 12px calc(10px + var(--safe-b)); background: var(--chrome); color: var(--chrome-text); font-size: 15px; text-align: center; }

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* ---------- settings / stats ---------- */
.page-body { flex: 1; padding: 14px 14px calc(20px + var(--safe-b)); display: grid; gap: 14px; align-content: start; }
#screen-settings, #screen-stats { padding-bottom: 0; }
.card { padding: 14px; }
.card h2 { margin: 0 0 10px; font-size: 19px; }
.card p { margin: 0 0 10px; line-height: 1.45; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg button {
  min-height: var(--tap); border-radius: 12px; border: 3px solid var(--panel-edge);
  background: var(--white); font-weight: 700; font-size: 16px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--gold-bright); border-color: var(--gold-deep); }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.field { width: 100%; min-height: var(--tap); padding: 10px 12px; font-size: 17px; border: 3px solid var(--panel-edge); border-radius: 12px; background: var(--white); color: var(--ink); font-family: var(--font-body); }
textarea.field { min-height: 96px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; }
textarea.paper-mark {
  min-height: 0; resize: none; overflow: hidden;
  font-size: 20px; font-weight: 700; letter-spacing: 0.04em;
  text-align: center; line-height: 1.45; word-break: keep-all;
}
.muted { color: var(--text-soft); font-size: 14px; }
.notice { padding: 12px; border-radius: 12px; background: #fff3cd; border: 2px solid #c9a227; line-height: 1.4; }

/* ---------- overlay (Merlin, scrolls, rank-up) ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 50;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: calc(16px + var(--safe-t)) calc(14px + var(--safe-r)) calc(16px + var(--safe-b)) calc(14px + var(--safe-l));
  background: rgba(10, 12, 20, .72);
  animation: fadein .25s ease-out;
}
.overlay.full { justify-content: center; background: radial-gradient(circle at 50% 35%, #3b2f6b, #0e0b1c 70%); }
.overlay .speech { position: relative; z-index: 1; padding: 16px; font-size: 18px; line-height: 1.5; }
.overlay .speech h2 { margin: 0 0 8px; font-size: 22px; }
.overlay .speech p { margin: 0 0 12px; }
.overlay .actions { display: grid; gap: 10px; margin-top: 12px; }
.overlay .figure { width: 150px; margin: 0 auto -6px; position: relative; z-index: 1; }
.overlay .figure svg { width: 100%; height: auto; display: block; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.flash { position: absolute; inset: 0; z-index: 90; background: #fff; opacity: 0; pointer-events: none; }
.flash.on { opacity: .85; }
.noscript { color: #fff; padding: 20px; }

.confetti { position: absolute; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -16px; border-radius: 2px; animation: confetti-fall 1.15s ease-in forwards; }
@keyframes confetti-fall { to { transform: translateY(105vh) rotate(180deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .map-node.next .disc { animation: none; }
  .confetti { display: none; }
  .land-sky { display: none; }
}

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.swatch {
  width: 48px; height: 48px; min-width: 48px; min-height: 48px; padding: 0;
  border-radius: 14px; border: 3px solid rgba(0,0,0,.25); cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--gold-bright); }
.knight-preview { width: 120px; margin: 0 auto 8px; }
.knight-preview svg { width: 100%; height: auto; display: block; }
.screen-foot {
  flex: 0 0 auto; padding: 8px 12px calc(8px + var(--safe-b));
  background: var(--chrome); border-top: 3px solid var(--accent-deep);
}
.page-body.has-foot { padding-bottom: 14px; }
.screen-foot .btn { width: 100%; }
.field-label { display: block; font-weight: 700; margin: 4px 0 6px; }
.foe-row { display: grid; gap: 6px; }
.foe-row span { font-weight: 700; }

.btn.ghost.dark { color: var(--ink); border-color: var(--panel-edge); }

/* ---------- stats ---------- */
.stats-hero { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stats-hero .muted { grid-column: 1 / -1; margin: 0; }
.big-stat { display: grid; gap: 2px; }
.big-stat .n { font: 700 34px/1 var(--font-head); color: var(--accent-deep); }
.big-stat .l { font-weight: 700; }
.big-stat small { color: var(--text-soft); line-height: 1.3; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.stats-table th, .stats-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--panel-edge); }
.stats-table td small { color: var(--text-soft); }
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.badge-col { display: grid; gap: 4px; align-content: start; }
.badge-col b { font-size: 14px; }
.badge-col small { color: var(--text-soft); font-size: 12px; line-height: 1.25; }
.tiers { display: flex; gap: 4px; }
.tier { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 700; border: 2px solid rgba(0,0,0,.2); opacity: .35; }
.tier.bronze { background: #c98b4a; } .tier.silver { background: #c9d1d8; } .tier.gold { background: #f2cf5b; }
.tier.on { opacity: 1; box-shadow: 0 0 0 2px var(--ink); }
.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 15px; }
.recent li { display: grid; grid-template-columns: 14px 1fr; column-gap: 8px; }
.recent li small { grid-column: 2; color: var(--text-soft); }
.recent .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; }
.dot.first { background: var(--hp-good); } .dot.second { background: var(--gold); } .dot.miss { background: var(--hp-low); }

/* ---------- rewards ---------- */
.badge-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; }
.badge-list li { padding: 10px 12px; border-radius: 12px; font-weight: 700; font-family: var(--font-head); border: 3px solid rgba(0,0,0,.2); }
.badge-list .tier-bronze { background: #e3b27c; } .badge-list .tier-silver { background: #dfe5ea; } .badge-list .tier-gold { background: #f7dc7a; }
.overlay.rankup .speech { text-align: center; }
.overlay.rankup h2 { font-size: 28px; color: var(--accent-deep); }
.rank-knight { width: 110px; margin: 4px auto 0; }
.rank-knight svg { width: 100%; height: auto; display: block; }
.overlay.deeds .speech { max-height: 100%; overflow-y: auto; }
.deeds-who { font-family: var(--font-head); font-weight: 700; font-size: 19px; text-align: center; }
.deeds-list { margin: 0 0 12px; padding-left: 20px; }
.deeds-list li { margin: 2px 0; }
.overlay .speech .field { margin: 6px 0 10px; }
