/* 同桌 · design tokens, reset, the phone stage and the per-scene backdrops. */
@font-face {
  font-family: "Tz Display";
  src: url("../fonts/tz-display.woff2") format("woff2");
  font-weight: 700 900;
  font-display: swap;
}

:root {
  --ink-0: #09070a;
  --ink-1: #120d10;
  --ink-2: #1b1418;
  --ink-3: #2a1f22;
  --gold-1: #8a6a36;
  --gold-2: #c9a25c;
  --gold-3: #ecd08f;
  --gold-4: #fff1c7;
  --parch-1: #f6ecd6;
  --parch-2: #e7d8b6;
  --parch-3: #c9b58a;
  --parch-ink: #2e2217;
  --blue: #5b8fd6;
  --blue-deep: #1b3566;
  --blue-glow: #9cc2ff;
  --red: #cf4d4f;
  --red-deep: #641922;
  --red-glow: #ff9a8f;
  --green: #5fae8b;
  --amber: #e9b949;
  --violet: #a67bd4;
  --text: #f5ecdb;
  --text-dim: rgba(245, 236, 219, 0.68);
  --text-faint: rgba(245, 236, 219, 0.42);
  --line: rgba(236, 208, 143, 0.22);
  --line-soft: rgba(255, 255, 255, 0.08);
  --glass: rgba(18, 13, 16, 0.58);
  --glass-strong: rgba(18, 13, 16, 0.78);
  --accent: var(--gold-3);
  --table-a: #6a4630;
  --table-b: #34221a;
  --font-display: "Tz Display", "Songti SC", "STSongti-SC-Black", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --font-body: system-ui, -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --font-num: "Iowan Old Style", "Palatino Linotype", Palatino, "Noto Serif", Georgia, serif;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.44, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--ink-0); }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
h1, h2, h3, p, ol, ul, dl, dd, figure { margin: 0; padding: 0; }
ol, ul { list-style: none; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; letter-spacing: 0.02em; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { font: inherit; color: inherit; user-select: text; -webkit-user-select: text; }
img { display: block; max-width: 100%; }
a { color: inherit; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; padding: 1px 5px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); }
:focus-visible { outline: 2px solid var(--gold-3); outline-offset: 2px; }
.icon { flex: none; display: block; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

.kicker {
  display: block;
  font-size: 11.500px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--accent);
  opacity: 0.92;
}
.fine { font-size: 12.500px; line-height: 1.6; color: var(--text-faint); }
.fine.warn { color: #f0c27a; }
.fine.center { text-align: center; }
.link { color: var(--gold-3); text-underline-offset: 3px; }

/* ── stage and phone ─────────────────────────────────────────────────────── */
#app { height: 100%; }
.stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: stretch;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  /* clip, not hidden: a hidden box can still be scrolled by focus() or the on-screen keyboard, which would shove the whole table off-centre */
  overflow: hidden;
  overflow: clip;
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(120, 78, 40, 0.3), transparent 70%),
    radial-gradient(60% 50% at 50% 100%, rgba(40, 26, 60, 0.45), transparent 70%),
    #070508;
}
.phone {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 460px;
  height: 100%;
  overflow: hidden;
  overflow: clip;
  isolation: isolate;
  background: var(--ink-1);
}
@media (min-width: 560px) and (min-height: 600px) {
  .stage:not(.is-sim) { align-items: center; padding: 20px; }
  .stage:not(.is-sim) .phone {
    width: 412px;
    height: min(100%, 892px);
    border-radius: 40px;
    box-shadow: 0 0 0 1px rgba(236, 208, 143, 0.22), 0 0 0 9px #0d0a0c, 0 0 0 10px rgba(255, 255, 255, 0.07), 0 50px 120px rgba(0, 0, 0, 0.75);
  }
}

