:root {
  --night: #f4ead3;
  --panel: #fff8ea;
  --panel-2: #efe2c8;
  --gold: #8b6914;
  --gold-dim: #6e5410;
  --cinnabar: #9b2335;
  --cinnabar-hot: #b02a28;
  --ink: #1c140c;
  --muted: #5c5346;
  --line: rgba(90, 60, 20, 0.22);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Iowan Old Style", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", sans-serif;
  --mono: "Sarasa Mono SC", "IBM Plex Mono", ui-monospace, monospace;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 70% -10%, rgba(155, 35, 53, 0.08), transparent 55%),
    radial-gradient(900px 500px at -10% 110%, rgba(201, 162, 74, 0.18), transparent 50%),
    var(--night);
  letter-spacing: 0.01em;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  z-index: 0;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 248, 234, 0.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--serif);
}
.brand .cn { font-size: 22px; font-weight: 700; }
.brand .en { font-size: 12px; color: var(--muted); letter-spacing: 0.18em; text-transform: uppercase; }

.nav {
  display: flex;
  gap: 18px;
  align-items: center;
  font-size: 14px;
}
.nav a { color: var(--ink); opacity: 0.78; }
.nav a.active, .nav a:hover { opacity: 1; color: var(--gold); text-decoration: none; }

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.page { width: min(1180px, calc(100% - 32px)); margin: 28px auto 80px; }

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  align-items: center;
  margin-bottom: 18px;
}
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1.12;
  margin: 0 0 12px;
}
.kicker {
  color: var(--cinnabar-hot);
  font-size: 12px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.lede { color: var(--muted); font-size: 16px; line-height: 1.7; max-width: 42em; }

.disclaimer {
  border: 1px solid rgba(155, 35, 53, 0.4);
  background: rgba(155, 35, 53, 0.08);
  color: var(--cinnabar-hot);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.55;
}

.star-wrap {
  position: relative;
  aspect-ratio: 1;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 50%, rgba(201,162,74,0.08), transparent 62%),
    var(--panel);
  overflow: hidden;
}
.star-wrap svg { width: 100%; height: 100%; display: block; }
.node-hit { cursor: pointer; }
.node-label { font-family: var(--serif); font-size: 13px; fill: var(--ink); pointer-events: none; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 22px;
}
.school-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  min-height: 118px;
}
.school-card:hover { border-color: var(--gold); }
.school-card h3 { margin: 0 0 6px; font-family: var(--serif); font-size: 18px; }
.school-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.school-card.selected { outline: 2px solid var(--gold); }

