:root {
  --ink: #14100c;
  --ink-2: #1d1712;
  --ink-3: #241c15;
  --paper: #e9dcc3;
  --paper-dim: #a39478;
  --cinnabar: #a63a2b;
  --cinnabar-bright: #c84b38;
  --gold: #c9a45c;
  --green: #7f9a6a;
  --blue: #5b8fb5;
  --line: rgba(233, 220, 195, 0.16);
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", "STSong", serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  background: radial-gradient(ellipse at 50% 0%, #241b13 0%, var(--ink) 55%, #0d0a08 100%);
  color: var(--paper);
  font-family: var(--font-serif);
  line-height: 1.8;
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.3;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.025) 0, transparent 30%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.02) 0, transparent 35%);
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

button {
  font-family: var(--font-serif);
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
}

/* ---------- 开始画面 ---------- */

#start-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  overflow-y: auto;
}

.title-block {
  margin-bottom: 44px;
  position: relative;
}

.seal {
  position: absolute;
  top: -18px;
  right: calc(50% - 112px);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f2e2c8;
  font-size: 15px;
  letter-spacing: 2px;
  background: var(--cinnabar);
  border-radius: 8px 8px 8px 2px;
  box-shadow: 0 4px 14px rgba(166, 58, 43, 0.45);
  transform: rotate(-6deg);
  writing-mode: vertical-rl;
}

.title-vertical {
  font-size: 52px;
  font-weight: 600;
  letter-spacing: 16px;
  text-indent: 16px;
  color: var(--paper);
  text-shadow: 0 0 32px rgba(201, 164, 92, 0.25);
  writing-mode: vertical-rl;
  height: 220px;
  margin: 0 auto;
}

.subtitle {
  margin-top: 6px;
  color: var(--gold);
  letter-spacing: 8px;
  text-indent: 8px;
  font-size: 14px;
}

