:root {
  --haze: 0.4;
  --bg-clear: 205 216 224;
  --bg-haze: 196 164 120;
  --ink: #1f2328;
  --muted: #5f6670;
  --card: rgba(255, 255, 255, 0.86);
  --line: rgba(31, 35, 40, 0.12);
  --accent: #c8642e;
  --accent-ink: #fff;
  --ok: #3f9d5a;
  --mid: #d98a1c;
  --bad: #cf4a2c;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-clear: 30 38 46;
    --bg-haze: 70 52 34;
    --ink: #ece7df;
    --muted: #a8a196;
    --card: rgba(28, 26, 24, 0.84);
    --line: rgba(236, 231, 223, 0.14);
  }
}
:root[data-theme="dark"] {
  --bg-clear: 30 38 46;
  --bg-haze: 70 52 34;
  --ink: #ece7df;
  --muted: #a8a196;
  --card: rgba(28, 26, 24, 0.84);
  --line: rgba(236, 231, 223, 0.14);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

html {
  background: color-mix(in srgb, rgb(var(--bg-haze)) calc(var(--haze) * 70% + 20%), rgb(var(--bg-clear)));
}

body {
  min-height: 100vh;
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg,
    color-mix(in srgb, rgb(var(--bg-haze)) calc(var(--haze) * 100%), rgb(var(--bg-clear))) 0%,
    color-mix(in srgb, rgb(var(--bg-haze)) calc(var(--haze) * 70% + 20%), rgb(var(--bg-clear))) 100%);
}

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 40px; letter-spacing: 0.04em; }
h2 { font-size: 22px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
h3 { font-size: 17px; }
p { margin: 6px 0; }

.eyebrow { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.lead { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--bad); font-weight: 600; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

button {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.06); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions button { flex: 1 1 200px; padding: 14px; }
.actions.sticky { position: sticky; bottom: 12px; z-index: 5; }
.actions.sticky button { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); }

.chip {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--c);
  vertical-align: middle;
  white-space: nowrap;
}

/* Title */
.title-card h1 { font-size: 52px; }
.live { margin: 14px 0; padding: 14px; border-radius: 12px; border: 1px dashed var(--line); }
.live-label { font-size: 13px; color: var(--muted); }
.live-value { display: flex; align-items: center; gap: 12px; margin: 2px 0 6px; }
.live-value .big { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; }
.how { margin-top: 14px; }
.how summary { cursor: pointer; color: var(--muted); }
.how ul { padding-left: 20px; margin: 8px 0 0; }

/* Language toggle */
.title-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
button.lang { flex-shrink: 0; white-space: nowrap; padding: 2px 10px; font-size: 13px; font-weight: 600; border-radius: 999px; }

/* Status */
.status {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; position: sticky; top: 8px; z-index: 6;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.status-items { display: flex; gap: 14px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }

/* PSI card */
.psi-card { border-left: 6px solid var(--c); }
.psi-row { display: flex; align-items: center; gap: 12px; }
.psi-num { font-size: 56px; font-weight: 800; line-height: 1; color: var(--c); font-variant-numeric: tabular-nums; }

/* Event */
.event { border: 2px solid var(--accent); }
.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.choices button { text-align: left; }
.result { font-weight: 600; }

/* Members */
.member { margin: 10px 0; }
.member-head { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.member-head small { color: var(--muted); }
.bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.fill { height: 100%; border-radius: 999px; transition: width 0.4s; }
.fill.ok { background: var(--ok); }
.fill.mid { background: var(--mid); }
.fill.bad, .fill.low { background: var(--bad); }
.delta { font-size: 13px; font-weight: 600; margin-left: 4px; }

/* Shop */
.shop { display: flex; flex-direction: column; gap: 10px; }
.shop-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.shop-item button { min-width: 88px; }

/* Plan */
.plan label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; padding: 8px 10px; font-size: 14px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Night */
.ledger { margin-top: 10px; border-top: 1px solid var(--line); }
.ledger > div { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.ledger .total { font-weight: 700; }
.fact { border-left: 6px solid #6b8fb3; }

/* Shift */
.shift { display: flex; flex-direction: column; gap: 8px; }
.hud { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-variant-numeric: tabular-nums; }
.hud-time b { font-size: 20px; }
.hud-mask { margin-left: auto; font-size: 13px; color: var(--muted); }
.breath { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.breath .bar { flex: 1; height: 12px; }
.hud-task { font-weight: 600; }
.canvas-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
#game {
  display: block;
  width: 100%;
  height: min(68vh, 640px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(40, 30, 20, 0.45);
}
.overlay-card { background: var(--card); border-radius: var(--radius); padding: 18px; max-width: 380px; }
.overlay-card button { width: 100%; margin-top: 8px; padding: 12px; }

/* Ending */
.ending { text-align: center; }
.ending h1 { font-size: 40px; }
.score { font-size: 64px; font-weight: 800; color: var(--accent); line-height: 1.1; margin: 8px 0 14px; }
.score small { font-size: 20px; margin-left: 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.stats > div { border: 1px solid var(--line); border-radius: 10px; padding: 10px 4px; display: flex; flex-direction: column; }
.stats b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.chart { width: 100%; max-width: 420px; }
.svg-num { font-size: 11px; font-weight: 600; fill: var(--ink); }
.svg-day { font-size: 11px; fill: var(--muted); }
.tips { padding-left: 20px; margin: 0; }
.tips li { margin: 6px 0; }

.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 0 16px 24px; }

@media (max-width: 480px) {
  h1, .title-card h1 { font-size: 40px; }
  .psi-num { font-size: 46px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .status-items { gap: 10px; font-size: 14px; }
}
