@font-face {
  font-family: Cinzel;
  src: url("../fonts/Cinzel-Regular.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("../fonts/NotoSansThai-Regular.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0E00-0E7F, U+200B-200D, U+25CC;
}

:root {
  --oak: #1a120c;
  --oak-2: #241810;
  --oak-3: #2e2014;
  --ink: #0b0906;
  --metal: #1c1a16;
  --brass: #c9a44c;
  --brass-2: #e0c36a;
  --brass-dim: #8a6d2f;
  --ivory: #e8dcc4;
  --ivory-dim: #cbbd9e;
  --sun: #d4893a;
  --sun-2: #f0c070;
  --hp: #c23b3b;
  --hp-bg: #3a1414;
  --mp: #4a7ab0;
  --mp-bg: #142033;
  --sp: #4a9a6a;
  --sp-bg: #14331c;
  --danger: #8b2a2a;
  --restored: #6a9a4a;
  --shadow: #6b7c8a;
  --panel: rgba(18, 12, 8, 0.88);
  --panel-2: rgba(28, 20, 12, 0.92);
  --radius: 4px;
  --gold-edge: linear-gradient(180deg, #e0c36a, #8a6d2f);
  --font-display: Cinzel, "Noto Sans Thai", "Noto Sans", Palatino, "Times New Roman", "DejaVu Serif", "WenQuanYi Zen Hei", "Unifont JP", serif;
  --font-body: "Noto Sans Thai", "Noto Sans", Palatino, Georgia, "Times New Roman", "DejaVu Sans", "FreeSans", "WenQuanYi Zen Hei", "Unifont JP", sans-serif;
}

[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--ivory);
  font-family: var(--font-body);
  overflow: hidden;
}
button, [role="button"] { font-family: inherit; }
button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; }
img { display: block; max-width: 100%; }

