/* ============================================================
   勇者御一行、接客中 — polish pass
   Palette and type derived from assets/key-art.jpg:
   warm cream paper, mint accents, cocoa ink, burgundy + gold trim.
   ============================================================ */

:root {
  color-scheme: light;

  --bg: #FBF3E2;
  --bg-warm: #F7E8CC;
  --paper: #FFFCF5;
  --paper-2: #FFF7E8;

  --line: #E2C79E;
  --line-soft: #EFE1C7;

  --ink: #3B2920;
  --ink-soft: #5E4737;
  --muted: #866A52;

  --wine: #8A3546;
  --wine-light: #A95063;
  --wine-dark: #5E2130;

  --mint: #8ACBAE;
  --mint-light: #B9E4D0;
  --mint-dark: #3F7D66;

  --gold: #D7A64F;
  --gold-light: #F0D08F;
  --gold-dark: #9A6F28;

  --focus: #8A3546;

  --tile-floor: #FEF7E8;
  --tile-line: #DFC29A;
  --hero-hp-bg: rgba(59, 41, 32, 0.22);
  --hero-hp: #4FBE8C;

  --font-body: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "YuGothic",
    "Noto Sans JP", "Noto Sans CJK JP", "Meiryo", sans-serif;
  --font-display: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP",
    "Noto Serif CJK JP", "Hiragino Sans", "Noto Sans JP", serif;

  font-family: var(--font-body);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-block-size: 100dvb;
  background-color: var(--bg);
  background-image:
    radial-gradient(52rem 26rem at 50% -9rem, rgba(255, 255, 255, 0.95), transparent 62%),
    radial-gradient(46rem 34rem at 108% -6%, rgba(138, 203, 174, 0.22), transparent 58%),
    radial-gradient(44rem 32rem at -8% 104%, rgba(215, 166, 79, 0.18), transparent 60%),
    repeating-linear-gradient(135deg, rgba(120, 88, 52, 0.022) 0 1px, transparent 1px 26px),
    linear-gradient(180deg, var(--bg), var(--bg-warm));
  background-attachment: fixed;
  color: var(--ink);
  font-family: inherit;
  font-feature-settings: "palt" 1;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: rgba(138, 53, 70, 0.18);
  color: var(--ink);
}

button {
  font: inherit;
  color: inherit;
}

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

/* ---------- shared buttons ---------- */

.btn-primary,
.btn-secondary,
.btn-quiet,
.actions button,
dialog button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-block-size: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  line-height: 1.35;
  text-align: center;
  cursor: pointer;
  transition:
    filter 140ms ease-out,
    transform 100ms ease-out,
    box-shadow 140ms ease-out;
}

.btn-primary {
  color: #FFF6EC;
  border-color: var(--wine-dark);
  background: linear-gradient(180deg, #A95161, var(--wine) 58%, #712B3A);
  text-shadow: 0 1px 1px rgba(60, 15, 25, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.34),
    inset 0 0 0 1px rgba(240, 208, 143, 0.32),
    0 3px 0 var(--wine-dark),
    0 8px 16px rgba(110, 45, 55, 0.22);
}

.btn-secondary {
  color: #1C4A37;
  border-color: #3F7D66;
  background: linear-gradient(180deg, #BCE8D4, var(--mint) 56%, #6DB697);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 3px 0 #3F7D66,
    0 8px 16px rgba(63, 125, 102, 0.18);
}

.btn-quiet {
  color: var(--ink-soft);
  border-color: var(--line);
  background: linear-gradient(180deg, #FFFDF7, #FBF0DC);
  text-shadow: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 3px 0 #DFC8A2,
    0 6px 12px rgba(150, 110, 60, 0.12);
}

.btn-primary:hover:not(:disabled),
.btn-secondary:hover:not(:disabled),
.btn-quiet:hover:not(:disabled),
.actions button:hover:not(:disabled),
dialog button:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled),
.btn-secondary:active:not(:disabled),
.btn-quiet:active:not(:disabled),
.actions button:active:not(:disabled),
dialog button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 1px 0 currentColor;
}

.btn-primary:active:not(:disabled) {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 1px 0 var(--wine-dark);
}

.btn-secondary:active:not(:disabled) {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 1px 0 #3F7D66;
}

.btn-quiet:active:not(:disabled) {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 1px 0 #DFC8A2;
}

button:disabled,
.actions button:disabled {
  border-color: #E4D4BC !important;
  background: linear-gradient(180deg, #F6EDDD, #EFE3CE) !important;
  color: #AC9A83 !important;
  text-shadow: none !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5) !important;
  cursor: not-allowed;
  transform: none !important;
  filter: none !important;
}

/* ---------- title screen ---------- */

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 20px;
  overflow-y: auto;
  overflow-x: clip;
  scrollbar-width: thin;
  background:
    radial-gradient(44rem 26rem at 50% -10rem, rgba(255, 255, 255, 0.95), transparent 62%),
    radial-gradient(46rem 36rem at 108% 108%, rgba(138, 203, 174, 0.26), transparent 60%),
    radial-gradient(38rem 30rem at -8% 88%, rgba(215, 166, 79, 0.24), transparent 62%),
    linear-gradient(180deg, var(--bg), var(--bg-warm));
}

