:root {
  --ink: #050a09;
  --paper: #edf3ee;
  --muted: rgba(226, 242, 234, 0.56);
  --faint: rgba(226, 242, 234, 0.3);
  --jade: #7fe3c4;
  --jade-deep: #2b7a63;
  --gold: #e7c37a;
  --cinnabar: #e05a4f;
  --line: rgba(127, 227, 196, 0.16);
  --cell: 72px;
  --gap: 8px;
  --pad: 8px;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: #050a09;
  color: var(--paper);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

#frame {
  position: relative;
  z-index: 1;
  width: min(100%, 540px);
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom));
  transition: opacity 0.45s ease, transform 0.45s ease;
}

body[data-screen="title"] #frame {
  opacity: 0;
  transform: scale(0.985);
  pointer-events: none;
}

body[data-screen="title"] .rail {
  opacity: 0;
}

/* side verses, only where there is room for them */
.rail {
  display: none;
  transition: opacity 0.4s ease;
}

@media (min-width: 1080px) and (min-height: 620px) {
  .rail {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: block;
    writing-mode: vertical-rl;
    font-size: 12px;
    letter-spacing: 0.42em;
    color: rgba(231, 195, 122, 0.28);
    text-shadow: 0 0 24px rgba(231, 195, 122, 0.1);
    pointer-events: none;
    z-index: 0;
  }

  .rail.left {
    left: clamp(20px, 6vw, 110px);
  }

  .rail.right {
    right: clamp(20px, 6vw, 110px);
    color: rgba(127, 227, 196, 0.2);
  }
}

/* ---------------- top hud ---------------- */

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 26px;
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
}

.hud-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

#modeName {
  color: var(--gold);
  letter-spacing: 0.24em;
  font-size: 13px;
}

.hud-sub {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-center {
  display: flex;
  gap: 10px;
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.hud-right {
  display: flex;
  gap: 6px;
}

.icon {
  width: 28px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(10, 20, 17, 0.5);
  color: var(--muted);
  font-family: var(--serif);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.icon:active {
  background: rgba(127, 227, 196, 0.12);
}

/* ---------------- world ---------------- */

#world {
  position: relative;
  flex: 0 0 auto;
  height: clamp(160px, 27vh, 260px);
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(10, 22, 18, 0.42), rgba(5, 10, 9, 0.12));
  border: 1px solid rgba(127, 227, 196, 0.1);
}

#worldCanvas {
  width: 100%;
  height: 100%;
  display: block;
  transition: opacity 0.4s ease;
}

#worldHud {
  position: absolute;
  inset: 0;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

/* while a banner speaks, let the panel fall back so the words read cleanly */
body.banner-up #worldCanvas {
  opacity: 0.3;
}

body.banner-up #worldHud {
  opacity: 0.16;
}

.world-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.realm-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.realm-name {
  font-size: 17px;
  letter-spacing: 0.18em;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(231, 195, 122, 0.35);
}

.realm-next {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--faint);
}

.clean-tags {
  display: flex;
  gap: 5px;
}

.meter-row.runway {
  width: 156px;
  margin-top: 4px;
}