.game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  background: var(--ink);
  display: flex;
  flex-direction: column;
}
.screen {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* ---------- shared chrome ---------- */
.gold-panel {
  background: var(--panel);
  border: 1px solid var(--brass-dim);
  box-shadow:
    inset 0 0 0 1px rgba(201, 164, 76, 0.18),
    0 8px 28px rgba(0, 0, 0, 0.55);
  position: relative;
}
.gold-panel::before {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(201, 164, 76, 0.22);
}
.banner {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brass-2);
  text-shadow: 0 1px 0 #000, 0 0 12px rgba(201, 164, 76, 0.25);
}
.btn {
  appearance: none;
  background: linear-gradient(180deg, #3a2a16 0%, #1c140c 100%);
  color: var(--ivory);
  border: 1px solid var(--brass);
  padding: 0.7rem 1.2rem;
  min-height: 44px;
  font-family: var(--font-display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.85rem;
  box-shadow: inset 0 1px 0 rgba(224, 195, 106, 0.25);
}
.btn:hover, .btn:focus-visible {
  outline: 2px solid var(--brass-2);
  outline-offset: 2px;
  color: #fff8e6;
  border-color: var(--brass-2);
}
.btn.primary {
  background: linear-gradient(180deg, #7a5a20 0%, #3a2a10 100%);
  color: #fff4d4;
}
.btn.ghost {
  background: rgba(12, 8, 6, 0.55);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.small-btn { min-width: 44px; min-height: 44px; padding: 0.45rem 0.7rem; }

.bar {
  height: 8px;
  background: #2a1610;
  border: 1px solid #000;
  overflow: hidden;
  display: flex;
}
.bar > i {
  display: block;
  height: 100%;
  width: var(--w, 50%);
  background: linear-gradient(180deg, #e25a5a, #8b2a2a);
}
.bar.mp > i { background: linear-gradient(180deg, #7aa8d8, #2a5080); }
.bar.sp > i { background: linear-gradient(180deg, #6ec48a, #2a6a40); }
.bar.xp > i { background: linear-gradient(180deg, #e0c36a, #8a6d2f); }

/* ---------- title ---------- */
.title-screen {
  position: absolute;
  inset: 0;
  background: #100c08 center/cover no-repeat;
}
.title-screen .veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(10, 8, 6, 0.45) 0%, rgba(10, 8, 6, 0.15) 35%, rgba(10, 8, 6, 0.2) 60%, rgba(10, 8, 6, 0.72) 100%);
}
.title-copy {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 4vh 1.2rem 22vh;
  text-align: center;
}
.presents {
  font-family: var(--font-display);
  font-size: clamp(0.7rem, 1.4vw, 0.95rem);
  letter-spacing: 0.32em;
  color: var(--brass-2);
  margin-bottom: 0.6rem;
}
.presents strong { display: block; letter-spacing: 0.22em; margin: 0.15rem 0; color: var(--ivory); }
.title-copy h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.8rem, 5.4vw, 4.4rem);
  line-height: 1.05;
  color: #f0d78a;
  text-shadow: 0 2px 0 #3a2a10, 0 8px 24px rgba(0, 0, 0, 0.65);
  margin: 0.2rem 0 1.2rem;
  max-width: 18ch;
}
.title-menu {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: min(360px, 86vw);
  margin-top: auto;
}
.title-menu .btn { width: 100%; }
.corner-note {
  position: absolute;
  bottom: 3.5rem;
  z-index: 2;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ivory-dim);
  max-width: 16ch;
}
.corner-note.left { left: 1.4rem; text-align: left; }
.corner-note.right { right: 1.4rem; text-align: right; }

/* ---------- party bar ---------- */
.party-bar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.35rem 0.5rem 0.4rem;
  background: linear-gradient(180deg, #120c08 0%, #0b0906 100%);
  border-top: 1px solid var(--brass-dim);
  flex: 0 0 auto;
  z-index: 5;
}
.party-card {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 0.35rem;
  padding: 0.28rem;
  background: linear-gradient(180deg, #2a1c12, #16100c);
  border: 1px solid #5a4320;
  min-height: 56px;
  position: relative;
  color: inherit;
  text-align: left;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
}
.party-card.front { transform: translateY(-8px); border-color: #8a6d2f; }
.party-card.rear { filter: saturate(0.92); opacity: 0.96; }
.party-card.active {
  border-color: var(--brass-2);
  box-shadow: 0 0 0 2px var(--brass), 0 8px 18px rgba(201, 164, 76, 0.4);
  transform: translateY(-12px);
  z-index: 2;
}
.party-card.down { filter: grayscale(0.75) brightness(0.75); }
.party-card.dead { filter: grayscale(1) brightness(0.55); }
.party-card.dead::after {
  content: "DEAD";
  position: absolute;
  inset: auto 0 2px;
  text-align: center;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  color: #c9b48a;
  font-family: var(--font-display);
}
.party-card img, .party-card .ph {
  width: 38px;
  height: 50px;
  object-fit: cover;
  object-position: top;
  background: #111;
}
.party-card .meta { min-width: 0; }
.party-card .name {
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ivory);
}
.party-card .cls {
  font-size: 0.58rem;
  color: var(--brass);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.party-card .hpnum { font-size: 0.58rem; color: var(--ivory-dim); margin: 0.1rem 0; }
.seat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--brass);
  background: #2a2010;
}

/* ---------- overworld ---------- */
.map-screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.map-art {
  flex: 1;
  position: relative;
  background: #1a120c center/cover no-repeat;
}
.map-art .restore-veil {
  position: absolute;
  pointer-events: none;
  inset: 0;
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 0.8s ease;
}
.node {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: 0;
  color: var(--ivory);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0;
}
.node .pip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--brass);
  background: #1a120c;
  box-shadow: 0 0 0 3px rgba(0,0,0,0.45);
}
.node.town .pip { border-radius: 3px; }
.node.dungeon .pip { border-radius: 2px 2px 10px 10px; }
.node.here .pip {
  background: var(--brass-2);
  box-shadow: 0 0 12px var(--sun);
}
.node.locked { opacity: 0.4; }
.node .label {
  font-family: var(--font-display);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: rgba(12,8,6,0.72);
  padding: 0.12rem 0.35rem;
  border: 1px solid rgba(201,164,76,0.35);
  white-space: nowrap;
}
.map-hud, .town-hud, .dun-hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  pointer-events: none;
  z-index: 3;
}
.map-hud > *, .town-hud > *, .dun-hud > * { pointer-events: auto; }
.hud-title {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brass-2);
  background: var(--panel);
  border: 1px solid var(--brass-dim);
  padding: 0.45rem 0.8rem;
}
.hud-stats {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.chip {
  background: var(--panel);
  border: 1px solid var(--brass-dim);
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--ivory);
}
.lang-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  margin-top: 0.8rem;
  max-height: 24vh;
  overflow: auto;
}
.lang-chip { cursor: pointer; font-family: var(--font-body); }
.lang-chip.on { border-color: var(--brass-2); color: var(--brass-2); }
html.lang-rtl body { text-align: right; }
html.lang-rtl .lang-row, html.lang-rtl .sheet, html.lang-rtl .log { direction: rtl; }

/* ---------- town ---------- */
.town-screen, .dungeon-screen, .combat-screen, .seat-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
}
.scene {
  flex: 1;
  position: relative;
  background: #100c08 center/cover no-repeat;
}
.hotspot {
  position: absolute;
  min-width: 44px;
  min-height: 44px;
  border: 1px dashed rgba(201,164,76,0.7);
  background: rgba(12,8,6,0.35);
  color: var(--ivory);
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.7rem;
  padding: 0.35rem 0.5rem;
}
.hotspot:hover, .hotspot:focus-visible {
  background: rgba(40, 28, 12, 0.7);
  border-color: var(--brass-2);
}
.dialogue {
  position: absolute;
  left: 8%; right: 8%; bottom: 8%;
  padding: 0.9rem 1.1rem;
  z-index: 4;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.town-talk {
  cursor: default;
  max-height: 42vh;
  overflow: auto;
}
.town-talk .person { margin-top: 0.65rem; padding-top: 0.45rem; border-top: 1px solid rgba(201,164,76,0.25); }
.town-talk .btn { margin: 0.28rem 0.35rem 0 0; }
.town-talk .bond-now { margin: 0.2rem 0; color: var(--brass-2); font-size: 0.82rem; }
.party-card.guest { outline: 1px dashed var(--brass-2); }
.gear-read { color: var(--brass-2); font-size: 0.82rem; }
.chronicle-line { margin-top: 0.45rem; color: var(--brass-2); font-size: 0.92rem; }
.code-box {
  width: 100%;
  min-height: 8rem;
  max-height: 28vh;
  background: #120e0a;
  color: var(--ivory);
  border: 1px solid var(--brass-dim);
  padding: 0.6rem;
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.35;
}
.dialogue .who {
  font-family: var(--font-display);
  color: var(--brass-2);
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  margin-bottom: 0.3rem;
}
.minimap {
  position: absolute;
  top: 3.6rem; right: 0.7rem;
  width: min(220px, 42vw);
  background: rgba(18,14,8,0.86);
  border: 1px solid var(--brass-dim);
  padding: 0.4rem;
  z-index: 3;
}
.minimap svg { width: 100%; height: auto; display: block; }
.exit-btn {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 3;
}

/* ---------- combat ---------- */
.battlefield {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #120c08 center/cover no-repeat;
}
.formation-banner {
  position: absolute;
  top: 0.7rem; right: 0.7rem;
  z-index: 3;
  padding: 0.45rem 0.7rem;
  text-align: center;
  min-width: 120px;
}
.formation-banner .st {
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  font-size: 0.85rem;
}
.pips { display: flex; gap: 0.25rem; justify-content: center; margin-top: 0.25rem; }
.pips b {
  width: 10px; height: 10px;
  background: var(--brass);
  transform: rotate(45deg);
  display: block;
}
.pips b.off { background: #3a3020; }
.enemy-row {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 1.2rem;
  pointer-events: none;
}
.enemy-row.back { top: 8%; height: 42%; }
.enemy-row.front { top: 38%; height: 50%; }
.enemy {
  pointer-events: auto;
  background: none;
  border: 2px solid transparent;
  color: var(--ivory);
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 22%;
}
.enemy img {
  height: 28vh;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  filter: drop-shadow(0 10px 10px rgba(0,0,0,0.6));
}
.enemy-row.back .enemy img { height: 22vh; max-width: 120px; opacity: 0.95; }
.enemy.legal { border-color: var(--brass-2); box-shadow: 0 0 0 2px rgba(201,164,76,0.35); }
.enemy.blocked { outline: 2px dashed #8a4a4a; }
.enemy .ename {
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  background: rgba(10,8,6,0.7);
  padding: 0.1rem 0.35rem;
}
.enemy .bar { width: 80px; margin-top: 0.15rem; }
.combat-ui {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem 0;
  background: linear-gradient(180deg, transparent, #0b0906 18%);
}
.cmd {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 42vh;
  overflow: auto;
}
.cmd .btn { text-align: left; }
.log {
  max-height: 7.5rem;
  overflow: auto;
  font-size: 0.82rem;
  padding: 0.45rem 0.6rem;
  color: var(--ivory-dim);
}
.log div { margin-bottom: 0.15rem; }

/* ---------- seat ---------- */
.seat-wrap {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: 1fr minmax(180px, 26%) 1fr;
  gap: 0.8rem;
  padding: 4.5rem 0.8rem 0.8rem;
  background:
    linear-gradient(180deg, rgba(10,8,6,0.55), rgba(10,8,6,0.35)),
    var(--bg, #120c08) center/cover no-repeat;
}
.seat-col { padding: 0.8rem; }
.seat-col h2 {
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  margin: 0 0 0.4rem;
  color: var(--brass-2);
  text-align: center;
}
.hero-pick {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}
.hero-pick button {
  border: 1px solid #5a4320;
  background: #1a120c;
  padding: 0.2rem;
  color: var(--ivory);
}
.hero-pick button.sel { border-color: var(--brass-2); box-shadow: 0 0 0 1px var(--brass); }
.hero-pick img { width: 100%; height: 70px; object-fit: cover; object-position: top; }
.seat-core { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.seat-core svg { width: min(240px, 70%); }
.restore-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
}
.restore-preview img { width: 100%; height: 90px; object-fit: cover; }

/* ---------- party select ---------- */
.select-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
  padding: 0.6rem;
  overflow: auto;
  height: 100%;
}
.pick-card {
  text-align: left;
  color: var(--ivory);
  padding: 0.4rem;
}
.pick-card img { width: 100%; height: 140px; object-fit: cover; object-position: top; }
.pick-card.on { border-color: var(--brass-2); box-shadow: 0 0 0 1px var(--brass); }

/* ---------- story ---------- */
.story {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  justify-content: flex-end;
  background: #100c08 center/cover no-repeat;
}
.story .panel {
  margin: 0 8% 8%;
  padding: 1.1rem 1.2rem;
  max-height: min(70vh, 560px);
  overflow: auto;
}
.story .who { color: var(--brass-2); font-family: var(--font-display); letter-spacing: 0.16em; font-size: 0.8rem; }

/* ---------- modal ---------- */
.modal {
  position: absolute; inset: 0;
  background: rgba(8, 6, 4, 0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
  padding: 1rem;
}
.modal .sheet {
  width: min(820px, 96vw);
  max-height: 90vh;
  overflow: auto;
  padding: 1rem 1.1rem;
}
.toast {
  position: absolute;
  top: 4.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(92vw, 36rem);
  text-align: center;
  padding: 0.5rem 0.9rem;
  font-family: var(--font-display);
  letter-spacing: 0.08em;
}
.fx { pointer-events: none; position: absolute; inset: 0; z-index: 15; }

.shop-list { display: flex; flex-direction: column; gap: 0.35rem; }
.shop-row {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.2rem;
  border-bottom: 1px solid rgba(201,164,76,0.15);
}

kbd {
  font-family: var(--font-display);
  font-size: 0.7rem;
  border: 1px solid var(--brass-dim);
  padding: 0.05rem 0.3rem;
}

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

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 820px) {
  .party-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .party-card.front { transform: none; }
  .party-card.active { transform: none; }
  .combat-ui { grid-template-columns: 1fr; }
  .cmd { display: grid; grid-template-columns: repeat(3, 1fr); }
  .seat-wrap { grid-template-columns: 1fr; overflow: auto; }
  .select-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .enemy img { height: 20vh; }
  .title-copy { padding-bottom: 18vh; }
  .minimap { width: min(160px, 46vw); }
}

@media (max-width: 430px) {
  .party-card { grid-template-columns: 36px 1fr; padding: 0.25rem; }
  .party-card img, .party-card .ph { width: 36px; height: 48px; }
  .hud-title { font-size: 0.7rem; padding: 0.35rem 0.5rem; }
  .title-copy h1 { font-size: 1.7rem; }
}

.enemy.down { opacity: 0.28; filter: grayscale(1); pointer-events: none; }


.tale-sub{font-family:Cinzel,'Noto Sans Thai',serif;letter-spacing:.16em;text-transform:uppercase;color:#e0c36a;font-size:.78rem;margin:0 0 .7rem;text-align:center}