.seat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 18px;
}
button, .chip {
  font: inherit;
  color: var(--ink);
}
.chip {
  appearance: none;
  border: 1px solid #c4a35a;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  line-height: 1.35;
  background: #fff8ea;
  color: #1c140c;
  cursor: pointer;
}
.chip.on {
  background: #f3d98a;
  color: #1c140c;
  border-color: #8b6914;
  font-weight: 700;
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
button.chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary {
  appearance: none;
  border: 0;
  background: linear-gradient(180deg, #d4b05a, #9a7428);
  color: #1a1408;
  font-weight: 700;
  border-radius: 999px;
  padding: 11px 20px;
  cursor: pointer;
  font-family: var(--sans);
}
.primary:disabled { opacity: 0.45; cursor: not-allowed; }

.ghost {
  appearance: none;
  background: #fff8ea;
  border: 1px solid #c4a35a;
  color: #1c140c;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font: inherit;
}

textarea, input, select {
  width: 100%;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.span-2 { grid-column: span 2; }

.msg {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 12px 0;
  white-space: pre-wrap;
  line-height: 1.7;
}
.msg .who { font-family: var(--serif); color: var(--gold); margin-bottom: 6px; }

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(40, 28, 16, 0.38);
  z-index: 50;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow: auto;
}
.settings-overlay.open { display: flex; }
.settings-panel {
  width: min(760px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
}
.settings-panel h2 { font-family: var(--serif); margin: 0 0 8px; color: var(--gold); }
.settings-panel h3 { font-family: var(--serif); margin: 22px 0 8px; color: var(--gold); font-size: 18px; }
.settings-profile-bar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin: 16px 0;
}
.settings-profile-bar label { flex: 1; min-width: 220px; }
.settings-profile-actions { display: flex; gap: 8px; }
.settings-mini {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}
.settings-mini.danger { color: #b02a28; border-color: rgba(176, 42, 40, 0.45); }
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.settings-wide { grid-column: 1 / -1; }
.settings-preferences, .settings-skills { margin-top: 8px; }
.settings-preferences-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
.skill-add { display: flex; gap: 8px; align-items: center; }
.skill-add input { flex: 1; }
.skill-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
.status { font-size: 13px; min-height: 1.4em; }
.tongue-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 8px;
}
.tongue-preview {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  flex: 0 0 auto;
}
.tongue-fields { flex: 1; min-width: 0; }
.status.ok { color: #2f7a3e; }
.status.err { color: #b02a28; }

.school-page { display: grid; grid-template-columns: 280px 1fr; gap: 22px; }
.school-list a { display: block; padding: 10px 12px; color: var(--ink); border-radius: 10px; }
.school-list a:hover, .school-list a.active { background: var(--panel-2); text-decoration: none; color: var(--gold); }

@media (max-width: 900px) {
  .hero, .school-page, .form-grid, .card-grid, .settings-grid, .settings-preferences-grid { grid-template-columns: 1fr; }
  .span-2, .settings-wide { grid-column: span 1; }
  .topbar { flex-wrap: wrap; }
  .nav { width: 100%; order: 3; gap: 12px; overflow-x: auto; }
}

.drift { width: 100%; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); }

html[data-theme="paper"] { color-scheme: light; }
html[data-theme="ink"] { color-scheme: dark; }

html[data-theme="ink"] {
  --night: #141210;
  --panel: #1e1a16;
  --panel-2: #2a241c;
  --gold: #d4b05a;
  --gold-dim: #c9a24a;
  --cinnabar: #e85d4c;
  --cinnabar-hot: #ff7a6a;
  --ink: #f4ead3;
  --muted: #b8a990;
  --line: rgba(212, 176, 90, 0.22);
}
html[data-theme="ink"] body {
  background:
    radial-gradient(1200px 700px at 70% -10%, rgba(155, 35, 53, 0.18), transparent 55%),
    radial-gradient(900px 500px at -10% 110%, rgba(201, 162, 74, 0.12), transparent 50%),
    var(--night);
}
html[data-theme="ink"] .topbar {
  background: rgba(20, 18, 16, 0.92);
}
html[data-theme="ink"] .chip,
html[data-theme="ink"] .ghost,
html[data-theme="ink"] .primary {
  color: #1c140c;
}
html[data-theme="ink"] .chip,
html[data-theme="ink"] .ghost {
  background: #fff8ea;
  border-color: #c4a35a;
}
html[data-theme="ink"] .chip.on {
  background: #f3d98a;
  color: #1c140c;
  border-color: #8b6914;
}

.hero.stage .kicker { letter-spacing: 0.42em; }
.hero.stage h1 { text-wrap: balance; }
.stage-note { color: var(--muted); font-size: 13px; margin: 14px 0 0; }
.hero.stage .star-wrap {
  box-shadow: 0 0 0 1px var(--line), 0 28px 70px rgba(28, 20, 12, 0.14);
}

.table-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(240px, 0.75fr);
  gap: 20px;
  margin-top: 22px;
  align-items: stretch;
}
.table-board { position: relative; }
.table-ring {
  position: relative;
  aspect-ratio: 1;
  min-height: 380px;
  color: var(--ink);
  border-radius: 50%;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 50%, rgba(155, 35, 53, 0.1) 0 34%, transparent 35%),
    radial-gradient(circle at 50% 42%, var(--panel-2), var(--panel));
  box-shadow:
    inset 0 0 0 12px rgba(139, 105, 20, 0.16),
    0 22px 50px rgba(28, 20, 12, 0.12);
  overflow: hidden;
}
.table-ring svg { width: 100%; height: 100%; display: block; color: inherit; }
.table-felt { fill: rgba(155, 35, 53, 0.06); }
.table-well { fill: var(--night); fill-opacity: 0.35; }
.seat-dot.speaking {
  transform-box: fill-box;
  transform-origin: center;
  animation: seat-speak 1.15s ease-in-out infinite;
}
@keyframes seat-speak {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(201, 162, 74, 0.2)); }
  50% { transform: scale(1.16); filter: drop-shadow(0 0 10px rgba(201, 162, 74, 0.85)); }
}
.table-log {
  overflow: auto;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
}
.table-log:empty::before {
  content: "开撞后，发言会出现在桌心。";
  color: var(--muted);
  font-size: 13px;
}
.table-log .msg {
  background: transparent;
  border: 0;
  border-bottom: 1px dashed var(--line);
  border-radius: 0;
  margin: 0;
  padding: 8px 2px;
  font-size: 12px;
}
.table-log .msg:last-child { border-bottom: 0; }
.table-side .hint { font-family: var(--mono); letter-spacing: 0.12em; }
@media (min-width: 901px) {
  .table-log {
    position: absolute;
    inset: 27%;
    border-radius: 18px;
  }
}
@media (max-width: 900px) {
  .table-stage { grid-template-columns: 1fr; }
  .table-log {
    position: relative;
    max-height: 42vh;
    border-radius: var(--radius);
    margin-top: 12px;
  }
  .table-ring { min-height: 300px; }
}

.archive-list { display: grid; gap: 8px; margin-top: 12px; }
.archive-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 4px 12px 12px 4px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.65;
}
.archive-card .who {
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
  font-family: var(--serif);
}

html[data-motion="off"] * { animation: none !important; transition: none !important; }
[hidden] { display: none !important; }
