:root {
  --gold: #f4c95d;
  --ink: #f7ead2;
  --muted: #bfae8d;
  --bg: #130d08;
  --panel: #24170d;
  --panel2: #302013;
  --line: rgba(244, 201, 93, 0.22);
  --good: #69d689;
  --bad: #ff756f;
  --warn: #ffb84d;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "Microsoft YaHei", serif;
  background:
    linear-gradient(180deg, rgba(19, 13, 8, .70), rgba(19, 13, 8, .96)),
    radial-gradient(90% 45% at 50% 0%, rgba(146, 72, 24, 0.55), transparent 68%),
    var(--game-bg-art),
    linear-gradient(180deg, #201107, var(--bg));
  background-size: auto, auto, cover, auto;
  background-position: center, center, center top, center;
  background-attachment: fixed;
  line-height: 1.45;
}

#app {
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(180deg, rgba(19, 13, 8, 0.96), rgba(19, 13, 8, 0.76));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 24px; color: var(--gold); letter-spacing: 1px; }
.topbar p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  background: linear-gradient(180deg, #392516, #21150c);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
  transition: transform .1s ease, filter .15s ease, opacity .15s ease;
  cursor: pointer;
}
button:active { transform: scale(.97); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: .42; filter: grayscale(.45); cursor: not-allowed; }
.ghost-btn { padding: 8px 14px; color: var(--gold); background: rgba(255,255,255,.04); }

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 14px 16px 8px;
}
.status-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  gap: 0 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(62, 39, 22, .92), rgba(31, 20, 12, .92));
  box-shadow: var(--shadow);
  animation: softPop .28s ease both;
}
.status-icon { grid-row: 1 / 3; align-self: center; font-size: 26px; }
.status-card small { color: var(--muted); font-size: 11px; }
.status-card strong { font-size: 16px; color: #fff3d7; }

.risk-card { padding: 4px 16px 12px; }
.risk-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
.risk-head strong { color: var(--ink); }
.risk-track {
  height: 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(0,0,0,.38);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.45);
}
#riskFill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--good), #d9ef73);
  transition: width .35s ease, background .2s ease;
}
#riskFill.warn { background: linear-gradient(90deg, var(--warn), #ff8c42); }
#riskFill.danger { background: linear-gradient(90deg, #ff544f, #b4001b); }

