:root {
  --ink-950: #071816;
  --ink-900: #0b2421;
  --ink-800: #12352f;
  --ink-700: #1b4a40;
  --jade-500: #2f9276;
  --jade-300: #84c7aa;
  --paper: #f4f0df;
  --paper-deep: #ded4b6;
  --gold: #e7bd62;
  --gold-deep: #9d6f28;
  --red: #b64b3f;
  --blue: #5b9fb2;
  --text: #f8f3e5;
  --muted: #b9c9bf;
  --line: rgba(226, 199, 126, .25);
  --shadow: 0 18px 50px rgba(0, 10, 8, .35);
  font-family: "Noto Serif SC", "Songti SC", SimSun, serif;
  color: var(--text);
  background: var(--ink-950);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--ink-950); }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 78% 12%, rgba(77, 142, 116, .22), transparent 30%),
    linear-gradient(145deg, #071816 0%, #133a34 48%, #071b19 100%);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.start-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(3, 20, 17, .86), rgba(6, 31, 27, .38)),
    url("assets/bg-cultivation.webp") center / cover no-repeat;
}

.start-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(4, 24, 21, .08), rgba(3, 19, 17, .5));
}

.start-screen::after {
  content: "";
  position: absolute;
  inset: auto -6vw -18vh -6vw;
  height: 48vh;
  background: radial-gradient(ellipse at center, rgba(190, 222, 207, .2), transparent 66%);
  filter: blur(16px);
}

.start-panel {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: .88fr 1.12fr;
  background: rgba(7, 28, 24, .88);
  border: 1px solid rgba(231, 189, 98, .35);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.start-story {
  padding: 58px 44px;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(26, 81, 64, .4), rgba(6, 27, 24, .78));
}

.seal {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid #c96857;
  color: #f6b7a7;
  font-weight: 800;
  line-height: 1;
  transform: rotate(-4deg);
}

.game-title {
  margin: 28px 0 12px;
  font-size: clamp(46px, 6vw, 76px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0;
}

.start-story p { color: var(--muted); font-size: 17px; line-height: 1.9; }
.chapter-mark { color: var(--gold); font-weight: 700; }

.create-form { padding: 42px; background: rgba(8, 29, 26, .95); }
.create-form h2 { margin: 0 0 26px; font-size: 28px; }
.field { margin-bottom: 24px; }
.field > label, .field-label { display: block; margin-bottom: 10px; color: var(--paper-deep); font-size: 15px; }

.text-input {
  width: 100%;
  border: 1px solid rgba(231, 189, 98, .28);
  background: rgba(244, 240, 223, .08);
  color: #fff;
  padding: 13px 14px;
  outline: none;
  border-radius: 4px;
}
.text-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(231, 189, 98, .12); }

.choice-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.choice-grid.origins { grid-template-columns: repeat(2, 1fr); }

.choice-card {
  min-height: 72px;
  border: 1px solid rgba(244, 240, 223, .16);
  border-radius: 5px;
  background: rgba(255, 255, 255, .035);
  color: var(--text);
  padding: 10px 8px;
  text-align: center;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.choice-card:hover { transform: translateY(-2px); border-color: rgba(231, 189, 98, .65); }
.choice-card.active { border-color: var(--gold); background: rgba(231, 189, 98, .14); box-shadow: inset 0 0 0 1px rgba(231, 189, 98, .28); }
.choice-card strong { display: block; font-size: 16px; margin-bottom: 5px; }
.choice-card small { color: var(--muted); font-size: 11px; line-height: 1.4; }

.primary-btn,
.action-btn,
.ghost-btn,
.card-btn,
.shop-btn {
  border-radius: 4px;
  border: 1px solid transparent;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
.primary-btn:hover:not(:disabled), .action-btn:hover:not(:disabled), .card-btn:hover:not(:disabled), .shop-btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.primary-btn { width: 100%; padding: 14px 18px; background: var(--gold); color: #2a2112; font-weight: 800; font-size: 17px; }
.continue-btn { margin-top: 10px; background: transparent; color: var(--gold); border: 1px solid rgba(231, 189, 98, .45); }

.game-shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 9px 22px;
  background: rgba(5, 24, 21, .94);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 182px; }
.brand .seal { width: 38px; height: 38px; font-size: 14px; }
.brand-name { font-size: 22px; font-weight: 800; }
.resource-strip { display: flex; align-items: center; gap: 8px; flex: 1; }
.resource { padding: 7px 11px; border-left: 1px solid var(--line); color: var(--muted); font-size: 14px; white-space: nowrap; }
.resource strong { color: var(--text); margin-left: 5px; }
.top-actions { display: flex; gap: 7px; }
.ghost-btn { padding: 8px 12px; color: var(--paper); border-color: rgba(244, 240, 223, .18); background: rgba(255, 255, 255, .035); }
.ghost-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .09); }
.audio-btn.on { color: #ffe4a0; border-color: rgba(231, 189, 98, .52); }

.game-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 270px;
  min-height: 0;
}

