:root {
  --parch: #f6ecd6;
  --parch-2: #efe0bf;
  --card: #fffaf0;
  --line: #dcc69c;
  --ink: #3a2a1a;
  --ink-soft: #6b5640;
  --red: #a3342f;
  --red-dark: #6e1f1b;
  --gold: #d9a632;
  --gold-soft: #f6dc8f;
  --green: #3f7d3a;
  --heart: #d63a3a;
  --shadow: 0 2px 0 rgba(58, 42, 26, 0.12), 0 6px 18px rgba(58, 42, 26, 0.10);
  --radius: 16px;
  --title-font: 'Cinzel Decorative', 'Papyrus', Georgia, serif;
  --body-font: 'Nunito', ui-rounded, 'Avenir Next', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  font-family: var(--body-font);
  color: var(--ink);
  background: var(--parch);
  background-image: radial-gradient(circle at 20% 0%, #fbf4e3 0, transparent 50%), radial-gradient(circle at 100% 100%, #ead8b2 0, transparent 45%);
  min-height: 100vh;
  font-size: 17px;
  line-height: 1.45;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, .place:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.muted { color: var(--ink-soft); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--red); color: #fff7e6;
  border-bottom: 4px solid var(--red-dark);
}
.logo { font-family: var(--title-font); font-weight: 900; font-size: 1.25rem; letter-spacing: 0.5px; }
.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.back-link {
  color: #fff7e6; text-decoration: none; font-weight: 800; font-size: 0.9rem;
  border: 2px solid rgba(255, 247, 230, 0.6); border-radius: 999px; padding: 4px 12px;
}
.back-link:hover { background: rgba(0, 0, 0, 0.15); }
.toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.toggle {
  border: 2px solid rgba(255, 247, 230, 0.6); background: transparent; color: #fff7e6;
  border-radius: 999px; padding: 5px 12px; font-weight: 700; font-size: 0.9rem;
}
.toggle[aria-pressed="true"] { background: var(--gold-soft); color: var(--ink); border-color: var(--gold-soft); }
.toggle.plain { border-style: dashed; }

main { max-width: 1240px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card h2 { font-family: var(--title-font); margin: 0 0 4px; font-size: 1.35rem; }

.big-btn {
  background: var(--red); color: #fff7e6; border: none; border-bottom: 4px solid var(--red-dark);
  border-radius: 14px; padding: 14px 26px; font-size: 1.15rem; font-weight: 800;
  transition: transform 0.1s;
}
.big-btn:hover:not(:disabled) { transform: translateY(-1px); }
.big-btn:active:not(:disabled) { transform: translateY(2px); border-bottom-width: 2px; }
.big-btn:disabled { background: #b9a88a; border-bottom-color: #8f805f; cursor: not-allowed; }
.big-btn.secondary { background: var(--ink-soft); border-bottom-color: var(--ink); }

/* ---------- start screen ---------- */
.hero-banner { text-align: center; padding: 12px 0 18px; }
.hero-banner h1 { font-family: var(--title-font); font-size: clamp(2rem, 6vw, 3.4rem); margin: 0; color: var(--red); text-shadow: 0 3px 0 var(--gold-soft); }
.subtitle { margin: 4px 0 0; font-size: 1.2rem; color: var(--ink-soft); font-style: italic; }
.credit { margin: 6px 0 0; font-weight: 800; color: var(--red); }

.continue { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: #fff4d6; }

.hero-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-top: 12px; align-items: start; }
.hero-card {
  border: 3px solid var(--line); border-radius: var(--radius); background: #fff; padding: 10px;
  display: flex; flex-direction: column; gap: 8px; transition: border-color 0.15s, background 0.15s;
}
.hero-card.selected { border-color: var(--hero); background: color-mix(in srgb, var(--hero) 9%, white); }
.hero-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: none; padding: 6px; }
.hero-name { font-weight: 800; font-size: 1.25rem; }
.hero-home { font-size: 0.85rem; color: var(--ink-soft); }
.hero-card:not(.selected) .class-pick, .hero-card:not(.selected) .class-desc { display: none; }
.class-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.class-btn {
  display: flex; flex-direction: column; align-items: center; padding: 6px 2px; font-size: 0.8rem; font-weight: 700;
  border: 2px solid var(--line); border-radius: 10px; background: var(--card);
}
.class-btn[aria-pressed="true"] { border-color: var(--hero); background: var(--hero); color: white; }
.class-icon { font-size: 1.4rem; }
.class-desc { font-size: 0.8rem; color: var(--ink-soft); display: grid; gap: 3px; line-height: 1.3; }
.class-desc .cd-main { text-align: center; font-weight: 700; color: var(--ink); }
.class-desc b { color: var(--ink); }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 10px; }
.cat-pick {
  display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px 14px;
  border: 3px solid var(--line); border-radius: var(--radius); background: #fff;
}
.cat-pick[aria-pressed="true"] { border-color: var(--green); background: #eef6e6; }
.cat-text { display: flex; flex-direction: column; }
.cat-text small { color: var(--ink-soft); }
.begin-row { text-align: center; padding: 6px 0 30px; }

/* ---------- art & avatars ---------- */
.art { display: inline-flex; align-items: center; justify-content: center; flex: none; overflow: hidden; }
.art img { width: 100%; height: 100%; object-fit: cover; }
.art-fallback { line-height: 1; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--parch-2); font-size: 1.5rem; }
.avatar.big { width: 72px; height: 72px; font-size: 2.6rem; }
.avatar.small { width: 30px; height: 30px; font-size: 1.1rem; }
.avatar-letter { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: white; font-weight: 800; font-size: 0.55em; }
.avatar.big .avatar-letter { font-size: 2rem; }
.avatar .avatar-letter { font-size: 1.15rem; }
.avatar.small .avatar-letter { font-size: 0.9rem; }

/* ---------- game layout ---------- */
.game { display: grid; grid-template-columns: minmax(300px, 410px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 880px) {
  .game { grid-template-columns: 1fr; }
  .col-right { order: -1; } /* story and buttons first on small screens */
}

.map-card { padding: 8px; }
.map-svg { width: 100%; height: auto; display: block; }
.map-bg { fill: var(--parch-2); }
.forest { fill: #bcd59d; }
.tree { font-size: 16px; text-anchor: middle; opacity: 0.8; }
.road-base { fill: none; stroke: #dcc394; stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.road-line { fill: none; stroke: #a48153; stroke-width: 2; stroke-dasharray: 6 6; stroke-linecap: round; stroke-linejoin: round; }
.river { fill: #5aa9e6; }
.river-name { font-family: var(--title-font); font-size: 13px; font-weight: 700; fill: #ffffff; }
.river-real { font-size: 9px; fill: #e5f3ff; font-style: italic; }
.kingdom { font-family: var(--title-font); font-size: 17px; font-weight: 900; fill: #b49a6c; text-anchor: middle; }
.kingdom-sub { font-family: var(--title-font); font-size: 10px; fill: #b49a6c; text-anchor: middle; }
.compass { font-size: 24px; text-anchor: middle; }

.place { cursor: default; }
.place .ring { fill: none; stroke: transparent; stroke-width: 3; }
.place .disc { fill: var(--card); stroke: #a48153; stroke-width: 2; }
.place .p-icon { font-size: 26px; text-anchor: middle; dominant-baseline: central; }
.place .p-name, .place .p-real { text-anchor: middle; paint-order: stroke; stroke: var(--parch-2); stroke-width: 4px; stroke-linejoin: round; }
.place .p-name { font-size: 12.5px; font-weight: 800; fill: var(--ink); }
.place .p-real { font-size: 9.5px; font-style: italic; fill: var(--ink-soft); }
.place.reachable { cursor: pointer; }
.place.reachable .ring { stroke: var(--gold); stroke-dasharray: 5 4; animation: spin 8s linear infinite; transform-box: fill-box; transform-origin: center; }
.place.reachable:hover .disc { fill: var(--gold-soft); }
.place.locked { cursor: pointer; }
.place.locked .disc { fill: #e7dccb; stroke-dasharray: 3 3; }
.place.here .disc { fill: var(--gold-soft); stroke: var(--red); stroke-width: 3; }
#token { transition: transform 0.8s cubic-bezier(.5, -0.3, .4, 1.4); pointer-events: none; }
.token-flag { font-size: 22px; text-anchor: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.panel-title { font-family: var(--title-font); margin: 0 0 8px; font-size: 1.05rem; }
.panel-title:not(:first-child) { margin-top: 14px; }
.party { display: grid; gap: 8px; }
.member {
  display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 12px;
  border: 2px solid transparent; background: #fff;
}
.member.is-turn { border-color: var(--hero, var(--gold)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hero, var(--gold)) 25%, transparent); }
.member.ko { filter: grayscale(1); opacity: 0.6; }
.member.cat { background: #f3f8ec; }
.member.cat.used { opacity: 0.6; }
.member-name { font-weight: 800; }
.member-class { font-size: 0.85rem; color: var(--ink-soft); }
.hearts { font-size: 15px; letter-spacing: 1px; line-height: 1; }
.hearts .full { color: var(--heart); }
.hearts .empty { color: var(--line); }
.inventory { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--parch); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 0.9rem; font-weight: 600; }

.place-header { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.place-header h2 { font-size: 1.6rem; margin: 0; }
.place-header .real { color: var(--ink-soft); font-style: italic; font-size: 0.9rem; }
.place-art { width: 64px; height: 64px; border-radius: 14px; background: var(--parch-2); font-size: 2.4rem; border: 2px solid var(--line); }

.quest { background: #fff6dc; border: 2px dashed var(--gold); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; }
.quest-title { font-weight: 800; display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--ink-soft); }
.quest-next { font-weight: 700; font-size: 1.05rem; }
.quest-dots { display: flex; gap: 5px; margin-top: 4px; }
.quest-dots .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.quest-dots .dot.done { background: var(--green); }

.combat { background: #fbe9e4; border: 2px solid #e2b5aa; border-radius: 12px; padding: 10px; margin-bottom: 12px; }
.round { font-weight: 800; color: var(--red); margin-bottom: 6px; }
.monsters { display: flex; flex-wrap: wrap; gap: 10px; }
.monster { width: 128px; text-align: center; background: #fff; border-radius: 12px; padding: 8px; border: 2px solid #e2b5aa; }
.monster.down { opacity: 0.4; filter: grayscale(1); }
.monster-art { width: 56px; height: 56px; font-size: 2.6rem; }
.monster-name { font-weight: 800; font-size: 0.9rem; line-height: 1.2; }
.bar { height: 8px; background: #eedcd5; border-radius: 99px; overflow: hidden; margin: 5px 0 2px; }
.bar span { display: block; height: 100%; background: var(--heart); transition: width 0.4s; }
.monster-hearts { font-size: 0.8rem; color: var(--ink-soft); }

.story {
  position: relative; max-height: 44vh; min-height: 140px; overflow-y: auto;
  padding: 4px 6px 4px 2px; margin-bottom: 10px; scroll-behavior: smooth;
}
.story hr { border: none; border-top: 1px dashed var(--line); margin: 10px 0; }
.para { margin: 0 0 8px; font-size: 1.15rem; line-height: 1.55; display: flex; gap: 8px; align-items: flex-start; color: var(--ink-soft); }
.para > span { flex: 1; }
.para.fresh { color: var(--ink); border-left: 4px solid var(--gold); padding-left: 10px; animation: fadein 0.5s ease both; }
.para.fresh:nth-child(2) { animation-delay: 0.1s; }
.speak { background: none; border: none; font-size: 0.95rem; opacity: 0.45; padding: 2px; }
.speak:hover { opacity: 1; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.thinking { font-style: italic; color: var(--ink-soft); margin-bottom: 8px; }
.turn { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; margin: 6px 0 10px; color: var(--hero, var(--ink)); }

.action-group h3 { margin: 10px 0 6px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-soft); }
.action-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.action {
  display: flex; align-items: center; gap: 10px; text-align: left; min-height: 56px;
  background: #fff; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 14px; padding: 8px 12px;
  transition: transform 0.1s, border-color 0.15s;
}
.action:hover:not(:disabled) { border-color: var(--gold); transform: translateY(-1px); }
.action:active:not(:disabled) { transform: translateY(2px); }
.action.special { background: #fff8e1; }
.action.locked { background: #f1ebe0; color: var(--ink-soft); }
.actions.busy .action { opacity: 0.55; cursor: wait; }
.a-icon { font-size: 1.6rem; width: 34px; text-align: center; flex: none; }
.a-text { display: flex; flex-direction: column; }
.a-label { font-weight: 800; }
.a-sub { font-size: 0.8rem; color: var(--ink-soft); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(40, 25, 10, 0.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.dialog { background: var(--card); border: 3px solid var(--gold); border-radius: 22px; padding: 22px; width: min(440px, 100%); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.dice-who { font-family: var(--title-font); font-size: 1.3rem; font-weight: 900; }
.dice-need { color: var(--ink-soft); margin: 4px 0 10px; }
.die { position: relative; width: 170px; height: 170px; border: none; background: none; padding: 0; margin: 4px auto; display: block; }
.die svg { width: 100%; height: 100%; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.25)); }
.die-face { fill: var(--red); stroke: var(--red-dark); stroke-width: 2; stroke-linejoin: round; transition: fill 0.3s; }
.die-inner { fill: #c0463f; stroke: var(--red-dark); stroke-width: 1.5; transition: fill 0.3s; }
.die-lines { fill: none; stroke: var(--red-dark); stroke-width: 1.5; }
.die-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding-top: 16px; color: #fff; font-weight: 900; font-size: 2.6rem; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); pointer-events: none; }
.die.rolling { animation: tumble 0.85s ease-out; }
.die.win .die-face { fill: var(--green); }
.die.win .die-inner { fill: #57a050; }
.die.lose .die-face { fill: #8c7f73; }
.die.lose .die-inner { fill: #a39587; }
@keyframes tumble {
  0% { transform: rotate(0) scale(1); }
  30% { transform: rotate(240deg) scale(1.15) translateY(-14px); }
  60% { transform: rotate(520deg) scale(0.95); }
  100% { transform: rotate(720deg) scale(1); }
}
.dice-hint { font-weight: 700; min-height: 1.4em; margin-bottom: 6px; }
.dice-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 8px; }
.dice-grid button { padding: 10px 0; font-weight: 800; font-size: 1.1rem; border-radius: 10px; border: 2px solid var(--line); background: #fff; }
.dice-grid button:hover { border-color: var(--gold); }
.dice-result { font-size: 1.15rem; margin: 6px 0 12px; }
.verdict { font-size: 1.5rem; font-weight: 900; margin-top: 4px; }
.verdict.yes { color: var(--green); }
.verdict.no { color: var(--red); }

.victory h2 { font-family: var(--title-font); color: var(--red); font-size: 1.8rem; margin: 6px 0; }
.confetti { font-size: 2.2rem; animation: bounce 1s ease-in-out infinite alternate; }
@keyframes bounce { to { transform: translateY(-8px) scale(1.05); } }
.victory-heroes { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 12px 0 18px; }
.v-hero { display: flex; flex-direction: column; align-items: center; font-weight: 800; }
.v-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: #fff7e6; padding: 10px 18px; border-radius: 999px; font-weight: 700;
  max-width: calc(100% - 32px); text-align: center; box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- classes, powers, gear ---------- */
.hearts-row { display: flex; align-items: center; gap: 4px; }
.shield { font-size: 0.8rem; font-weight: 800; color: #8a5a2b; }
.member-power { font-size: 0.8rem; color: var(--ink-soft); }
.member-power.ready { color: var(--green); font-weight: 800; }
.member-gear { display: flex; gap: 3px; font-size: 1rem; margin-top: 2px; }
.gear { cursor: help; }
.chip.gold { background: #fff3c4; border-color: var(--gold); font-weight: 800; }
.chip.luck { background: #e6f5df; border-color: var(--green); }
.chip.trinket { background: #f3ecff; border-color: #cdb8f0; }
.chip.quest { background: #ffe9e4; border-color: #e2b5aa; }

.tags { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; margin-top: 4px; }
.tag { font-size: 0.72rem; font-weight: 800; border-radius: 999px; padding: 1px 6px; cursor: help; }
.tag.weak { background: #ffe1d6; color: #a3342f; }
.tag.tough { background: #e4e4ea; color: #4b4b5a; }
.tag.fly { background: #e2f0fb; color: #1f5f8f; }
.monster-note { font-size: 0.85rem; color: var(--ink-soft); margin-top: 8px; }
.courage { color: var(--green); font-weight: 800; }

.combat.is-event { background: #fff6dc; border-color: var(--gold); }
.event-banner { display: flex; gap: 12px; align-items: center; }
.event-icon { font-size: 2.4rem; }
.event-title { font-family: var(--title-font); font-weight: 900; font-size: 1.2rem; }

.action.talent { background: #fff3c4; border-color: var(--gold); }
.action.target { background: #fff; }
.action.cancel { background: var(--parch); }
.picker h3 { text-transform: none; letter-spacing: 0; font-size: 1rem; color: var(--ink); }

.difficulty { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 10px; }
.diff-pick {
  display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px 14px;
  border: 3px solid var(--line); border-radius: var(--radius); background: #fff;
}
.diff-pick[aria-pressed="true"] { border-color: var(--red); background: #fdecea; }
.diff-icon { font-size: 1.8rem; }

/* ---------- voices menu ---------- */
.dialog.voices { width: min(560px, 100%); text-align: left; }
.dialog.voices h2 { font-family: var(--title-font); margin: 0 0 4px; }
.voice-list { display: grid; gap: 10px; margin: 12px 0; }
.voice-row { display: grid; grid-template-columns: 1fr; gap: 4px; }
.voice-who { font-weight: 800; }
.voice-row select { font: inherit; padding: 6px 8px; border-radius: 10px; border: 2px solid var(--line); background: #fff; width: 100%; }
.voice-test { justify-self: start; border: 2px solid var(--line); background: var(--parch); border-radius: 999px; padding: 3px 12px; font-weight: 700; }
.voice-rate { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 12px; }
.voice-rate input { flex: 1; }
.voice-tip { background: #fff6dc; border: 2px dashed var(--gold); border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; margin-bottom: 14px; }
@media (min-width: 560px) { .voice-row { grid-template-columns: 170px 1fr auto; align-items: center; } }