@keyframes softPop {
  from { opacity: .78; transform: translateY(4px) scale(.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes dangerPulse {
  0%, 100% { box-shadow: inset 0 2px 5px rgba(0,0,0,.45); }
  50% { box-shadow: 0 0 0 3px rgba(255, 84, 79, .22), inset 0 2px 5px rgba(0,0,0,.45); }
}
.risk-track:has(#riskFill.danger) { animation: dangerPulse .9s ease-in-out infinite; }

.content { padding: 0 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.hero-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 104px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(90deg, rgba(48, 32, 19, .96), rgba(29, 18, 10, .78));
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero-panel img {
  width: 78px;
  height: 90px;
  object-fit: contain;
  align-self: flex-end;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,.45));
}
.hero-panel strong { color: var(--gold); font-size: 18px; }
.hero-panel p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 15px;
  background: linear-gradient(180deg, rgba(48, 32, 19, .96), rgba(29, 18, 10, .96));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.04);
}
.panel h2 { margin: 0 0 8px; font-size: 18px; color: var(--gold); }
.panel h3 { margin: 14px 0 8px; font-size: 14px; color: #ffe4a3; }
.muted, .panel p { color: var(--muted); font-size: 13px; }

.choice-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.choice-card {
  width: 100%;
  text-align: left;
  padding: 14px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 2px 10px;
  background: linear-gradient(180deg, #432918, #25170d);
}
.choice-card.response { grid-template-columns: 42px 1fr; }
.choice-card.has-art { grid-template-columns: 88px 1fr auto; min-height: 120px; }
.choice-icon { grid-row: 1 / 4; font-size: 30px; align-self: center; }
.stock-art {
  width: 78px;
  height: 96px;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(244,201,93,.22);
}
.stock-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.choice-card strong { font-size: 16px; color: #fff4dc; }
.choice-card em {
  align-self: start;
  justify-self: end;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--gold);
  font-size: 11px;
  font-style: normal;
  background: rgba(244, 201, 93, .12);
}
.choice-card.response em { justify-self: start; }
.choice-card p { grid-column: 2 / -1; margin: 3px 0 8px; }
.fx-row { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.fx-row b {
  padding: 3px 7px;
  border-radius: 8px;
  background: rgba(0,0,0,.26);
  font-size: 11px;
  color: #ffe8b0;
}

.event-desc, .rival-desc {
  padding: 12px;
  border-radius: 14px;
  background: rgba(0,0,0,.22);
  border: 1px dashed var(--line);
}
.rival-desc {
  border-color: rgba(255,117,111,.34);
  background: rgba(255,117,111,.08);
  color: #ffd7d3;
  font-size: 13px;
}
.summary-box {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(244, 201, 93, .1);
  border: 1px solid rgba(244, 201, 93, .18);
}
.summary-box span { color: var(--muted); }
.primary-btn {
  width: 100%;
  margin-top: 12px;
  min-height: 54px;
  color: #271606;
  background: linear-gradient(180deg, #ffe08a, var(--gold));
  border: none;
  box-shadow: 0 8px 22px rgba(244, 201, 93, .25);
}

.level-now { display: flex; gap: 12px; align-items: center; }
.level-now span { font-size: 34px; }
.level-now strong { color: #fff4dc; }
.level-now p { margin: 3px 0 0; }
.upgrade-btn {
  width: 100%;
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  color: var(--gold);
}
.upgrade-btn span { color: var(--muted); font-size: 12px; }

.rescue-list { display: flex; flex-direction: column; gap: 8px; }
.rescue-btn { width: 100%; display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; }
.rescue-btn span { color: var(--muted); font-size: 12px; }
.tutorial { margin-top: 12px; padding: 11px; border-radius: 14px; background: rgba(255,255,255,.05); }
.tutorial strong { color: var(--gold); }
.tutorial p { margin: 4px 0 0; }

.log { max-height: 180px; overflow-y: auto; padding-right: 3px; }
.log-line { padding: 7px 0; border-bottom: 1px dashed rgba(255,255,255,.08); color: var(--muted); font-size: 12px; }
.log-line span { color: var(--gold); font-weight: 800; margin-right: 8px; }

.toast-layer {
  position: fixed;
  left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  opacity: 0;
  transform: translateY(10px);
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(26, 16, 9, .96);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  box-shadow: var(--shadow);
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.good { border-color: rgba(105,214,137,.55); }
.toast.bad { border-color: rgba(255,117,111,.65); }
.toast.info { border-color: rgba(244,201,93,.55); }

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 6, 3, .76);
  backdrop-filter: blur(4px);
}
.modal-layer[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 440px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px 18px 18px;
  background: linear-gradient(180deg, #3b2616, #1b1008);
  box-shadow: 0 20px 70px rgba(0,0,0,.62);
}
.ending-icon { font-size: 48px; }
.modal small { color: var(--gold); font-weight: 800; }
.modal h2 { margin: 8px 0; color: #fff1c9; }
.modal p { color: var(--muted); }
.ending-stats { margin: 14px 0; color: var(--gold); font-size: 13px; }

.risk-tip {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.book-card {
  min-height: 86px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  background: rgba(0,0,0,.2);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  text-align: center;
}
.book-card.open {
  border-color: rgba(244,201,93,.34);
  background: rgba(244,201,93,.08);
  color: var(--ink);
}
.book-card span { font-size: 24px; }
.book-card strong { font-size: 13px; }
.book-card small { font-size: 10px; color: var(--muted); }

@media (min-width: 460px) {
  .status-grid { grid-template-columns: repeat(3, 1fr); }
  .book-grid { grid-template-columns: repeat(3, 1fr); }
}