.side-nav, .profile-panel { background: rgba(7, 29, 25, .92); }
.side-nav { border-right: 1px solid var(--line); padding: 20px 12px; overflow-y: auto; }
.side-heading { margin: 0 9px 12px; color: var(--gold); font-size: 13px; font-weight: 700; }
.location-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 10px;
  margin-bottom: 6px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  text-align: left;
}
.location-btn:hover:not(:disabled) { background: rgba(255,255,255,.04); color: #fff; }
.location-btn.active { background: rgba(47, 146, 118, .17); border-color: rgba(132, 199, 170, .28); color: #fff; }
.location-btn.locked { opacity: .42; }
.loc-icon { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--gold); font-size: 13px; }
.loc-copy strong { display: block; font-size: 15px; }
.loc-copy small { color: #8aa095; font-size: 11px; }

.main-stage { min-width: 0; display: flex; flex-direction: column; background: #0c2c27; }
.scene-art {
  position: relative;
  min-height: 390px;
  flex: 1;
  overflow: hidden;
  isolation: isolate;
  background: #183e36 url("assets/bg-cultivation.webp") center / cover no-repeat;
}
.scene-cloudsea,
.scene-starfall {
  background:
    linear-gradient(180deg, rgba(20, 69, 79, .08), rgba(5, 31, 28, .48)),
    url("assets/bg-cloudsea.webp") center / cover no-repeat;
}
.scene-flamecave {
  background:
    linear-gradient(180deg, rgba(40, 10, 5, .05), rgba(14, 7, 5, .5)),
    url("assets/bg-flamecave.webp") center / cover no-repeat;
}
.scene-tribulation {
  background:
    linear-gradient(180deg, rgba(7, 24, 28, .08), rgba(3, 18, 18, .55)),
    url("assets/bg-battle.webp") center / cover no-repeat;
}
.scene-art::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, rgba(4, 25, 21, .18), transparent 52%, rgba(4, 25, 21, .14));
}
.scene-art::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, transparent 55%, rgba(5, 22, 20, .78));
}