.boot {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  height: 100vh;
  height: 100dvh;
  color: var(--text-dim);
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  background: radial-gradient(60% 40% at 50% 45%, rgba(214, 150, 70, 0.22), transparent 70%), var(--ink-0);
}
.boot-mark {
  width: 14px;
  height: 22px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(circle at 50% 70%, #fff6d8, #ffb347 55%, #e2622a);
  box-shadow: 0 0 34px 10px rgba(255, 170, 70, 0.45);
  animation: flame 1.6s ease-in-out infinite;
}

/* ── scenes ──────────────────────────────────────────────────────────────── */
.scene { position: absolute; inset: 0; z-index: -1; overflow: hidden; animation: fade-in 0.7s both; }
.scene-layer { position: absolute; inset: 0; }
.scene-grain {
  opacity: 0.22;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

[data-scene="tavern"] { --accent: var(--gold-3); --table-a: #7a5236; --table-b: #33211a; }
[data-scene="tavern"] .scene-base {
  background:
    radial-gradient(70% 34% at 50% -4%, rgba(255, 176, 92, 0.34), transparent 72%),
    radial-gradient(120% 70% at 50% 108%, rgba(95, 44, 30, 0.5), transparent 70%),
    linear-gradient(180deg, #33201a 0%, #1d1314 42%, #0f0a0d 100%);
}
[data-scene="avalon"] { --accent: #f0d896; --table-a: #3b4f86; --table-b: #17203f; }
[data-scene="avalon"] .scene-base {
  background:
    radial-gradient(70% 36% at 50% -6%, rgba(240, 206, 130, 0.3), transparent 72%),
    radial-gradient(110% 60% at 50% 110%, rgba(110, 30, 44, 0.42), transparent 70%),
    linear-gradient(180deg, #23366b 0%, #131b3a 44%, #0a0c1b 100%);
}
[data-scene="avalon"] .scene-rays {
  background: repeating-conic-gradient(from 0deg at 50% -12%, rgba(240, 216, 150, 0.07) 0deg 5deg, transparent 5deg 14deg);
  mask-image: linear-gradient(180deg, #000 0%, transparent 62%);
  -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 62%);
}
[data-scene="night"] { --accent: #c6d8ff; --table-a: #2c3d6e; --table-b: #131a36; --line: rgba(198, 216, 255, 0.24); }
[data-scene="night"] .scene-base { background: linear-gradient(180deg, #050818 0%, #0d1638 46%, #1d2c5e 100%); }
[data-scene="dawn"] { --accent: #ffd9a3; --table-a: #8a5a4a; --table-b: #3a2638; }
[data-scene="dawn"] .scene-base {
  background:
    linear-gradient(180deg, transparent 52%, rgba(14, 8, 14, 0.62) 100%),
    radial-gradient(90% 38% at 50% 100%, rgba(255, 170, 96, 0.6), transparent 72%),
    linear-gradient(180deg, #171c40 0%, #35295a 42%, #6d3e5c 74%, #a85f4c 100%);
}
[data-scene="masque"] { --accent: #f0d896; --table-a: #2f6b54; --table-b: #133428; }
[data-scene="masque"] .scene-base {
  background:
    radial-gradient(70% 34% at 50% -4%, rgba(255, 196, 110, 0.3), transparent 72%),
    radial-gradient(120% 70% at 50% 108%, rgba(12, 44, 36, 0.8), transparent 70%),
    linear-gradient(180deg, #1c4a3b 0%, #112b25 46%, #091412 100%);
}

.stars {
  background-image:
    radial-gradient(1.2px 1.2px at 12% 9%, #fff, transparent 60%), radial-gradient(1px 1px at 27% 21%, #dbe6ff, transparent 60%),
    radial-gradient(1.4px 1.4px at 43% 6%, #fff, transparent 60%), radial-gradient(1px 1px at 58% 17%, #cfe0ff, transparent 60%),
    radial-gradient(1.2px 1.2px at 71% 8%, #fff, transparent 60%), radial-gradient(1px 1px at 86% 24%, #e8efff, transparent 60%),
    radial-gradient(1px 1px at 8% 34%, #cfe0ff, transparent 60%), radial-gradient(1.3px 1.3px at 34% 39%, #fff, transparent 60%),
    radial-gradient(1px 1px at 64% 33%, #fff, transparent 60%), radial-gradient(1.2px 1.2px at 92% 41%, #dbe6ff, transparent 60%),
    radial-gradient(1px 1px at 19% 52%, #fff, transparent 60%), radial-gradient(1px 1px at 79% 55%, #cfe0ff, transparent 60%);
  animation: twinkle 5s ease-in-out infinite;
}
.stars-2 { transform: scale(-1, 1) translateY(4%); opacity: 0.7; animation-duration: 7s; animation-delay: -3s; }
.scene-moon {
  position: absolute;
  top: 9.500%;
  right: 5%;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 34%, #fffdf2, #e7ecff 55%, #b8c6f0);
  box-shadow: 0 0 60px 18px rgba(190, 210, 255, 0.28), inset -8px -6px 14px rgba(120, 140, 200, 0.4);
  animation: moon-rise 1.4s var(--ease-out) both;
}
.scene-sun {
  position: absolute;
  left: 50%;
  bottom: -70px;
  width: 260px;
  height: 260px;
  margin-left: -130px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 236, 190, 0.95), rgba(255, 190, 110, 0.55) 45%, transparent 70%);
  animation: sun-rise 2.2s var(--ease-out) both;
}
.scene-village {
  top: auto;
  height: 46%;
  background: url("../assets/night-web-v1.webp") center 78% / cover no-repeat;
  opacity: 0.34;
  mask-image: linear-gradient(180deg, transparent 0%, #000 55%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 55%);
}
.scene-village.is-day { opacity: 0.2; mix-blend-mode: luminosity; }

.embers i {
  position: absolute;
  bottom: -10px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffc77a;
  box-shadow: 0 0 8px 2px rgba(255, 170, 80, 0.6);
  opacity: 0;
  animation: ember 9s linear infinite;
}
.embers i:nth-child(1) { left: 12%; animation-delay: 0s; }
.embers i:nth-child(2) { left: 28%; animation-delay: -3.2s; animation-duration: 11s; }
.embers i:nth-child(3) { left: 44%; animation-delay: -6.1s; }
.embers i:nth-child(4) { left: 58%; animation-delay: -1.7s; animation-duration: 12s; }
.embers i:nth-child(5) { left: 71%; animation-delay: -4.8s; }
.embers i:nth-child(6) { left: 85%; animation-delay: -7.5s; animation-duration: 10s; }
.embers i:nth-child(7) { left: 93%; animation-delay: -2.4s; animation-duration: 13s; }

/* ── page frame ──────────────────────────────────────────────────────────── */
.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: none;
  padding: calc(var(--safe-top) + 8px) 12px 8px 14px;
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; text-align: left; color: var(--accent); }
.topbar-text { display: grid; min-width: 0; }
.topbar-text b { font-family: var(--font-display); font-size: 16.500px; letter-spacing: 0.04em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-text small { font-size: 11.500px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-tools { display: flex; align-items: center; gap: 6px; flex: none; }

.view { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; animation: view-in 0.45s var(--ease-out) both; }
.view-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.view-scroll > * { flex-shrink: 0; }
.view-scroll::-webkit-scrollbar { display: none; }

.dock {
  position: relative;
  z-index: 4;
  flex: none;
  padding: 10px 14px calc(var(--safe-bottom) + 14px);
  background: linear-gradient(180deg, transparent, rgba(8, 6, 9, 0.72) 34%, rgba(8, 6, 9, 0.9));
}
.dock-hint { margin-bottom: 8px; text-align: center; font-size: 12px; color: var(--text-dim); }
.dock-row { display: flex; align-items: stretch; gap: 10px; }
.dock-main { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: stretch; }
.dock-main > .btn { flex: 1; min-width: 0; }
.dock-main > .btn.is-side { flex: 0 0 auto; padding: 0 16px; }
.dock-side {
  flex: none;
  width: 54px;
  min-height: 54px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  border-radius: 16px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: transform 0.12s, background 0.2s;
}
.dock-side:active { transform: scale(0.94); background: rgba(255, 255, 255, 0.12); }
.dock-side.is-empty { visibility: hidden; }
.dock-side em { font-style: normal; font-size: 10.500px; letter-spacing: 0.08em; color: var(--text-dim); }
.mini-card {
  width: 17px;
  height: 24px;
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, rgba(236, 208, 143, 0.5) 0 1.500px, transparent 1.500px 5px), linear-gradient(160deg, #7b2f3d, #3a1420);
  box-shadow: inset 0 0 0 1.500px var(--gold-3), 0 2px 5px rgba(0, 0, 0, 0.5);
}
.dock-wait {
  flex: 1;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 16px;
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px var(--line-soft);
}

.offline-bar {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 6px;
  padding: 8px 10px 8px 12px;
  border-radius: 12px;
  font-size: 12.500px;
  color: #ffe6c2;
  background: rgba(150, 70, 30, 0.6);
  box-shadow: inset 0 0 0 1px rgba(255, 190, 120, 0.4);
  animation: drop-in 0.35s var(--ease-out) both;
}
.offline-bar span { flex: 1; min-width: 0; }
.offline-bar button { flex: none; padding: 4px 10px; border-radius: 8px; font-weight: 600; background: rgba(255, 255, 255, 0.16); }

.closed {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 40px 32px;
  text-align: center;
  color: var(--accent);
}
.closed h1 { font-size: 40px; color: var(--text); letter-spacing: 0.14em; }
.closed p { max-width: 280px; color: var(--text-dim); }
.closed .btn { margin-top: 12px; min-width: 200px; }

.icon-btn.is-dev { color: #1c1206; background: linear-gradient(180deg, #ffd87a, #e09a2c); box-shadow: none; }
.dev-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 6px 10px; border-radius: 10px; font-size: 12.500px; color: var(--gold-3); text-decoration: none; background: rgba(236, 208, 143, 0.08); }

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