.title-screen.is-hidden {
  display: none;
}

.title-card {
  display: grid;
  gap: 0;
  justify-items: center;
  inline-size: min(720px, 100%);
  margin-block: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, #FFFDF8, #FDF3E1);
  outline: 1px solid rgba(215, 166, 79, 0.32);
  outline-offset: 6px;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.85) inset,
    0 26px 60px rgba(140, 90, 45, 0.24);
  text-align: center;
}

.title-keyart {
  display: block;
  inline-size: 100%;
  block-size: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 0;
  border-block-end: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}

.title-logo {
  position: relative;
  z-index: 1;
  margin: -1.75rem auto 0;
  padding: 0.42em 1.1em 0.34em;
  inline-size: fit-content;
  max-inline-size: calc(100% - 32px);
  color: var(--ink);
  background: linear-gradient(180deg, #FFFDF7, #FBEEDA);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 1.05rem + 2.6vw, 2.35rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.28;
  white-space: nowrap;
  text-wrap: balance;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9),
    0 2px 6px rgba(140, 90, 45, 0.18);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.7),
    inset 0 0 0 4px rgba(215, 166, 79, 0.4),
    0 10px 22px rgba(130, 85, 40, 0.2);
}

.title-tagline {
  margin: 14px 0 0;
  padding-inline: 20px;
  max-inline-size: 44ch;
  color: var(--ink-soft);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.title-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  inline-size: 100%;
  max-inline-size: 400px;
  margin-block: 20px 0;
  padding: 0 clamp(16px, 5vw, 28px) 26px;
}

.title-actions .btn-primary {
  grid-column: 1 / -1;
  min-block-size: 50px;
  font-size: 1.04rem;
  letter-spacing: 0.09em;
}

.title-actions .btn-secondary {
  min-block-size: 46px;
  font-size: 0.9rem;
}

/* ---------- shell ---------- */

.app-shell {
  inline-size: min(1160px, 100%);
  margin-inline: auto;
  padding: 18px 16px 28px;
}

.topbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-block-end: 16px;
}

.stat {
  position: relative;
  min-inline-size: 0;
  padding: 9px 12px 10px;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: linear-gradient(180deg, #FFFEFA, #FFF6E4);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 2px 6px rgba(150, 105, 60, 0.1);
}

.stat::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  block-size: 2px;
  background: linear-gradient(90deg, rgba(215, 166, 79, 0), rgba(215, 166, 79, 0.55), rgba(215, 166, 79, 0));
  pointer-events: none;
}

.stat-label,
.stat-value {
  display: block;
}

.stat-label {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  line-height: 1.4;
}

.stat-value {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.45;
}

.stat-meter {
  display: flex;
  gap: 3px;
  margin-block-start: 5px;
}