.scene-copy {
  width: min(610px, calc(100% - 48px));
  position: absolute;
  left: 28px;
  bottom: 28px;
  padding: 22px 24px;
  background: rgba(5, 25, 22, .82);
  border-left: 3px solid var(--gold);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.scene-kicker { color: var(--gold); font-size: 13px; font-weight: 700; }
.scene-copy h1 { margin: 4px 0 8px; font-size: clamp(26px, 3vw, 40px); }
.scene-copy p { margin: 0; color: #cbd9d0; line-height: 1.75; }
.scene-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.action-btn { padding: 10px 16px; background: var(--jade-500); color: #fff; font-weight: 700; }
.action-btn.gold { background: var(--gold); color: #2b2214; }
.action-btn.danger { background: var(--red); }
.action-btn.subtle { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.15); }

.story-log { min-height: 164px; max-height: 210px; padding: 17px 22px; background: rgba(5, 23, 21, .96); border-top: 1px solid var(--line); overflow: auto; }
.log-title { display: flex; justify-content: space-between; color: var(--gold); font-size: 13px; margin-bottom: 8px; }
.log-list { display: grid; gap: 5px; }
.log-entry { color: #aebfb5; font-size: 13px; line-height: 1.55; }
.log-entry:first-child { color: var(--paper); }

.profile-panel { border-left: 1px solid var(--line); padding: 20px 18px; overflow-y: auto; }
.portrait-row { display: flex; align-items: center; gap: 13px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.portrait { width: 62px; height: 62px; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--gold); background: linear-gradient(145deg, #367966, #102f2a); font-size: 25px; color: #fff; }
.player-name { margin: 0 0 4px; font-size: 21px; }
.realm { color: var(--gold); font-size: 13px; }
.stat-block { padding: 16px 0; border-bottom: 1px solid var(--line); }
.stat-row { display: flex; justify-content: space-between; gap: 12px; margin: 8px 0; color: var(--muted); font-size: 13px; }
.stat-row strong { color: var(--text); }
.bar-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin: 10px 0 5px; }
.bar { height: 8px; background: rgba(255,255,255,.08); overflow: hidden; border-radius: 2px; }
.bar > i { display: block; height: 100%; background: var(--jade-300); transition: width .25s ease; }
.bar.hp > i { background: #d26758; }
.bar.qi > i { background: #58a7bb; }
.bar.cultivation > i { background: var(--gold); }
.root-line { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 9px; }
.root-chip { padding: 4px 7px; font-size: 11px; border: 1px solid var(--line); color: var(--paper-deep); }
.inventory-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 10px; }
.inventory-item { padding: 8px; background: rgba(255,255,255,.035); font-size: 12px; color: var(--muted); }
.inventory-item strong { color: var(--text); float: right; }
.breakthrough-btn { width: 100%; margin-top: 14px; padding: 11px 10px; background: var(--gold); color: #2a2112; border: 0; border-radius: 4px; font-weight: 800; }

.combat-screen { display: flex; flex-direction: column; min-height: 100%; background: #0b2824; }
.combat-field {
  position: relative;
  min-height: 360px;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 50px;
  padding: 40px 8%;
  background:
    linear-gradient(180deg, rgba(8, 27, 28, .12), rgba(4, 22, 20, .72)),
    url("assets/bg-battle.webp") center / cover no-repeat;
}
.fighter { position: relative; text-align: center; }
.fighter-art { width: 150px; height: 180px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 50% 50% 45% 45%; font-size: 72px; color: #eaf2e8; text-shadow: 0 10px 25px rgba(0,0,0,.45); }
.fighter.player .fighter-art { background: radial-gradient(circle at 50% 35%, #4da386, #163c35 70%); }
.fighter.enemy .fighter-art { background: radial-gradient(circle at 50% 35%, #b66c51, #3d211c 70%); }
.fighter h2 { margin: 4px 0; }
.fighter-meta { color: var(--muted); font-size: 13px; }
.combat-bar { width: min(260px, 100%); margin: 8px auto; }
.damage-pop { position: absolute; top: 16%; left: 50%; color: #ffe28f; font-size: 28px; font-weight: 800; animation: floatUp .7s ease both; pointer-events: none; }
@keyframes floatUp { from { opacity: 0; transform: translate(-50%, 12px); } 25% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -34px); } }

.technique-tray { padding: 16px 20px 20px; background: rgba(5, 22, 20, .98); border-top: 1px solid var(--line); }
.combat-status { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.technique-cards { display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 10px; }
.card-btn { min-height: 112px; padding: 11px; text-align: left; color: #1f2b27; background: var(--paper); border-color: var(--paper-deep); position: relative; }
.card-btn strong { display: block; margin-bottom: 7px; font-size: 16px; }
.card-btn small { display: block; min-height: 34px; color: #57635d; line-height: 1.45; }
.card-cost { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: #327d8e; color: #fff; font: 700 12px Arial; }
.card-element { margin-top: 8px; color: var(--gold-deep); font-size: 11px; font-weight: 700; }

.overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; background: rgba(1, 12, 10, .76); backdrop-filter: blur(5px); }
.overlay.encounter {
  background:
    linear-gradient(180deg, rgba(2, 13, 18, .26), rgba(1, 10, 12, .7)),
    url("assets/bg-encounter.webp") center / cover no-repeat;
  backdrop-filter: none;
}
.overlay.encounter .modal { background: rgba(8, 35, 33, .9); backdrop-filter: blur(8px); }
.modal { width: min(620px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto; padding: 28px; background: #102f2a; border: 1px solid rgba(231, 189, 98, .45); box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 12px; color: var(--paper); }
.modal p { color: var(--muted); line-height: 1.75; }
.modal-actions { display: grid; gap: 9px; margin-top: 20px; }
.modal-actions .action-btn { width: 100%; text-align: left; padding: 13px 15px; }
.modal-actions .action-btn small { display: block; opacity: .78; font-size: 11px; margin-top: 4px; }
.shop-list { display: grid; gap: 9px; margin-top: 18px; }
.shop-item { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; padding: 13px; border: 1px solid var(--line); background: rgba(255,255,255,.025); }
.shop-item strong { display: block; color: var(--paper); }
.shop-item small { color: var(--muted); }
.shop-btn { padding: 9px 12px; background: var(--gold); color: #282012; font-weight: 700; }
.close-btn { width: 100%; margin-top: 16px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translate(-50%, 20px); padding: 10px 16px; background: #f1e6c8; color: #152821; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1050px) {
  .game-grid { grid-template-columns: 150px minmax(0, 1fr) 230px; }
  .resource:nth-child(n+4) { display: none; }
  .technique-cards { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  .start-screen { padding: 0; }
  .start-panel { min-height: 100dvh; display: block; border: 0; }
  .start-story { min-height: 240px; padding: 28px 22px 22px; border: 0; }
  .game-title { font-size: 48px; }
  .start-story p { font-size: 14px; line-height: 1.65; }
  .create-form { padding: 24px 18px 34px; }
  .choice-grid { grid-template-columns: repeat(3, 1fr); }
  .choice-grid.origins { grid-template-columns: 1fr 1fr; }
  .choice-card { min-height: 68px; padding: 8px 5px; }

  .topbar { min-height: 58px; padding: 7px 10px; gap: 8px; position: relative; }
  .brand { min-width: auto; }
  .brand .seal { width: 34px; height: 34px; }
  .brand-name { font-size: 17px; white-space: nowrap; }
  .resource-strip { justify-content: flex-end; gap: 0; }
  .resource { padding: 5px 7px; font-size: 11px; }
  .resource:nth-child(n+3) { display: none; }
  .top-actions .ghost-btn { padding: 7px 8px; font-size: 12px; }
  .top-actions .save-btn { display: none; }

  .game-grid { display: flex; flex-direction: column; }
  .side-nav { order: 0; display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; padding: 7px 8px; border: 0; border-bottom: 1px solid var(--line); scrollbar-width: none; }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-heading { display: none; }
  .location-btn { min-width: 84px; flex-direction: column; gap: 3px; padding: 7px 5px; margin: 0; text-align: center; }
  .loc-icon { width: 27px; height: 27px; }
  .loc-copy strong { font-size: 12px; }
  .loc-copy small { display: none; }

  .main-stage { order: 1; min-height: 0; }
  .scene-art { min-height: 430px; }
  .scene-copy { width: calc(100% - 24px); left: 12px; bottom: 12px; padding: 16px; }
  .scene-copy h1 { font-size: 27px; }
  .scene-copy p { font-size: 13px; line-height: 1.6; }
  .scene-actions { gap: 7px; }
  .action-btn { flex: 1 1 42%; padding: 11px 8px; font-size: 13px; text-align: center; }
  .story-log { min-height: 135px; max-height: 160px; padding: 13px 15px; }

  .profile-panel { order: 2; border: 0; border-top: 1px solid var(--line); padding: 15px; }
  .portrait-row { padding-bottom: 11px; }
  .portrait { width: 48px; height: 48px; }
  .stat-block { padding: 9px 0; }
  .profile-panel .stat-block:last-child { display: none; }
  .inventory-grid { grid-template-columns: repeat(4, 1fr); }

  .combat-field { min-height: 410px; gap: 12px; padding: 25px 14px; }
  .combat-field { background-position: center; }
  .fighter-art { width: 105px; height: 130px; font-size: 52px; }
  .fighter h2 { font-size: 17px; }
  .technique-tray { padding: 12px 10px 16px; }
  .technique-cards { display: flex; overflow-x: auto; gap: 8px; scroll-snap-type: x mandatory; }
  .card-btn { min-width: 138px; scroll-snap-align: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
