/* ==========================================================================
   AI 文字冒险 · 视觉基调：夜读、羊皮纸、剧场灯光
   ========================================================================== */

:root {
  --bg: #0d0f14;
  --bg-soft: #14171f;
  --panel: #171b24;
  --panel-2: #1e232e;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e9e5dc;
  --text-dim: #a4a3a0;
  --text-faint: #6f7076;
  --accent: #e0a458;
  --accent-soft: rgba(224, 164, 88, 0.14);
  --danger: #d9534f;
  --ok: #4fae7a;
  --radius: 14px;
  --serif: "Songti SC", "Source Han Serif SC", "Noto Serif CJK SC", "Noto Serif SC", Georgia, "STSong", serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", system-ui, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(900px 500px at 50% -10%, rgba(224, 164, 88, 0.09), transparent 65%),
    radial-gradient(700px 400px at 100% 100%, rgba(65, 105, 225, 0.07), transparent 60%);
  background-attachment: fixed;
}

a {
  color: var(--accent);
}

button {
  font-family: inherit;
  cursor: pointer;
}

::selection {
  background: var(--accent-soft);
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
  background-clip: content-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}

.shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 22px 22px 60px;
}

.shell.game-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 10px;
}

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #2a2318, #171a22);
  border: 1px solid var(--line-strong);
  color: var(--accent);
  font-size: 17px;
}

.brand-name {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: 2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 1.6px;
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-faint);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 11.5px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.02);
  letter-spacing: 0.4px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.dot.off {
  background: var(--text-faint);
  box-shadow: none;
}

/* ---------------------------------------------------------------- 首页 */
.hero {
  padding: 36px 0 30px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 34px;
}

.hero-kicker {
  font-size: 11.5px;
  letter-spacing: 3px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 16px;
}

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(30px, 4.6vw, 50px);
  line-height: 1.24;
  margin: 0 0 16px;
  font-weight: 500;
  letter-spacing: 1px;
}

.hero h1 em {
  font-style: normal;
  color: var(--accent);
}

.hero p {
  max-width: 620px;
  color: var(--text-dim);
  line-height: 1.95;
  font-size: 14.5px;
  margin: 0;
}

.hero-meta {
  display: flex;
  gap: 26px;
  margin-top: 26px;
  flex-wrap: wrap;
}

.hero-meta div {
  font-size: 12px;
  color: var(--text-faint);
}

.hero-meta strong {
  display: block;
  font-family: var(--serif);
  font-size: 21px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 3px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 18px;
}

.section-head h2 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 1.5px;
  margin: 0;
}

.section-head span {
  font-size: 12px;
  color: var(--text-faint);
}

/* 模板卡 */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(262px, 1fr));
  gap: 16px;
  margin-bottom: 46px;
}

.tpl {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 20px 18px;
  background: linear-gradient(165deg, var(--panel), var(--bg-soft));
  overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-height: 232px;
}

.tpl::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(340px 180px at 100% 0%, var(--tpl-accent-soft, rgba(224, 164, 88, 0.1)), transparent 70%);
  opacity: 0.9;
  pointer-events: none;
}

.tpl:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.tpl-tag {
  font-size: 10.5px;
  letter-spacing: 2.4px;
  color: var(--tpl-accent, var(--accent));
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}

.tpl h3 {
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 500;
  margin: 0 0 8px;
  letter-spacing: 1px;
  position: relative;
  z-index: 1;
}

.tpl .sub {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 14px;
  position: relative;
  z-index: 1;
}

.tpl .world {
  font-size: 12.8px;
  line-height: 1.85;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.tpl .go {
  margin-top: auto;
  padding-top: 16px;
  font-size: 12.5px;
  color: var(--tpl-accent, var(--accent));
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.tpl .go i {
  font-style: normal;
  transition: transform 0.25s;
}

.tpl:hover .go i {
  transform: translateX(4px);
}

/* 存档列表 */
.saves {
  display: grid;
  gap: 10px;
}

.save {
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--panel);
}

.save:hover {
  border-color: var(--line-strong);
}

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

.save-name {
  font-family: var(--serif);
  font-size: 15px;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-meta {
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.save-meta b {
  color: var(--text-dim);
  font-weight: 400;
}

.tag-ended {
  color: var(--ok);
}

.tag-playing {
  color: var(--accent);
}

.save-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 26px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- 按钮 */
.btn {
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 15px;
  font-size: 12.5px;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.28);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1206;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.09);
  background: var(--accent);
}

.btn.ghost {
  border-color: transparent;
  color: var(--text-faint);
  padding: 8px 10px;
}

.btn.ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.btn.sm {
  padding: 6px 11px;
  font-size: 11.5px;
}

/* ---------------------------------------------------------------- 游戏页 */
.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 0 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.game-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.game-title h2 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  margin: 0;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-title .loc {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 4px;
}

.turn-badge {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 286px;
  gap: 20px;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

.play-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
}

/* 叙事区 */
.narrative {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), #12151c);
  padding: 8px 30px 26px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  position: relative;
}

.turn {
  padding: 24px 0 22px;
  border-bottom: 1px dashed var(--line);
  animation: fade-up 0.5s ease both;
}

.turn:last-child {
  border-bottom: none;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.turn-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 1.4px;
}

.turn-head .no {
  font-family: var(--mono);
  color: var(--accent);
}

.turn-head .scene {
  color: var(--text-dim);
}

.turn-input {
  font-size: 13px;
  color: var(--text-dim);
  border-left: 2px solid var(--accent-soft);
  padding: 2px 0 2px 12px;
  margin-bottom: 16px;
  line-height: 1.8;
}