.stat-meter .pip {
  flex: 1 1 0;
  min-inline-size: 0;
  max-inline-size: 15px;
  block-size: 7px;
  border-radius: 999px;
  background: #EFE0C7;
  box-shadow: inset 0 0 0 1px #E1CFAE;
  transition: background 200ms ease-out, box-shadow 200ms ease-out;
}

.stat-meter .pip.on {
  background: linear-gradient(180deg, #E9AE72, #C25A4E);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 1px 2px rgba(180, 90, 60, 0.25);
}

.stat-meter .pip.on.mint {
  background: linear-gradient(180deg, #9ADBC0, var(--mint-dark));
}

.stat-stars {
  display: block;
  margin-block-start: 2px;
  color: var(--gold);
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  line-height: 1.3;
  text-shadow:
    0 1px 0 #FFFFFF,
    0 0 6px rgba(215, 166, 79, 0.35);
}

.stat-stars .star-off {
  color: #E3D2B3;
  text-shadow: none;
}

.stat:has(.stat-meter) .stat-value {
  color: var(--wine-dark);
}

.stat:has(.stat-stars) .stat-value {
  color: var(--gold-dark);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.board-panel,
.control-panel > section {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: linear-gradient(180deg, #FFFEFA, #FFFAF0);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 0 rgba(215, 166, 79, 0.12),
    0 10px 24px rgba(150, 100, 55, 0.12);
}

.board-panel {
  min-inline-size: 0;
  padding: 16px;
}

.control-panel {
  min-inline-size: 0;
  display: grid;
  gap: 16px;
}

.control-panel > section {
  padding: 16px;
}

h1,
h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.05em;
}

h1 {
  font-size: clamp(1.15rem, 1rem + 1vw, 1.5rem);
}

h2 {
  font-size: 1.02rem;
}

.board-panel h1 {
  margin-block-end: 14px;
}

.board-panel h1::after {
  content: "";
  display: block;
  inline-size: 64px;
  block-size: 3px;
  margin-block-start: 9px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), rgba(215, 166, 79, 0));
}

.control-panel h2 {
  position: relative;
  margin-block-end: 12px;
  padding-inline-start: 15px;
  padding-block-end: 8px;
  border-block-end: 1px solid var(--line-soft);
  letter-spacing: 0.07em;
}

.control-panel h2::before {
  content: "";
  position: absolute;
  inset-block-start: 0.5em;
  inset-inline-start: 0;
  inline-size: 7px;
  block-size: 7px;
  border-radius: 1px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  box-shadow: 0 0 0 1px rgba(154, 111, 40, 0.25);
  transform: rotate(45deg);
}

/* ---------- dungeon board ---------- */

.dungeon-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  inline-size: 100%;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid #E4CDA6;
  background:
    repeating-linear-gradient(45deg, rgba(198, 146, 82, 0.09) 0 10px, transparent 10px 20px),
    linear-gradient(180deg, #FAE9CF, #F3DDB8);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.6),
    inset 0 6px 18px rgba(180, 125, 65, 0.16),
    0 1px 2px rgba(150, 100, 60, 0.08);
}

.dungeon-grid.shake {
  animation: grid-shake 460ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes grid-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-4px, 2px); }
  30% { transform: translate(4px, -2px); }
  45% { transform: translate(-3px, -2px); }
  60% { transform: translate(3px, 2px); }
  75% { transform: translate(-2px, 1px); }
  90% { transform: translate(2px, -1px); }
}