.slots {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.slot-btn {
  width: 100px;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.25s, background 0.25s, transform 0.15s;
}

.slot-btn:active {
  transform: scale(0.96);
}

.slot-btn:hover {
  border-color: var(--cinnabar-bright);
  background: rgba(200, 75, 56, 0.08);
}

.slot-name {
  font-size: 14px;
}

.slot-status {
  font-size: 11px;
  color: var(--paper-dim);
  line-height: 1.5;
}

.start-hint {
  margin-top: 36px;
  font-size: 12px;
  color: var(--paper-dim);
  letter-spacing: 2px;
}

.budget-hint {
  margin-top: 8px;
  font-size: 12px;
  color: rgba(201, 164, 92, 0.8);
}

/* ---------- 顶栏 ---------- */

#topbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(20, 16, 12, 0.92);
  backdrop-filter: blur(6px);
  z-index: 20;
  flex-shrink: 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.topbar-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.loc-name {
  font-size: 14.5px;
  letter-spacing: 1px;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loc-zone {
  font-size: 9.5px;
  color: var(--paper-dim);
  letter-spacing: 2px;
  margin-top: 1px;
}

.topbar-mid {
  display: flex;
  flex-direction: row;
  gap: 6px;
  width: 100%;
  flex-shrink: 0;
}

.bar {
  position: relative;
  height: 12px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 6px;
  overflow: hidden;
}

.bar span.fill {
  display: block;
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s ease;
}

.bar.hp span.fill {
  background: linear-gradient(90deg, #8c2f22, #d2573f);
}

.bar.mp span.fill {
  background: linear-gradient(90deg, #2c5578, #5b8fb5);
}

.bar .bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  letter-spacing: 0.5px;
  color: rgba(233, 220, 195, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.money {
  font-size: 12.5px;
  color: var(--gold);
  white-space: nowrap;
  margin-right: 2px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  font-size: 15px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 故事流 ---------- */

#story {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px 24px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.para {
  margin-bottom: 16px;
  animation: fadeUp 0.5s ease both;
}

.para.narrator {
  font-size: 16.5px;
  text-indent: 2em;
  letter-spacing: 0.02em;
}

.para.system {
  font-size: 13.5px;
  color: var(--gold);
  text-indent: 0;
  padding: 2px 10px;
  border-left: 2px solid rgba(201, 164, 92, 0.5);
  background: rgba(201, 164, 92, 0.06);
  border-radius: 0 6px 6px 0;
}

.para.dialog {
  font-size: 15.5px;
  color: #d9c9ad;
  text-indent: 2em;
}

.para .speaker {
  display: block;
  font-size: 12px;
  color: var(--cinnabar-bright);
  letter-spacing: 2px;
  margin-bottom: 2px;
}

.goal-chip {
  display: inline-block;
  font-size: 12px;
  color: var(--gold);
  border: 1px solid rgba(201, 164, 92, 0.35);
  border-radius: 999px;
  padding: 3px 12px;
  margin-bottom: 16px;
  letter-spacing: 1px;
  background: rgba(201, 164, 92, 0.06);
  animation: fadeUp 0.5s ease both;
}

.scene-sep {
  text-align: center;
  color: var(--paper-dim);
  font-size: 12px;
  margin: 18px 0;
  letter-spacing: 8px;
  animation: fadeUp 0.5s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 选项面板 ---------- */

#choices {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  max-height: 46vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(13, 10, 8, 0.94) 26%);
  z-index: 15;
  border-top: 1px solid rgba(233, 220, 195, 0.08);
}

.choices-title {
  font-size: 11px;
  color: var(--paper-dim);
  letter-spacing: 4px;
  text-align: center;
  margin-bottom: 10px;
}

.choice-btn {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-size: 15px;
  border-radius: 9px;
  border: 1px solid rgba(233, 220, 195, 0.24);
  background: rgba(233, 220, 195, 0.045);
  transition: border-color 0.2s, background 0.2s, transform 0.12s;
  margin-bottom: 8px;
}

.choice-btn:last-child {
  margin-bottom: 0;
}

.choice-btn:hover {
  border-color: var(--cinnabar-bright);
}

.choice-btn:active {
  transform: scale(0.985);
  background: rgba(200, 75, 56, 0.12);
}

.choice-tag {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--gold);
  border: 1px solid rgba(201, 164, 92, 0.35);
  border-radius: 6px;
  padding: 2px 8px;
  letter-spacing: 1px;
}

.choice-text {
  flex: 1;
  line-height: 1.5;
}

.choice-btn.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ---------- 抽屉 ---------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(92vw, 400px);
  background: var(--ink-2);
  border-left: 1px solid var(--line);
  z-index: 40;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.25s ease both;
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  letter-spacing: 3px;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 9px 0;
  font-size: 13px;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--paper-dim);
}

.tab.active {
  color: var(--gold);
  border-bottom-color: var(--cinnabar);
  background: rgba(166, 58, 43, 0.1);
}

.tab-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-cell {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
}

.stat-cell .k {
  font-size: 11px;
  color: var(--paper-dim);
  letter-spacing: 1px;
}

.stat-cell .v {
  font-size: 15px;
  color: var(--gold);
  margin-top: 2px;
}

.stat-cell.wide {
  grid-column: span 2;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 14px;
}

.item-sub {
  font-size: 11px;
  color: var(--paper-dim);
  margin-top: 1px;
}

.item-use {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--gold);
  min-height: 36px;
  padding: 6px 16px;
  border-radius: 7px;
}

.tech-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.tech-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tech-name {
  font-size: 14px;
  color: var(--gold);
}

.tech-type {
  font-size: 10px;
  color: var(--paper-dim);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 6px;
}

.tech-desc {
  font-size: 12px;
  color: var(--paper-dim);
  margin-top: 5px;
  line-height: 1.6;
}

/* ---------- 地图 ---------- */

.map-intro {
  font-size: 11px;
  color: var(--paper-dim);
  letter-spacing: 1px;
  margin-bottom: 12px;
  line-height: 1.6;
}

.map-zone {
  margin-bottom: 18px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(233, 220, 195, 0.08);
  border-radius: 12px;
  padding: 10px;
}

.map-zone-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.map-zone-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.map-zone-name {
  font-size: 16px;
  color: var(--gold);
  letter-spacing: 4px;
  font-weight: 600;
  text-indent: 4px;
}

.map-zone-sub {
  font-size: 10.5px;
  color: var(--paper-dim);
  letter-spacing: 1px;
}

.map-zone-line {
  flex: 1;
  height: 1px;
  background: rgba(201, 164, 92, 0.25);
}

.map-loc {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.2s;
}

.map-loc.current {
  border-color: var(--cinnabar);
  background: rgba(166, 58, 43, 0.09);
}

.map-loc.unknown {
  opacity: 0.6;
}

.map-loc-main {
  flex: 1;
  min-width: 0;
}

.map-loc-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  flex-wrap: wrap;
}

.map-loc-name .cur-badge {
  font-size: 10px;
  color: #fff;
  background: var(--cinnabar-bright);
  border-radius: 5px;
  padding: 1px 8px;
  letter-spacing: 1px;
}

.map-loc-desc {
  font-size: 12px;
  color: #bfae8f;
  margin-top: 2px;
  line-height: 1.5;
}

.role-badge {
  flex-shrink: 0;
  font-size: 11px;
  border-radius: 5px;
  padding: 2px 9px;
  letter-spacing: 1px;
  border: 1px solid;
}

