@font-face {
  font-family: "LXGW WenKai";
  src: url("./fonts/lxgw-wenkai-subset.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ink: #f6ecd9;
  --gold: #e4c78a;
  --cinnabar: #b6403a;
  --line: rgba(228, 199, 138, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #100c14;
  color: var(--ink);
  font-family: "LXGW WenKai", "Songti TC", "STSong", "PMingLiU", "WenQuanYi Micro Hei", "PingFang TC", "Noto Serif CJK TC", serif;
}

#stage {
  position: fixed;
  inset: 0;
  transition: opacity 0.22s ease;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 52%, rgba(0, 0, 0, 0.42) 100%);
}

.icon-btn, .hud-link, #resetBtn, #spinBtn, .seg button, #sheetClose, #introBtn {
  font: inherit;
  font-size: 16px;
  color: var(--gold);
  background: rgba(18, 12, 20, 0.55);
  border: 1px solid var(--line);
  border-radius: 2px;
  text-decoration: none;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 0 0 1px rgba(255, 236, 200, 0.08);
}

.icon-btn {
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(18, 12, 20, 0.45);
}

.icon-btn svg { width: 22px; height: 22px; }

.panel-btn {
  position: fixed;
  z-index: 5;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
}

.sound {
  position: fixed;
  z-index: 4;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
}

.sound[aria-pressed="false"] { opacity: 0.55; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: rgba(0, 0, 0, 0.38);
}

.panel {
  position: fixed;
  z-index: 6;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(22rem, calc(100vw - 28px));
  max-width: 100%;
  display: flex;
  flex-direction: column;
  transform: translateX(-105%);
  transition: transform 0.28s ease;
  background: rgba(14, 10, 18, 0.96);
  border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  pointer-events: none;
  box-shadow: 16px 0 40px rgba(0, 0, 0, 0.4);
}

.panel.open {
  transform: translateX(0);
  pointer-events: auto;
}

.panel-bar, .link-row, .seg {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-bar {
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(228, 199, 138, 0.2);
}

.panel-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.birth, .pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  color: var(--gold);
  font-size: 16px;
  min-width: 0;
}

.birth label, .pick {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.birth label.wide, .pick { grid-column: 1 / -1; }

.birth select, .pick select {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: rgba(18, 12, 20, 0.72);
  border: 1px solid var(--line);
  border-radius: 2px;
  min-height: 44px;
  width: 100%;
  max-width: 100%;
  padding: 0 8px;
  touch-action: manipulation;
}

#spinBtn[aria-pressed="false"] {
  color: #cbbba4;
  opacity: 0.8;
}

.form-alert {
  margin: 0;
  color: #ffd0c4;
  font-size: 16px;
  line-height: 1.45;
}

.credit {
  margin: 8px 0 0;
  color: rgba(232, 220, 196, 0.72);
  font-size: 11px;
  line-height: 1.5;
}

.credit a {
  color: #e4c78a;
}

.hud-title {
  margin: 0;
  letter-spacing: 0.18em;
  font-size: 1.15rem;
}

.hud-title span {
  margin-left: 8px;
  color: var(--cinnabar);
  letter-spacing: 0.12em;
  font-size: 0.82rem;
}

.hud-note, .hint {
  margin: 0;
  color: #cbbba4;
  font-size: 16px;
  line-height: 1.45;
}

.credit span {
  display: block;
  margin-bottom: 4px;
  letter-spacing: 0.14em;
}

.seg button[aria-pressed="true"] {
  background: #7d2824;
  color: #f8efe4;
  border-color: var(--cinnabar);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  color: #f6ecd9;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}

.legend li { display: flex; align-items: center; gap: 6px; }

.gem {
  width: 14px;
  height: 14px;
  display: inline-block;
  box-shadow: 0 0 8px currentColor;
}

.gem.lu { color: #ffd36a; background: radial-gradient(circle at 50% 60%, #fff1b8, #e0a020 70%); border-radius: 40% 40% 46% 46%; }
.gem.quan { color: #e24b3a; background: #b42318; border-radius: 2px; }
.gem.ke { color: #d7e6ff; background: #9eb6d8; clip-path: polygon(50% 0, 62% 35%, 100% 38%, 70% 60%, 78% 100%, 50% 76%, 22% 100%, 30% 60%, 0 38%, 38% 35%); }
.gem.ji { color: #c9b6e6; background: #2a2433; border-radius: 50% 50% 42% 42%; border: 1px solid #8d74b8; }

.beam {
  width: 22px;
  height: 4px;
  border-radius: 4px;
  display: inline-block;
  box-shadow: 0 0 8px currentColor;
}
.beam.san { color: #ffd36a; background: #ffd36a; }
.beam.dui { color: #3ec8e6; background: #3ec8e6; }

.sheet {
  position: fixed;
  z-index: 4;
  left: calc(10px + env(safe-area-inset-left));
  right: calc(64px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: rgba(16, 11, 18, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.sheet-bar {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.aspect {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--gold);
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

#introBtn {
  color: #f8efe4;
  background: #7d2824;
  border-color: var(--cinnabar);
}

.fail {
  position: fixed;
  inset: auto 16px calc(24px + env(safe-area-inset-bottom));
  z-index: 7;
  background: #2a1414;
  border: 1px solid var(--cinnabar);
  padding: 12px;
  font-size: 16px;
}