.turn-input b {
  color: var(--accent);
  font-weight: 500;
  margin-right: 6px;
}

.prose {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 2.15;
  color: #e6e1d6;
  letter-spacing: 0.35px;
  white-space: pre-wrap;
  word-break: break-word;
}

.prose::after {
  content: "";
}

.streaming .prose::after {
  content: "▍";
  color: var(--accent);
  animation: blink 0.9s steps(1) infinite;
  margin-left: 1px;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.degraded-note {
  margin-top: 12px;
  font-size: 11px;
  color: var(--text-faint);
  border: 1px dashed var(--line);
  border-radius: 7px;
  padding: 6px 10px;
  display: inline-block;
}

/* 选项 */
.choices {
  display: grid;
  gap: 9px;
  flex: 0 0 auto;
}

.choice {
  text-align: left;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 15px;
  font-size: 13.5px;
  line-height: 1.6;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  transition: all 0.18s ease;
}

.choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateX(3px);
}

.choice i {
  font-style: normal;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  padding-top: 3px;
}

/* 输入区 */
.composer {
  margin-top: 0;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.7;
  outline: none;
  min-height: 42px;
  max-height: 120px;
  padding: 4px 6px;
}

.composer textarea::placeholder {
  color: var(--text-faint);
}

.composer .hint {
  font-size: 11px;
  color: var(--text-faint);
  padding: 0 6px 6px;
}

/* 侧栏 */
.aside {
  display: grid;
  gap: 14px;
  align-content: start;
  overflow-y: auto;
  max-height: 100%;
  padding-right: 2px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px 17px;
}

.card h4 {
  margin: 0 0 14px;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-faint);
  font-weight: 500;
}

.stat {
  margin-bottom: 13px;
}

.stat-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.stat-top b {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text);
  font-size: 11.5px;
}

.bar {
  height: 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.bar.hp span {
  background: linear-gradient(90deg, #b23a35, #e06c5b);
}

.bar.st span {
  background: linear-gradient(90deg, #2f6f5e, #4fae7a);
}

.gold {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--accent);
}

.inv {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 11.5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 8px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.02);
}

.chip.empty-chip {
  border-style: dashed;
  color: var(--text-faint);
}

.delta-pop {
  position: fixed;
  right: 44px;
  bottom: 130px;
  display: grid;
  gap: 5px;
  z-index: 50;
  pointer-events: none;
}

.delta-pop span {
  font-family: var(--mono);
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 6px;
  background: rgba(15, 17, 22, 0.92);
  border: 1px solid var(--line-strong);
  animation: pop-in 0.35s ease both;
}

.delta-pop .up {
  color: #e06c5b;
}

.delta-pop .down {
  color: #4fae7a;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------------------------------------------------------------- 结局 */
.ending-wrap {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 10, 0.82);
  backdrop-filter: blur(7px);
  display: grid;
  place-items: center;
  padding: 26px;
  z-index: 100;
  animation: fade-in 0.4s ease both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.ending-card {
  width: min(600px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: linear-gradient(175deg, #1b1f28, #10131a);
  padding: 38px 40px 30px;
  position: relative;
  overflow: hidden;
  max-height: 86vh;
  overflow-y: auto;
}

.ending-card::before {
  content: "";
  position: absolute;
  inset: -40% -20% auto;
  height: 220px;
  background: radial-gradient(closest-side, var(--accent-soft), transparent);
}

.ending-kicker {
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--accent);
  margin-bottom: 14px;
}

.ending-card h2 {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 500;
  margin: 0 0 20px;
  letter-spacing: 2px;
}

.ending-text {
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 2.1;
  color: var(--text-dim);
  white-space: pre-wrap;
}

.recap {
  margin-top: 24px;
  border-top: 1px dashed var(--line);
  padding-top: 18px;
}

.recap h5 {
  margin: 0 0 12px;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-faint);
  font-weight: 500;
}

.recap ol {
  margin: 0;
  padding-left: 20px;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 2;
}

.ending-actions {
  display: flex;
  gap: 10px;
  margin-top: 26px;
  flex-wrap: wrap;
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: #22262f;
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 12.5px;
  z-index: 200;
  animation: pop-in 0.3s ease both;
  max-width: 84vw;
}

.toast.bad {
  border-color: rgba(217, 83, 79, 0.5);
  color: #f0b7b5;
}

/* 骨架 */
.loading {
  display: grid;
  place-items: center;
  padding: 90px 0;
  color: var(--text-faint);
  font-size: 13px;
  gap: 14px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 900px) {
  .game-grid {
    grid-template-columns: 1fr;
    height: auto;
  }
  .aside {
    position: static;
    grid-template-columns: 1fr 1fr;
    display: grid;
    max-height: none;
  }
  .narrative {
    max-height: 62vh;
    min-height: 320px;
    padding: 6px 20px 22px;
  }
  .delta-pop {
    display: none;
  }
}

@media (max-width: 560px) {
  .shell {
    padding: 14px 14px 40px;
  }
  .hero {
    padding: 18px 0 24px;
    margin-bottom: 24px;
  }
  .hero-meta {
    gap: 18px;
  }
  .aside {
    grid-template-columns: 1fr;
  }
  .prose {
    font-size: 16px;
    line-height: 2.05;
  }
  .ending-card {
    padding: 26px 22px 22px;
  }
  .ending-card h2 {
    font-size: 24px;
  }
  .save {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .save-actions {
    justify-content: flex-end;
  }
}
