:root {
  color-scheme: dark;
  --bg: #101119;
  --panel: rgba(24, 25, 37, 0.9);
  --text: #fff6e5;
  --muted: rgba(255, 246, 229, 0.7);
  --line: rgba(255, 220, 157, 0.22);
  --gold: #f1c667;
  --rose: #ff8f9f;
  --aqua: #8be4e0;
  --ink: #11121a;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    linear-gradient(150deg, rgba(139, 228, 224, 0.14), transparent 32%),
    linear-gradient(230deg, rgba(255, 143, 159, 0.13), transparent 36%),
    radial-gradient(circle at 50% -12%, rgba(241, 198, 103, 0.12), transparent 26%),
    #101119;
  user-select: none;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

h1,
h2,
p {
  margin-top: 0;
}

.page-shell {
  width: min(460px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.app {
  min-height: calc(100vh - 16px);
}

.start-hero,
.route-select,
.novel-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.32);
}

.start-hero {
  position: relative;
  min-height: 250px;
  padding: 16px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(15, 16, 26, 0.28), rgba(16, 17, 25, 0.92)),
    linear-gradient(135deg, #242235, #12131d);
}

.hero-scene {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.9;
}

.moon {
  position: absolute;
  right: 26px;
  top: 24px;
  width: 70px;
  height: 70px;
  border: 1px solid rgba(241, 198, 103, 0.44);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 246, 229, 0.78), rgba(241, 198, 103, 0.16) 42%, transparent 66%);
}

.server-tower {
  position: absolute;
  right: 80px;
  bottom: 38px;
  width: 54px;
  height: 128px;
  border: 1px solid rgba(139, 228, 224, 0.3);
  border-radius: 8px 8px 2px 2px;
  background:
    repeating-linear-gradient(180deg, rgba(139, 228, 224, 0.18) 0 8px, transparent 8px 17px),
    rgba(8, 12, 20, 0.62);
}

.frozen-lake {
  position: absolute;
  left: -30px;
  right: -30px;
  bottom: -36px;
  height: 120px;
  border-top: 1px solid rgba(139, 228, 224, 0.38);
  background:
    linear-gradient(110deg, transparent 20%, rgba(139, 228, 224, 0.24) 21%, transparent 23%),
    linear-gradient(170deg, transparent 54%, rgba(255, 246, 229, 0.12) 55%, transparent 57%),
    rgba(139, 228, 224, 0.08);
  transform: skewY(-5deg);
}

.signal-line {
  position: absolute;
  left: 28px;
  width: 160px;
  height: 1px;
  background: rgba(255, 143, 159, 0.42);
  transform-origin: left;
}

.line-a {
  top: 92px;
  transform: rotate(10deg);
}

.line-b {
  top: 132px;
  transform: rotate(-7deg);
}

.start-hero > *:not(.hero-scene) {
  position: relative;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.brand-line img {
  width: 30px;
  height: 30px;
}

.brand-line.compact {
  min-width: 0;
}

.brand-line.compact span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.start-hero h1 {
  max-width: 250px;
  margin: 58px 0 10px;
  font-size: clamp(1.9rem, 8.6vw, 2.55rem);
  line-height: 1.06;
}

.start-hero p {
  max-width: 310px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.route-select {
  display: grid;
  gap: 10px;
  margin-top: 8px;
  padding: 10px;
}

.name-field {
  display: grid;
  gap: 5px;
}

.name-field span {
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 900;
}

.name-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: rgba(7, 8, 14, 0.62);
  user-select: text;
}

.focus-card {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 10px;
  min-height: 126px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--route), transparent 58%);
  border-radius: 8px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--route), transparent 82%), rgba(255, 255, 255, 0.04)),
    rgba(7, 8, 14, 0.38);
}

.portrait,
.scene-art strong {
  display: grid;
  place-items: center;
  color: var(--ink);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--route), var(--accent));
  font-weight: 900;
}

.portrait {
  min-height: 104px;
  font-size: 2.4rem;
}

.focus-card span {
  display: block;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
}

.focus-card h2 {
  margin: 3px 0 6px;
  font-size: 1.38rem;
}

.focus-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.44;
}

.route-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.route-card {
  display: grid;
  gap: 4px;
  min-height: 92px;
  padding: 8px 5px;
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--route), transparent 60%);
  border-radius: 8px;
  background: rgba(7, 8, 14, 0.42);
  text-align: center;
}

.route-card.selected {
  color: var(--ink);
  background: linear-gradient(135deg, var(--route), var(--accent));
}