.tag {
  font-size: 9.5px;
  letter-spacing: 0.1em;
  padding: 2px 7px;
  border-radius: 99px;
  color: var(--jade);
  border: 1px solid rgba(127, 227, 196, 0.28);
  background: rgba(127, 227, 196, 0.06);
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meter {
  flex: 1;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.meter i,
.meter-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #2f8f74, #9df0d4);
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(127, 227, 196, 0.5);
}

.meter-label {
  font-size: 9.5px;
  color: var(--faint);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.world-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.trib-chip.warn {
  color: var(--cinnabar);
}

.demon-chip {
  color: rgba(224, 90, 79, 0.75);
}

/* battle layout (mode 2) */

.battle-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
}

.fighter {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.fighter.foe {
  text-align: right;
}

.f-name {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--paper);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.f-sub {
  font-size: 9.5px;
  color: var(--faint);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #2f8f74, #9df0d4);
  transition: width 0.25s ease;
}

.bar.foe i {
  background: linear-gradient(90deg, #8c2f2c, #ef7a6c);
  margin-left: auto;
}

.vs-mark {
  font-size: 14px;
  color: rgba(224, 90, 79, 0.6);
  letter-spacing: 0.2em;
  padding-top: 4px;
}

.story {
  font-size: 10.5px;
  line-height: 1.6;
  color: rgba(226, 242, 234, 0.55);
  letter-spacing: 0.04em;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  padding: 12px 0 2px;
  margin-top: -6px;
  background: linear-gradient(180deg, rgba(5, 10, 9, 0), rgba(4, 8, 7, 0.9) 72%);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body[data-mode="heaven"] #world {
  height: clamp(168px, 27vh, 240px);
}

.story.show {
  opacity: 1;
  transform: none;
}

.story b {
  color: var(--gold);
  font-weight: 400;
  margin-right: 6px;
  letter-spacing: 0.14em;
}

.story p {
  margin: 2px 0 0;
}

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

#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}

#boardWrap {
  width: min(100%, calc(100dvh - 27vh - 168px));
  max-width: 100%;
  aspect-ratio: 1 / 1;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 20px;
  background: rgba(7, 16, 13, 0.66);
  border: 1px solid rgba(127, 227, 196, 0.14);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 0 50px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

.grid {
  position: absolute;
  inset: var(--pad);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
}

.cell {
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.022);
  border: 1px solid rgba(127, 227, 196, 0.05);
}

.tiles {
  position: absolute;
  inset: 0;
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cell);
  height: var(--cell);
  border-radius: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  transition: translate 0.11s cubic-bezier(0.22, 0.7, 0.28, 1);
  background: linear-gradient(
    158deg,
    hsl(var(--h) var(--s) calc(var(--l) * 1.22)),
    hsl(var(--h) var(--s) var(--l))
  );
  border: 1px solid hsla(var(--h), var(--s), 78%, 0.24);
  box-shadow: 0 0 calc(20px * var(--glow)) hsla(var(--h), var(--s), 62%, calc(var(--glow) * 0.85)),
    inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 3px 10px rgba(0, 0, 0, 0.35);
  will-change: translate, scale;
  color: rgba(244, 255, 250, 0.96);
}

.tile.no-anim {
  transition: none;
}

.tile .tname {
  font-size: calc(var(--cell) * 0.195);
  letter-spacing: 0.08em;
  opacity: 0.66;
  line-height: 1;
}

.tile .tval {
  font-size: calc(var(--cell) * 0.3);
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.tile.light {
  color: #0d1a16;
}

.tile.light .tname {
  opacity: 0.6;
}

.tile.high {
  box-shadow: 0 0 calc(30px * var(--glow)) hsla(var(--h), var(--s), 65%, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 3px 14px rgba(0, 0, 0, 0.4);
}

.tile.demon {
  background: radial-gradient(circle at 50% 38%, #3a1113 0%, #1a0809 55%, #0d0506 100%);
  border: 1px solid rgba(224, 90, 79, 0.4);
  color: rgba(240, 150, 140, 0.8);
  box-shadow: 0 0 22px rgba(224, 90, 79, 0.25), inset 0 0 24px rgba(0, 0, 0, 0.8);
  animation: demonPulse 3.2s ease-in-out infinite;
}

.tile.demon .tname {
  font-size: calc(var(--cell) * 0.17);
  letter-spacing: 0.14em;
  margin-top: 2px;
}

.demon-eye {
  width: calc(var(--cell) * 0.2);
  height: calc(var(--cell) * 0.2);
  border-radius: 50%;
  background: radial-gradient(circle, #ff8a76 0%, #b32b23 45%, rgba(60, 8, 8, 0) 72%);
  box-shadow: 0 0 12px rgba(224, 90, 79, 0.8);
}

.tile.spawn {
  animation: spawnIn 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.tile.merge {
  animation: popIn 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.tile.merge-jump {
  animation: popJump 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.tile.vanish {
  animation: vanishOut 0.24s ease-in forwards;
}

.tile.struck {
  z-index: 2;
  animation: tileStruck 0.5s ease-out;
}

.tile.pickable {
  outline: 1px dashed rgba(231, 195, 122, 0.45);
  outline-offset: -4px;
  cursor: pointer;
}

.tile.picked {
  box-shadow: 0 0 0 2px var(--gold), 0 0 24px rgba(231, 195, 122, 0.6);
}

.board.shake {
  animation: boardShake 0.28s ease-in-out;
}

.float {
  position: absolute;
  left: 0;
  top: 0;
  transform: translateX(-50%);
  z-index: 5;
  font-size: 12px;
  color: #c9f7e6;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.9), 0 0 18px rgba(127, 227, 196, 0.5);
  pointer-events: none;
  animation: floatUp 0.9s ease-out forwards;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.float.demon {
  color: #ff9587;
  text-shadow: 0 0 12px rgba(224, 90, 79, 0.8);
}

.float.buff {
  color: #ffe3a8;
}

.float.float-center {
  left: 50%;
  top: 42%;
  font-size: 13px;
}

/* ---------------- dock ---------------- */

#dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.dock-group {
  display: flex;
  gap: 6px;
}

.dock-group .act {
  flex: 1 1 0;
  min-width: 0;
}

.dock-group.empty-group {
  display: none;
}

.act.item {
  border-color: rgba(231, 195, 122, 0.26);
  background: linear-gradient(170deg, rgba(44, 36, 20, 0.7), rgba(10, 22, 18, 0.72));
}

.act.item .act-glyph {
  color: var(--gold);
}

.act {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 7px 3px 6px;
  border-radius: 12px;
  border: 1px solid rgba(127, 227, 196, 0.13);
  background: rgba(10, 22, 18, 0.66);
  color: var(--paper);
  font-family: var(--serif);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.2s ease;
  min-height: 46px;
}

.act:active {
  transform: scale(0.96);
}

.act.armed {
  border-color: rgba(231, 195, 122, 0.75);
  background: linear-gradient(170deg, rgba(66, 52, 24, 0.92), rgba(16, 30, 24, 0.88));
  box-shadow: 0 0 0 1px rgba(231, 195, 122, 0.55), 0 0 20px rgba(231, 195, 122, 0.35);
}

.act.armed .act-name {
  color: var(--gold);
}

.act .act-glyph {
  font-size: 15px;
  color: var(--gold);
  line-height: 1.1;
}

.act .act-name {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted);
  line-height: 1.2;
}

.act .act-badge {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 9px;
  color: var(--jade);
  font-variant-numeric: tabular-nums;
}

.act .act-cost {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 9px;
  color: var(--gold);
  opacity: 0.85;
}

.act .dim {
  opacity: 0.32;
}

.act.locked,
.act.disabled {
  opacity: 0.38;
}

.act.empty {
  border-style: dashed;
  border-color: rgba(127, 227, 196, 0.08);
  background: rgba(8, 16, 13, 0.35);
}

.dock-status {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 14px;
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.08em;
}

.tianji {
  display: flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
}

.tianji b {
  color: var(--gold);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.zhuoqi {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.meter.slim {
  height: 3px;
}

.meter.slim i {
  background: linear-gradient(90deg, #7a2a24, #e05a4f);
  box-shadow: 0 0 8px rgba(224, 90, 79, 0.6);
}

/* ---------------- banner ---------------- */

#banner {
  position: fixed;
  top: calc(42px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  height: clamp(160px, 27vh, 260px);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

body[data-mode="heaven"] #banner {
  height: clamp(168px, 27vh, 240px);
}

#banner.show {
  opacity: 1;
}

.banner-box {
  text-align: center;
  padding: 16px 26px;
  max-width: 84vw;
  background: radial-gradient(ellipse at 50% 50%, rgba(4, 9, 8, 0.82), rgba(4, 9, 8, 0) 72%);
  animation: bannerIn 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

.banner-glyph {
  font-size: 32px;
  color: var(--gold);
  letter-spacing: 0.2em;
  text-shadow: 0 0 30px rgba(231, 195, 122, 0.55);
  line-height: 1;
  margin-bottom: 6px;
}

.banner-title {
  font-size: clamp(18px, 4.6vw, 24px);
  letter-spacing: 0.22em;
  color: var(--paper);
  text-shadow: 0 0 24px rgba(0, 0, 0, 0.95);
}

.banner-sub {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: rgba(226, 242, 234, 0.68);
  line-height: 1.7;
  text-shadow: 0 0 14px rgba(0, 0, 0, 0.9);
}

.banner-box.danger .banner-glyph {
  color: var(--cinnabar);
  text-shadow: 0 0 30px rgba(224, 90, 79, 0.65);
}

.banner-box.danger .banner-title {
  color: #ffd9d2;
}

.banner-box.realm .banner-glyph {
  color: var(--jade);
  text-shadow: 0 0 34px rgba(127, 227, 196, 0.6);
}

/* ---------------- toasts ---------------- */

#toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}

.toast {
  padding: 6px 14px;
  border-radius: 99px;
  background: rgba(6, 14, 11, 0.86);
  border: 1px solid rgba(127, 227, 196, 0.2);
  color: var(--jade);
  font-size: 11px;
  letter-spacing: 0.08em;
  animation: toastIn 0.3s ease;
  backdrop-filter: blur(6px);
  max-width: 88vw;
  text-align: center;
}

.toast.spell {
  color: #b8f5df;
}

.toast.item {
  color: var(--gold);
  border-color: rgba(231, 195, 122, 0.28);
}

.toast.danger {
  color: #ffe4de;
  background: rgba(46, 12, 10, 0.95);
  border-color: rgba(224, 90, 79, 0.62);
  font-size: 12.5px;
  letter-spacing: 0.1em;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.55);
}

.toast.kill {
  color: #ffe1a6;
}

.toast.out {
  opacity: 0;
  transform: translateY(-6px);
  transition: all 0.4s ease;
}

/* ---------------- overlay ---------------- */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 42%, rgba(6, 14, 12, 0.5), rgba(2, 5, 4, 0.88));
  backdrop-filter: blur(6px);  transition: opacity 0.25s ease;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

body[data-screen="title"] #overlay {
  background: radial-gradient(circle at 50% 42%, rgba(6, 14, 12, 0.26), rgba(2, 5, 4, 0.8) 82%);
  backdrop-filter: blur(3px);
}

.screen,
.panel {
  width: 100%;
  max-width: 500px;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  animation: riseIn 0.4s ease;
  scrollbar-width: none;
}

.panel {
  padding: 26px 22px;
  border-radius: 22px;
  border: 1px solid rgba(127, 227, 196, 0.12);
  background: rgba(7, 15, 13, 0.72);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.panel.wide {
  max-width: 620px;
}

.panel h2,
.screen h2 {
  font-size: 22px;
  letter-spacing: 0.2em;
  font-weight: 400;
  margin: 6px 0 4px;
  color: var(--paper);
}

.panel-sub {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.08em;
  line-height: 1.7;
  margin: 4px 0 18px;
}

.kicker {
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--gold);
  opacity: 0.8;
  margin: 0;
}

/* title */

.title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(20px, 4vh, 34px);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.brand-rule {
  width: 64px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(231, 195, 122, 0.55), transparent);
}

.game-title {
  margin: 0;
  line-height: 1.05;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.game-title .num {
  font-size: clamp(40px, 13vw, 64px);
  letter-spacing: 0.04em;
  color: var(--paper);
  text-shadow: 0 0 40px rgba(127, 227, 196, 0.22);
  font-variant-numeric: tabular-nums;
}

.game-title .cn {
  font-size: clamp(24px, 7.4vw, 34px);
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(231, 195, 122, 0.35);
}

.game-title .en {
  font-family: var(--sans);
  font-size: clamp(9px, 2.6vw, 12px);
  letter-spacing: 0.45em;
  text-indent: 0.45em;
  color: var(--faint);
  text-transform: lowercase;
  margin-top: 4px;
}

.tagline {
  margin: 2px 0 0;
  font-size: 12px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--muted);
}

.menu {
  width: 100%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 18px;
  border-radius: 14px;
  border: 1px solid rgba(127, 227, 196, 0.18);
  background: rgba(9, 20, 16, 0.6);
  color: var(--paper);
  font-family: var(--serif);
  cursor: pointer;
  text-align: left;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.menu-btn b {
  font-size: 17px;
  letter-spacing: 0.3em;
  font-weight: 400;
}

.menu-btn span {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.menu-btn.primary {
  border-color: rgba(231, 195, 122, 0.5);
  background: linear-gradient(160deg, rgba(48, 40, 22, 0.55), rgba(10, 20, 16, 0.6));
  box-shadow: 0 0 30px rgba(231, 195, 122, 0.1);
}

.menu-btn.primary b {
  color: var(--gold);
}

.menu-btn.locked {
  opacity: 0.5;
}

.menu-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.menu-btn.ghost {
  padding: 9px 6px;
  align-items: center;
  text-align: center;
  font-size: 11.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.title-foot {
  font-size: 10px;
  letter-spacing: 0.16em;
  color: rgba(226, 242, 234, 0.26);
}

/* cards */

.cards {
  display: grid;
  gap: 9px;
}

.cards.three {
  grid-template-columns: 1fr;
}

@media (min-width: 680px) {
  .cards.three {
    grid-template-columns: repeat(3, 1fr);
  }
}

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 14px 14px 13px;
  border-radius: 14px;
  border: 1px solid rgba(127, 227, 196, 0.16);
  background: rgba(10, 22, 18, 0.72);
  color: var(--paper);
  font-family: var(--serif);
  text-align: left;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.card:active {
  transform: scale(0.98);
}

@media (hover: hover) {
  .card:hover {
    border-color: rgba(127, 227, 196, 0.4);
    background: rgba(14, 30, 25, 0.85);
  }
}

.card-glyph {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(231, 195, 122, 0.38);
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 0;
  background: rgba(231, 195, 122, 0.06);
}

.card-name {
  font-size: 15px;
  letter-spacing: 0.16em;
}

.card-name em {
  font-style: normal;
  font-size: 10.5px;
  color: var(--faint);
  margin-left: 7px;
  letter-spacing: 0.1em;
}

.card-kind {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--jade);
  opacity: 0.75;
}

.card-desc {
  font-size: 11px;
  line-height: 1.65;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.card-stats {
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.06em;
}

.card-trait {
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 0.12em;
  opacity: 0.85;
}

.card.rarity-rare {
  border-color: rgba(231, 195, 122, 0.36);
  background: linear-gradient(165deg, rgba(46, 38, 20, 0.5), rgba(10, 22, 18, 0.75));
}

.card.rarity-rare .card-name {
  color: var(--gold);
}

.hero-card {
  align-items: center;
  text-align: center;
}

/* help */

.help-grid {
  display: grid;
  gap: 16px;
  text-align: left;
  margin-top: 10px;
}

@media (min-width: 680px) {
  .help-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
  }
}

.help-grid h3 {
  font-size: 12px;
  letter-spacing: 0.24em;
  color: var(--gold);
  font-weight: 400;
  margin: 0 0 6px;
}

.help-grid p {
  font-size: 11px;
  line-height: 1.8;
  color: var(--muted);
  margin: 0 0 8px;
}

.help-grid b {
  color: var(--paper);
  font-weight: 400;
}

.credit-line {
  font-size: 11px;
  line-height: 1.75;
  color: var(--muted);
  margin: 0 0 12px;
}

.credit-line.dim {
  color: var(--faint);
}

.panel-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

/* buttons */

.btn {
  padding: 11px 22px;
  border-radius: 12px;
  border: 1px solid rgba(127, 227, 196, 0.2);
  background: rgba(10, 22, 18, 0.7);
  color: var(--paper);
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.2em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.2s ease;
}

.btn.primary {
  border-color: rgba(231, 195, 122, 0.5);
  color: var(--gold);
  background: linear-gradient(160deg, rgba(48, 40, 22, 0.6), rgba(10, 20, 16, 0.7));
}

.btn.ghost {
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}

.btn:disabled {
  opacity: 0.32;
}

.btn:active {
  transform: scale(0.97);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

/* result */

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.result-glyph {
  font-size: 54px;
  line-height: 1;
  margin-bottom: 4px;
  color: var(--gold);
  text-shadow: 0 0 40px rgba(231, 195, 122, 0.5);
}

.result.win .result-glyph {
  color: #a9f5dc;
  text-shadow: 0 0 50px rgba(127, 227, 196, 0.6);
}

.result.lose .result-glyph {
  color: #f08f80;
  text-shadow: 0 0 40px rgba(224, 90, 79, 0.5);
}

.result h2 {
  margin: 0;
}

.result-note {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  color: var(--gold);
  opacity: 0.85;
  margin: 2px 0 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 18px;
  width: 100%;
  max-width: 320px;
  margin: 14px 0 4px;
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid rgba(127, 227, 196, 0.08);
  padding-bottom: 5px;
}

.stat b {
  font-weight: 400;
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}

.unlock-note {
  margin: 12px 0 0;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--jade);
  text-shadow: 0 0 20px rgba(127, 227, 196, 0.4);
}

.result .stack {
  width: 100%;
  max-width: 320px;
}

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

/* Tiles are positioned with the `translate` property and animated with
   `scale`/`rotate`, so a pop or fade never touches where the tile sits. */
@keyframes spawnIn {
  from {
    opacity: 0;
    scale: 0.55;
  }
  to {
    opacity: 1;
    scale: 1;
  }
}

@keyframes popIn {
  0% {
    scale: 0.84;
    filter: brightness(1.7);
  }
  60% {
    scale: 1.12;
  }
  100% {
    scale: 1;
    filter: brightness(1);
  }
}

@keyframes popJump {
  0% {
    scale: 0.8;
    filter: brightness(2.2);
  }
  55% {
    scale: 1.22;
  }
  100% {
    scale: 1;
    filter: brightness(1);
  }
}

@keyframes vanishOut {
  to {
    opacity: 0;
    scale: 0.6;
    rotate: 6deg;
  }
}

@keyframes tileStruck {
  0% {
    filter: brightness(2.4) saturate(0.5);
    box-shadow: 0 0 0 3px rgba(224, 90, 79, 0.95), 0 0 42px rgba(224, 90, 79, 0.8);
  }
  55% {
    filter: brightness(1.25);
  }
  100% {
    filter: none;
  }
}

@keyframes floatUp {
  0% {
    opacity: 0;
    translate: 0 6px;
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    translate: 0 -38px;
  }
}

@keyframes boardShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}

@keyframes demonPulse {
  0%,
  100% {
    box-shadow: 0 0 18px rgba(224, 90, 79, 0.2), inset 0 0 24px rgba(0, 0, 0, 0.8);
  }
  50% {
    box-shadow: 0 0 30px rgba(224, 90, 79, 0.4), inset 0 0 24px rgba(0, 0, 0, 0.8);
  }
}

@keyframes bannerIn {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#app.quake {
  animation: quake 0.42s ease-in-out;
}

@keyframes quake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-6px, 3px, 0);
  }
  40% {
    transform: translate3d(5px, -4px, 0);
  }
  60% {
    transform: translate3d(-4px, 2px, 0);
  }
  80% {
    transform: translate3d(3px, -2px, 0);
  }
}

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

@media (max-height: 680px) {
  #world,
  #banner {
    height: clamp(120px, 20vh, 160px);
  }
  #frame {
    gap: 6px;
  }
  #boardWrap {
    width: min(100%, calc(100dvh - 20vh - 168px));
  }
  .banner-glyph {
    font-size: 26px;
  }
  .banner-sub {
    font-size: 10px;
  }
}

@media (min-width: 900px) and (min-height: 640px) {
  #frame {
    width: min(100%, 520px);
  }
  #boardWrap {
    width: min(100%, calc(100dvh - 27vh - 170px));
  }
}

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