.tile {
  --tile-bg: var(--tile-floor);
  --tile-ring: rgba(190, 130, 70, 0.14);
  --tile-glow: transparent;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-inline-size: 0;
  padding: 2px;
  border: 1px solid var(--tile-line);
  border-radius: 11px;
  background-color: var(--tile-bg);
  background-image:
    radial-gradient(120% 95% at 28% 15%, rgba(255, 255, 255, 0.7), transparent 58%),
    radial-gradient(circle at 85% 88%, rgba(242, 192, 148, 0.2), transparent 55%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -2px 5px rgba(198, 142, 82, 0.16),
    0 1px 2px rgba(150, 100, 55, 0.14),
    0 0 0 1px var(--tile-ring),
    0 0 14px var(--tile-glow);
  cursor: pointer;
  transition:
    border-color 140ms ease-out,
    box-shadow 160ms ease-out,
    transform 120ms ease-out,
    filter 140ms ease-out;
}

.tile:hover {
  transform: translateY(-1px);
  border-color: var(--gold-dark);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    inset 0 -2px 5px rgba(205, 150, 92, 0.14),
    0 0 0 2px rgba(215, 166, 79, 0.5),
    0 6px 12px rgba(150, 100, 50, 0.18),
    0 0 18px rgba(215, 166, 79, 0.28);
  z-index: 2;
}

.tile:active {
  transform: translateY(1px);
}

/* a whisper of a checkerboard so the 8x6 floor reads as paving stones
   (nth-child(2) is the first tile; hero-layer occupies child 1) */
.tile:nth-child(16n+2),
.tile:nth-child(16n+4),
.tile:nth-child(16n+6),
.tile:nth-child(16n+8),
.tile:nth-child(16n+11),
.tile:nth-child(16n+13),
.tile:nth-child(16n+15),
.tile:nth-child(16n+17) {
  filter: brightness(0.984) saturate(1.02);
}

.tile:hover {
  filter: none;
}

.tile-entrance {
  --tile-bg: #E1F3E9;
  --tile-ring: rgba(78, 155, 124, 0.42);
  --tile-glow: rgba(127, 200, 169, 0.4);
  border-color: #85C7AA;
}

.tile-boss {
  --tile-bg: #F7DFE2;
  --tile-ring: rgba(138, 53, 70, 0.4);
  --tile-glow: rgba(138, 53, 70, 0.28);
  border-color: #C98B98;
}

.tile-pit {
  --tile-bg: #ECDBBE;
}

.tile-poison {
  --tile-bg: #E9DBF2;
  border-color: #D5BCE8;
}

.tile-chest {
  --tile-bg: #FBEBCB;
  border-color: #EBD08A;
}

.tile-goblin {
  --tile-bg: #E1EED5;
  border-color: #BCD9A8;
}

.tile-spring {
  --tile-bg: #D8EFEB;
  border-color: #A5DAD5;
}

.tile-used::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(135deg, rgba(120, 90, 60, 0.12) 0 5px, transparent 5px 10px);
  pointer-events: none;
}

.tile-used .tile-marker {
  opacity: 0.5;
  filter: saturate(0.7);
}

.tile-marker {
  display: grid;
  place-items: center;
  inline-size: 72%;
  block-size: 72%;
  line-height: 1;
}

.tile-marker svg {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  filter: drop-shadow(0 1px 1px rgba(120, 70, 30, 0.22));
}

.tile-caption {
  position: absolute;
  inset-inline: 3px;
  inset-block-end: 3px;
  padding: 1px 2px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 253, 246, 0.78);
  color: var(--ink-soft);
  font-size: 0.5rem;
  letter-spacing: 0.02em;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

.tile-note {
  position: absolute;
  inset-block-start: 3px;
  inset-inline-end: 3px;
  padding: 0 3px;
  border-radius: 6px;
  background: rgba(255, 253, 246, 0.82);
  color: var(--wine-dark);
  font-size: 0.52rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  text-shadow: none;
}

.tile-pop {
  animation: tile-pop 460ms cubic-bezier(0.32, 1.5, 0.5, 1);
}

@keyframes tile-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); }
  70% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

/* ---------- heroes ---------- */

.hero-stack {
  position: absolute;
  inset-inline: 2px;
  inset-block-end: 2px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  pointer-events: none;
  z-index: 1;
  filter: drop-shadow(0 1px 1px rgba(120, 70, 30, 0.4));
}

.hero-token {
  display: grid;
  justify-items: center;
  min-inline-size: 0;
}