.route-card span {
  font-weight: 900;
}

.route-card strong {
  font-size: 0.9rem;
}

.route-card small {
  overflow: hidden;
  color: inherit;
  opacity: 0.78;
  font-size: 0.66rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.primary-action {
  min-height: 46px;
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #ffeab1);
  font-weight: 900;
}

.home-rank-board {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 8, 14, 0.35);
}

.home-rank-head,
.progress-head,
.section-head,
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.home-rank-head strong,
.section-head strong {
  color: var(--gold);
  font-size: 0.84rem;
}

.home-rank-head span,
.section-head span {
  color: var(--muted);
  font-size: 0.68rem;
}

.home-rank-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.home-rank-row {
  display: grid;
  grid-template-columns: 21px minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
  min-height: 26px;
  padding: 4px 5px;
  border: 1px solid rgba(255, 220, 157, 0.13);
  border-radius: 7px;
  background: rgba(255, 246, 229, 0.045);
}

.home-rank-row.empty {
  opacity: 0.48;
}

.home-rank-row em {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--ink);
  border-radius: 6px;
  background: var(--gold);
  font-size: 0.62rem;
  font-style: normal;
  font-weight: 900;
}

.home-rank-row strong,
.home-rank-row span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.home-rank-row strong {
  font-size: 0.68rem;
}

.home-rank-row span {
  color: var(--gold);
  font-size: 0.66rem;
  font-weight: 900;
}

.novel-stage > * {
  min-width: 0;
}

.novel-stage {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto auto auto;
  gap: 7px;
  min-height: calc(100vh - 16px);
  padding: 8px;
  overflow: hidden;
  background:
    linear-gradient(150deg, color-mix(in srgb, var(--route), transparent 88%), transparent 42%),
    linear-gradient(225deg, color-mix(in srgb, var(--accent), transparent 88%), transparent 42%),
    var(--panel);
}

.top-bar button,
.quick-actions button,
.sheet-head button,
.ending-card button {
  min-height: 44px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 246, 229, 0.08);
  font-size: 0.74rem;
  font-weight: 900;
}

.status-strip,
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.status-strip div,
.stat-grid div,
.progress-card,
.choice-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 8, 14, 0.36);
}

.status-strip div,
.stat-grid div {
  display: grid;
  place-items: center;
  min-height: 42px;
}

.status-strip span,
.stat-grid span {
  color: var(--muted);
  font-size: 0.66rem;
}

.status-strip strong,
.stat-grid strong {
  max-width: 100%;
  overflow: hidden;
  font-size: 0.8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stat-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.stat-grid .danger strong {
  color: var(--rose);
}

.scene-panel {
  position: relative;
  display: grid;
  grid-template-rows: minmax(190px, 1fr) auto;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 246, 229, 0.06), rgba(7, 8, 14, 0.18)),
    rgba(7, 8, 14, 0.3);
}

.scene-art {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 190px;
  overflow: hidden;
}

.scene-art .halo {
  position: absolute;
  width: 220px;
  height: 220px;
  border: 1px solid color-mix(in srgb, var(--route), transparent 58%);
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--route), transparent 65%), transparent 64%);
  animation: scene-in 0.5s ease-out;
}

.scene-art strong {
  position: relative;
  width: 106px;
  height: 136px;
  font-size: 3rem;
  box-shadow: 0 22px 38px rgba(0, 0, 0, 0.28);
}

.scene-art em {
  position: absolute;
  bottom: 16px;
  color: var(--accent);
  font-style: normal;
  font-weight: 900;
}

.dialogue-box {
  margin: 0 8px 8px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--route), transparent 55%);
  border-radius: 8px;
  background: rgba(16, 17, 25, 0.88);
  animation: scene-in 0.22s ease-out;
}

.dialogue-box span {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
}

.dialogue-box h2 {
  margin: 3px 0 7px;
  font-size: 1.08rem;
}

.dialogue-box p {
  max-height: 144px;
  margin: 0;
  overflow: auto;
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.58;
}

.dialogue-box small {
  display: block;
  margin-top: 7px;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 900;
}

.progress-card {
  padding: 7px;
}

.progress-head span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.progress-head strong {
  color: var(--gold);
  font-size: 0.78rem;
}

.progress-track {
  height: 7px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 246, 229, 0.12);
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--route), var(--gold));
}

.route-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.route-strip button,
.choice-grid button,
.gift-list button,
.dungeon-list button {
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 8, 14, 0.38);
}

.route-strip button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 5px;
  align-items: center;
  min-height: 44px;
  padding: 5px;
}