.role-badge.role-客栈 { color: #e0b978; border-color: rgba(224, 185, 120, 0.4); }
.role-badge.role-武馆 { color: #d97a68; border-color: rgba(217, 122, 104, 0.4); }
.role-badge.role-医馆 { color: #9cbb86; border-color: rgba(156, 187, 134, 0.4); }
.role-badge.role-镖局 { color: #84b4d8; border-color: rgba(132, 180, 216, 0.4); }
.role-badge.role-帮派 { color: #c98d8d; border-color: rgba(201, 141, 141, 0.4); }
.role-badge.role-集市 { color: #d8ab72; border-color: rgba(216, 171, 114, 0.4); }
.role-badge.role-城门 { color: #b7a98d; border-color: rgba(183, 169, 141, 0.4); }
.role-badge.role-庙宇 { color: #b39ddb; border-color: rgba(179, 157, 219, 0.4); }
.role-badge.role-酒楼 { color: #dba6bd; border-color: rgba(219, 166, 189, 0.4); }
.role-badge.role-险地 { color: #a8927a; border-color: rgba(168, 146, 122, 0.4); }
.role-badge.role-野外 { color: #8fa87c; border-color: rgba(143, 168, 124, 0.4); }

.map-go {
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--gold);
  min-width: 56px;
  min-height: 32px;
  padding: 5px 12px;
  border-radius: 7px;
}

/* ---------- 战斗 ---------- */

.combat-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(ellipse at 50% 20%, #221a12 0%, #100c09 70%);
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}

.battlefield {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 14px 8px;
  gap: 6px;
  min-height: 0;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 46%;
}

.side.enemy {
  align-items: flex-end;
}

.unit-card {
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.35s ease;
}

.unit-card.lunge-right {
  transform: translateX(12px);
}

.unit-card.lunge-left {
  transform: translateX(-12px);
}

.unit-card.hit {
  animation: hitFlash 0.45s ease;
}

@keyframes hitFlash {
  0% { filter: brightness(1); }
  30% { filter: brightness(2.2) saturate(0.3); }
  100% { filter: brightness(1); }
}

.unit-card.dead {
  opacity: 0.25;
  filter: grayscale(1);
  transition: opacity 0.6s, filter 0.6s;
}

.avatar {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  color: rgba(233, 220, 195, 0.85);
  border: 2px solid rgba(233, 220, 195, 0.25);
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.14), transparent 55%), linear-gradient(160deg, #3a2c20, #1d1510);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar[data-avatar="h"], .avatar[data-avatar="y"] {
  background: linear-gradient(160deg, #2f4a52, #17272c);
}

.avatar[data-avatar="b"] {
  background: linear-gradient(160deg, #4a2430, #1e0f14);
  border-color: var(--cinnabar);
}

.avatar[data-avatar="r"] {
  background: linear-gradient(160deg, #6b4a22, #2e1d0d);
}

.avatar[data-avatar="s"], .avatar[data-avatar="z"], .avatar[data-avatar="k"] {
  background: linear-gradient(160deg, #4a3a2b, #241b13);
}

.unit-name {
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 1px;
  white-space: nowrap;
}

.unit-bars {
  width: 100%;
  margin-top: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.unit-bar {
  height: 9px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  position: relative;
}

.unit-bar span {
  display: block;
  height: 100%;
  border-radius: 4px;
  transition: width 0.45s ease;
}

.unit-hp span {
  background: linear-gradient(90deg, #8c2f22, #d2573f);
}

.unit-mp span {
  background: linear-gradient(90deg, #2c5578, #5b8fb5);
}

.unit-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: rgba(233, 220, 195, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.status-icons {
  display: flex;
  gap: 3px;
  margin-top: 3px;
  min-height: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.status-icon {
  font-size: 10px;
  padding: 0 5px;
  border-radius: 4px;
  color: #f2d9c8;
  background: rgba(166, 58, 43, 0.75);
}

.status-icon.positive {
  background: rgba(44, 85, 120, 0.8);
}

.float-dmg {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  font-size: 17px;
  font-weight: 600;
  color: #f2e2c8;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
  animation: floatUp 0.9s ease-out both;
  z-index: 5;
}

.float-dmg.crit {
  color: #ffd27a;
  font-size: 20px;
}

@keyframes floatUp {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -42px); }
}

.combat-log {
  height: 24%;
  min-height: 110px;
  max-height: 28vh;
  overflow-y: auto;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  font-size: 13px;
  line-height: 1.7;
  -webkit-overflow-scrolling: touch;
}

.log-line {
  animation: fadeUp 0.3s ease both;
}

.log-line.twist {
  color: var(--gold);
}

.combat-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(13, 10, 8, 0.92);
  max-height: 30vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.combat-btn {
  min-height: 44px;
  font-size: 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(233, 220, 195, 0.05);
}

.combat-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.combat-btn.primary {
  border-color: var(--cinnabar);
  color: #f2d9c8;
}

.combat-btn .cd {
  display: block;
  font-size: 10px;
  color: var(--paper-dim);
  line-height: 1.4;
}

/* ---------- 加载与提示 ---------- */

.loading {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 10, 8, 0.75);
  backdrop-filter: blur(2px);
}

.loading-ink {
  font-size: 16px;
  letter-spacing: 6px;
  color: var(--gold);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.toast {
  position: fixed;
  left: 50%;
  top: 16%;
  transform: translateX(-50%);
  z-index: 90;
  max-width: 82%;
  padding: 9px 16px;
  font-size: 13px;
  background: rgba(30, 23, 18, 0.96);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--paper);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: fadeUp 0.3s ease both;
}

@media (min-width: 720px) {
  .para.narrator {
    font-size: 18px;
  }
  .avatar {
    width: 80px;
    height: 80px;
  }
  #choices {
    max-height: 40vh;
  }
}