.hero-symbol {
  display: grid;
  place-items: center;
  inline-size: 20px;
  block-size: 20px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  box-shadow:
    0 0 0 1.5px rgba(255, 253, 246, 0.9),
    0 0 0 3px rgba(90, 60, 40, 0.16),
    0 1px 3px rgba(120, 75, 40, 0.35);
}

.hero-symbol svg {
  display: block;
  inline-size: 14px;
  block-size: 14px;
}

.hero-warrior .hero-symbol { background: #F4B8AE; }
.hero-priest .hero-symbol { background: #BCD9F4; }
.hero-rogue .hero-symbol { background: #F4DFA6; }
.hero-mage .hero-symbol { background: #DAC6EE; }
.hero-novice .hero-symbol { background: #B9E6D2; }

.hero-hp {
  display: block;
  inline-size: 100%;
  block-size: 4px;
  margin-block-start: 2px;
  border-radius: 999px;
  background: var(--hero-hp-bg);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.6),
    inset 0 1px 1px rgba(60, 40, 25, 0.25);
  overflow: clip;
}

.hero-hp-fill {
  display: block;
  block-size: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--hero-hp), #8FE7B4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: inline-size 260ms ease-out;
}

/* ---------- damage floats ---------- */

.float-damage {
  position: absolute;
  z-index: 7;
  color: var(--wine-dark);
  font-size: 0.9rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  text-shadow:
    0 1px 0 #FFFFFF,
    0 0 3px rgba(255, 255, 255, 0.95),
    0 0 9px rgba(255, 250, 235, 0.9);
  pointer-events: none;
  animation: float-up 1000ms cubic-bezier(0.22, 0.72, 0.28, 1) forwards;
}

.float-damage.heal {
  color: var(--mint-dark);
}

@keyframes float-up {
  0% { opacity: 0; transform: translateY(4px) scale(0.8); }
  15% { opacity: 1; transform: translateY(-2px) scale(1.12); }
  100% { opacity: 0; transform: translateY(-26px) scale(1); }
}

/* ---------- palette ---------- */

.palette {
  display: grid;
  gap: 8px;
}

.palette-item {
  position: relative;
  display: grid;
  gap: 4px;
  inline-size: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  background: linear-gradient(180deg, #FFFEFA, #FFF6E6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  text-align: start;
  cursor: pointer;
  transition:
    background 140ms ease-out,
    border-color 140ms ease-out,
    box-shadow 160ms ease-out,
    transform 120ms ease-out;
}

.palette-item:hover {
  transform: translateY(-1px);
  border-color: var(--line);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 4px 12px rgba(190, 125, 65, 0.16);
}

.palette-item.selected {
  border-color: var(--gold-dark);
  background: linear-gradient(180deg, #FFFDF6, #FAEBCF);
  box-shadow:
    0 0 0 1px var(--gold-dark),
    0 0 0 4px rgba(240, 208, 143, 0.35),
    0 6px 14px rgba(150, 105, 50, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.palette-item.selected::before {
  content: "";
  position: absolute;
  inset-block: 9px;
  inset-inline-start: 0;
  inline-size: 4px;
  border-radius: 0 999px 999px 0;
  background: linear-gradient(180deg, var(--wine-light), var(--wine));
}

.palette-item.selected .palette-name {
  color: var(--wine-dark);
}

.palette-item.selected .palette-symbol {
  background: linear-gradient(180deg, #FFF9EA, #F5E2BA);
  border-color: var(--gold);
  box-shadow:
    0 1px 3px rgba(170, 120, 50, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.palette-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-inline-size: 0;
}

.palette-symbol {
  display: grid;
  place-items: center;
  inline-size: 28px;
  block-size: 28px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(180deg, #FFFFFF, #FFF0DC);
  border: 1px solid var(--line-soft);
  box-shadow: 0 1px 3px rgba(170, 110, 60, 0.16);
  transition: background 140ms ease-out, border-color 140ms ease-out;
}

.palette-symbol svg {
  display: block;
  inline-size: 20px;
  block-size: 20px;
}

.palette-name {
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.palette-cost {
  flex: 0 0 auto;
  margin-inline-start: auto;
  padding: 0 7px;
  border: 1px solid #EBD6A8;
  border-radius: 999px;
  background: #FBF0D4;
  color: #7C5A20;
  font-size: 0.74rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
}

.palette-description {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

.palette-help {
  margin: 12px 0 0;
  padding-block-start: 9px;
  border-block-start: 1px dashed var(--line-soft);
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.65;
}

/* ---------- actions ---------- */

.actions {
  display: grid;
  gap: 10px;
}

.actions .btn-primary {
  min-block-size: 48px;
  letter-spacing: 0.06em;
}

#roar-button {
  color: #FFF7EC;
  border-color: #4F3C86;
  background: linear-gradient(180deg, #8E76C8, #7259AD 55%, #5F488F);
  text-shadow: 0 1px 1px rgba(45, 25, 80, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 0 0 1px rgba(240, 208, 143, 0.22),
    0 3px 0 #4F3C86,
    0 6px 12px rgba(100, 70, 160, 0.22);
}

#roar-button:active:not(:disabled) {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 1px 0 #4F3C86;
}

/* ---------- log ---------- */

.log-list {
  display: grid;
  max-block-size: 300px;
  margin: 0;
  padding: 0 2px 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #DEC29A transparent;
  list-style: none;
}

.log-list::-webkit-scrollbar {
  inline-size: 8px;
}

.log-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #DEC29A;
  background-clip: padding-box;
}

.log-list::-webkit-scrollbar-track {
  background: transparent;
}

.log-entry {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 8px;
  padding-block: 8px;
  border-block-start: 1px dashed var(--line-soft);
  font-size: 0.79rem;
  line-height: 1.6;
}

.log-entry:first-child {
  border-block-start: 0;
}

.log-entry.fresh .log-text {
  animation: log-in 380ms cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.log-entry.fresh .log-text {
  box-shadow:
    0 0 0 1px rgba(215, 166, 79, 0.45),
    0 2px 6px rgba(150, 100, 60, 0.1);
}

@keyframes log-in {
  0% { opacity: 0; transform: translateY(-5px) scale(0.99); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.log-meta {
  padding-block-start: 7px;
  color: var(--gold-dark);
  font-size: 0.68rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.log-text {
  position: relative;
  min-inline-size: 0;
  padding: 7px 11px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  border-start-start-radius: 5px;
  background: linear-gradient(180deg, #FFFDF8, #FFF4E2);
  box-shadow: 0 1px 3px rgba(150, 100, 60, 0.1);
  color: var(--ink);
}

.log-text::before {
  content: "";
  position: absolute;
  inset-inline-start: -5px;
  inset-block-start: 9px;
  inline-size: 8px;
  block-size: 8px;
  background: #FFFDF8;
  border-block-end: 1px solid var(--line-soft);
  border-inline-start: 1px solid var(--line-soft);
  transform: rotate(45deg);
}

/* ---------- dialogs ---------- */

dialog {
  max-inline-size: min(460px, calc(100% - 28px));
  max-block-size: calc(100dvb - 44px);
  overflow-y: auto;
  padding: 26px 24px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 248, 234, 0.95), transparent 60%),
    linear-gradient(180deg, #FFFDF8, #FDF2DE);
  color: var(--ink);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.9),
    inset 0 0 0 3px rgba(215, 166, 79, 0.22),
    0 28px 64px rgba(90, 55, 30, 0.32);
  scrollbar-width: thin;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgba(72, 48, 28, 0.4);
  backdrop-filter: blur(4px);
}

dialog h1 {
  margin-block-end: 12px;
  padding-block-end: 9px;
  border-block-end: 1px solid var(--line-soft);
  font-size: clamp(1.1rem, 1rem + 0.6vw, 1.28rem);
  letter-spacing: 0.04em;
  line-height: 1.4;
  word-break: keep-all;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

dialog h2 {
  position: relative;
  margin-block: 14px 4px;
  padding-inline-start: 13px;
  color: var(--wine-dark);
  font-size: 0.92rem;
  letter-spacing: 0.05em;
}

dialog h2::before {
  content: "";
  position: absolute;
  inset-block-start: 0.55em;
  inset-inline-start: 0;
  inline-size: 6px;
  block-size: 6px;
  border-radius: 1px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  transform: rotate(45deg);
}

dialog p {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  line-height: 1.75;
}

.help-body p {
  margin: 0 0 9px;
}

.help-body ol,
.help-body ul {
  margin: 0;
  padding-inline-start: 1.35em;
  color: var(--ink-soft);
  font-size: 0.83rem;
  line-height: 1.75;
}

.help-body li + li {
  margin-block-start: 3px;
}

.help-body li::marker {
  color: var(--gold-dark);
}

.help-body strong {
  color: var(--wine-dark);
}

dialog form {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-block-start: 16px;
}

dialog form button {
  min-inline-size: 128px;
}

/* ---------- hero overlay layer ---------- */

.hero-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  overflow: clip;
}

.uf-hero {
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0;
  inline-size: 22px;
  transition: transform 340ms cubic-bezier(0.25, 0.8, 0.3, 1);
  filter: drop-shadow(0 1px 1px rgba(120, 70, 30, 0.45));
}

.uf-hero .hero-symbol {
  inline-size: 20px;
  block-size: 20px;
  margin-inline: auto;
}

.uf-hero .hero-hp {
  inline-size: 100%;
}

/* ---------- responsive ---------- */

@media (max-width: 820px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .control-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-panel > section:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px 12px 22px;
  }

  .topbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-block-end: 12px;
  }

  .stat {
    padding: 8px 8px 9px;
    border-radius: 10px;
  }

  .stat-label {
    font-size: 0.64rem;
    letter-spacing: 0.06em;
  }

  .stat-value {
    font-size: 1rem;
  }

  .board-panel,
  .control-panel > section {
    border-radius: 12px;
  }

  .board-panel {
    padding: 12px;
  }

  .board-panel h1 {
    margin-block-end: 10px;
  }

  .control-panel {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .control-panel > section {
    padding: 12px;
  }

  .dungeon-grid {
    gap: 4px;
    padding: 6px;
    border-radius: 11px;
  }

  .tile {
    border-radius: 7px;
  }

  .tile-caption {
    display: none;
  }

  .hero-symbol {
    inline-size: 16px;
    block-size: 16px;
  }

  .hero-symbol svg {
    inline-size: 12px;
    block-size: 12px;
  }

  .hero-hp {
    block-size: 4px;
  }

  .log-list {
    max-block-size: 230px;
  }

  .log-entry {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 7px;
    font-size: 0.76rem;
  }

  .title-screen {
    padding: 16px;
  }

  .title-card {
    border-radius: 16px;
    outline-offset: 4px;
  }

  .title-logo {
    margin-block-start: -1.2rem;
    border-radius: 12px;
    letter-spacing: 0.08em;
  }

  .title-tagline {
    margin-block-start: 12px;
    font-size: 0.82rem;
    line-height: 1.65;
  }

  .title-actions {
    margin-block-start: 16px;
    gap: 8px;
    padding: 0 16px 20px;
    max-inline-size: 100%;
  }

  .title-actions .btn-primary {
    min-block-size: 48px;
    font-size: 0.98rem;
  }

  dialog {
    padding: 20px 18px 18px;
    border-radius: 16px;
  }

  dialog form {
    justify-content: stretch;
  }

  dialog form button {
    flex: 1 1 auto;
    min-inline-size: 0;
  }
}

/* ---------- motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  .dungeon-grid.shake,
  .tile-pop,
  .float-damage,
  .log-entry.fresh .log-text {
    animation: none !important;
  }

  .uf-hero,
  .hero-hp-fill,
  .stat-meter .pip {
    transition: none !important;
  }
}

/* ---------- overflow guards ---------- */

html,
body {
  overflow-x: clip;
}