.route-strip button.active {
  border-color: color-mix(in srgb, var(--route), transparent 32%);
  background: color-mix(in srgb, var(--route), transparent 78%);
}

.route-strip span,
.choice-grid span,
.gift-list span,
.dungeon-list span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: var(--ink);
  border-radius: 7px;
  background: linear-gradient(135deg, var(--route, var(--gold)), var(--accent, #ffeab1));
  font-size: 0.76rem;
  font-weight: 900;
}

.route-strip strong,
.route-strip small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.route-strip strong {
  font-size: 0.78rem;
}

.route-strip small {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
}

.choice-panel {
  display: grid;
  gap: 6px;
  padding: 7px;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.choice-grid button {
  display: grid;
  gap: 3px;
  justify-items: center;
  min-height: 78px;
  padding: 6px 3px;
  text-align: center;
}

.choice-grid strong,
.choice-grid small {
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.choice-grid strong {
  font-size: 0.78rem;
}

.choice-grid small {
  color: var(--muted);
  font-size: 0.62rem;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.quick-actions button {
  min-height: 40px;
  padding: 0 3px;
  color: var(--ink);
  border: 0;
  background: linear-gradient(135deg, var(--gold), #ffeab1);
}

.sheet-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  align-items: end;
  padding: 10px;
  background: rgba(0, 0, 0, 0.58);
  animation: fade-in 0.16s ease-out;
}

.bottom-sheet {
  width: min(460px, 100%);
  max-height: min(78vh, 700px);
  max-height: min(78dvh, 700px);
  margin: 0 auto;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 246, 229, 0.08), rgba(255, 246, 229, 0.035)),
    #12131d;
  box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.45);
  animation: sheet-rise 0.18s ease-out;
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  background: rgba(18, 19, 29, 0.95);
  border-bottom: 1px solid var(--line);
}

.sheet-head div {
  min-width: 0;
}

.sheet-head strong,
.sheet-head span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sheet-head span {
  color: var(--muted);
  font-size: 0.7rem;
}

.gift-list,
.dungeon-list,
.log-list {
  display: grid;
  gap: 7px;
  margin: 8px;
}

.gift-list button,
.dungeon-list button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 7px;
  min-height: 68px;
  padding: 8px;
  text-align: left;
}

.gift-list button.disabled {
  opacity: 0.46;
}

.gift-list strong,
.gift-list small,
.dungeon-list strong,
.dungeon-list small {
  display: block;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.gift-list small,
.dungeon-list small {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.68rem;
}

.dungeon-copy,
.ending-card {
  margin: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 8, 14, 0.36);
}

.dungeon-copy p,
.ending-card p,
.log-list p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.52;
}

.dungeon-copy small {
  display: block;
  margin-top: 7px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
}

.log-list article {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 246, 229, 0.045);
}

.log-list strong {
  color: var(--gold);
  font-size: 0.84rem;
}

.log-list small {
  display: block;
  margin-top: 5px;
  color: var(--aqua);
  font-size: 0.68rem;
}

.ending-card button {
  width: 100%;
  margin-top: 10px;
  color: var(--ink);
  border: 0;
  background: linear-gradient(135deg, var(--gold), #ffeab1);
}

@keyframes scene-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sheet-rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 380px) {
  .page-shell {
    padding: 6px;
  }

  .novel-stage {
    min-height: calc(100vh - 12px);
    gap: 5px;
    padding: 6px;
    grid-template-rows: auto auto auto auto auto auto auto auto;
  }

  .start-hero h1 {
    font-size: 1.82rem;
  }

  .focus-card {
    grid-template-columns: 66px minmax(0, 1fr);
  }

  .portrait {
    min-height: 108px;
  }

  .status-strip strong,
  .stat-grid strong {
    font-size: 0.72rem;
  }

  .choice-grid button {
    min-height: 72px;
  }

  .scene-panel {
    grid-template-rows: minmax(154px, 0.82fr) auto;
  }

  .scene-art {
    min-height: 154px;
  }

  .scene-art .halo {
    width: 178px;
    height: 178px;
  }

  .scene-art strong {
    width: 88px;
    height: 112px;
    font-size: 2.5rem;
  }

  .dialogue-box p {
    max-height: 120px;
  }

  .quick-actions button {
    font-size: 0.68rem;
  }
}

@media (min-width: 760px) {
  .page-shell {
    width: 460px;
    padding: 12px;
  }

  .novel-stage {
    min-height: calc(100vh - 24px);
  }
}
