:root {
  color-scheme: dark;
  --bg-deep: #08070c;
  --bg-panel: rgba(20, 14, 29, 0.92);
  --bg-panel-soft: rgba(36, 24, 45, 0.72);
  --line: rgba(230, 202, 142, 0.19);
  --gold: #e8c67a;
  --gold-bright: #ffe2a5;
  --red: #b9374a;
  --red-bright: #f05d6e;
  --purple: #76508e;
  --text: #f6f0e7;
  --muted: #b9adbd;
  --success: #78d7a6;
  --warning: #f1bd65;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
  --safe-top: max(16px, env(safe-area-inset-top));
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg-deep);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg-deep);
}

body {
  min-width: 320px;
  color: var(--text);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(255, 226, 165, 0.9);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.noscript-message {
  margin: 24px;
  padding: 16px;
  border: 1px solid var(--red-bright);
  background: #261119;
  color: #fff;
  text-align: center;
}

.app-shell {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--safe-top) 12px var(--safe-bottom);
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(118, 80, 142, 0.23), transparent 45%),
    linear-gradient(155deg, #09070d 0%, #110b18 48%, #08070c 100%);
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 42vmax;
  aspect-ratio: 1;
  border-radius: 999px;
  filter: blur(90px);
  opacity: 0.18;
  pointer-events: none;
}

.ambient-one {
  top: -20vmax;
  right: -15vmax;
  background: var(--red);
}

.ambient-two {
  bottom: -22vmax;
  left: -16vmax;
  background: var(--purple);
}

.game-frame {
  position: relative;
  width: min(100%, 480px);
  min-height: min(760px, calc(100dvh - var(--safe-top) - var(--safe-bottom)));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(30, 19, 38, 0.92), rgba(10, 8, 14, 0.98)),
    var(--bg-panel);
  box-shadow: var(--shadow);
}

.game-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.025), transparent),
    radial-gradient(circle at 50% 0%, rgba(232, 198, 122, 0.08), transparent 32%);
}

.scene {
  position: relative;
  z-index: 1;
  min-height: inherit;
  padding: 28px 22px;
}

.scene.is-active {
  animation: scene-in 320ms ease both;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.22em;
}

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

h1,
h2,
h3 {
  line-height: 1.18;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.5rem, 12vw, 4.3rem);
  font-weight: 900;
  letter-spacing: 0.06em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 7vw, 2.2rem);
}

h3 {
  margin-bottom: 6px;
}

.button {
  min-height: 50px;
  border: 1px solid transparent;
  border-radius: 15px;
  padding: 12px 18px;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

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

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

.button-primary {
  border-color: rgba(255, 226, 165, 0.35);
  background: linear-gradient(135deg, #8d2638, #c04453 48%, #7f263e);
  box-shadow: 0 14px 28px rgba(144, 35, 54, 0.25);
}

.button-primary:not(:disabled):hover {
  border-color: var(--gold-bright);
  transform: translateY(-1px);
}

.button-secondary {
  border-color: rgba(232, 198, 122, 0.34);
  background: linear-gradient(135deg, rgba(82, 57, 36, 0.8), rgba(45, 33, 34, 0.92));
}

.button-ghost,
.button-compact {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.button-danger {
  border-color: rgba(240, 93, 110, 0.55);
  background: rgba(111, 28, 43, 0.48);
  color: #ffdce1;
}

.button-wide {
  width: 100%;
}

.button-compact {
  min-height: 46px;
  padding-inline: 14px;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
}

.scene-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.loading-mark,
.title-emblem,
.hero-avatar {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 226, 165, 0.46);
  background:
    radial-gradient(circle at 32% 25%, rgba(255, 226, 165, 0.28), transparent 30%),
    linear-gradient(145deg, rgba(119, 26, 47, 0.92), rgba(27, 16, 39, 0.95));
  color: var(--gold-bright);
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.35), 0 18px 46px rgba(0, 0, 0, 0.32);
}

.loading-mark {
  width: 96px;
  height: 96px;
  margin-bottom: 28px;
  border-radius: 34% 66% 44% 56% / 48% 42% 58% 52%;
  font-size: 2.5rem;
  font-weight: 900;
}

.loading-copy {
  color: var(--muted);
}

.loading-track {
  width: min(290px, 82%);
  height: 7px;
  margin-top: 24px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
}

.loading-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red-bright), var(--gold));
  transition: width 110ms ease;
}

.loading-percent {
  margin-top: 10px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.scene-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.title-content {
  margin-block: auto;
}

.version-chip {
  display: inline-flex;
  margin-bottom: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.title-emblem {
  width: 110px;
  height: 110px;
  margin: 0 auto 24px;
  border-radius: 50%;
  font-size: 3rem;
  font-weight: 900;
  outline: 1px solid rgba(232, 198, 122, 0.14);
  outline-offset: 9px;
}

.title-tagline {
  max-width: 320px;
  margin: 0 auto 32px;
  color: var(--muted);
  line-height: 1.7;
}

.menu-stack {
  display: grid;
  gap: 12px;
}

.menu-stack .button {
  display: grid;
  gap: 2px;
}

.button-kicker {
  font-size: 0.63rem;
  letter-spacing: 0.14em;
  opacity: 0.72;
}

.save-summary {
  min-height: 42px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.title-footer {
  margin-top: 24px;
  color: rgba(185, 173, 189, 0.58);
  font-size: 0.7rem;
}

.scene-header,
.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}

.scene-header {
  justify-content: flex-start;
}

.character-preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 180px;
  margin-bottom: 18px;
}

.character-silhouette {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 112px;
  height: 142px;
  border: 1px solid rgba(232, 198, 122, 0.23);
  border-radius: 52% 52% 24% 24%;
  background: linear-gradient(160deg, rgba(71, 42, 83, 0.82), rgba(16, 11, 23, 0.98));
  box-shadow: 0 22px 45px rgba(0, 0, 0, 0.42);
  font-size: 2.25rem;
}

.character-aura {
  position: absolute;
  width: 180px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(185, 55, 74, 0.26), transparent 68%);
  filter: blur(12px);
}

.form-card,
.settings-card,
.story-card,
.hero-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-panel-soft);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.22);
}

.form-card {
  padding: 20px;
}

.form-card > label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px;
}

input[type="text"] {
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(232, 198, 122, 0.28);
  border-radius: 13px;
  padding: 10px 13px;
  background: rgba(5, 4, 8, 0.55);
  color: var(--text);
}

.field-help,
.settings-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

.field-help {
  margin: 8px 0 18px;
}

.starter-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  margin-bottom: 18px;
  padding: 15px;
  border: 1px solid rgba(118, 80, 142, 0.35);
  border-radius: 16px;
  background: rgba(118, 80, 142, 0.12);
}

.starter-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.starter-label {
  color: var(--gold) !important;
  font-size: 0.7rem !important;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.starter-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(185, 55, 74, 0.18);
  font-size: 1.4rem;
}

.hero-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  padding: 17px;
  margin-bottom: 18px;
}

.hero-avatar {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  font-size: 1.75rem;
  font-weight: 900;
}

.hero-name-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.hero-name-line h3 {
  margin: 0;
}

.level-badge {
  border: 1px solid rgba(232, 198, 122, 0.35);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
}

.resource-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.68rem;
}

.resource-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.resource-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.hp-bar {
  background: linear-gradient(90deg, #b9374a, #ef6c77);
}

.mp-bar {
  background: linear-gradient(90deg, #4c68aa, #7f98e1);
}

.village-grid {
  display: grid;
  gap: 14px;
}

.story-card {
  padding: 18px;
}

.story-card > p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.65;
}

.quest-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--gold);
  font-size: 0.8rem;
  font-weight: 800;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.feature-button {
  display: grid;
  justify-items: start;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.feature-button > span {
  margin-bottom: 9px;
  color: var(--gold);
  font-size: 1.35rem;
}

.feature-button small {
  margin-top: 3px;
  color: var(--muted);
}

.feature-primary {
  border-color: rgba(240, 93, 110, 0.35);
  background: linear-gradient(140deg, rgba(123, 31, 52, 0.56), rgba(59, 31, 58, 0.55));
}

.village-footer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.village-footer-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: right;
}

.settings-card {
  overflow: hidden;
  margin-bottom: 18px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-row span {
  display: grid;
  gap: 5px;
}

.setting-row small {
  color: var(--muted);
  line-height: 1.4;
}

.setting-row input[type="checkbox"] {
  width: 46px;
  height: 26px;
  accent-color: var(--red-bright);
}

.setting-slider {
  display: grid;
  align-items: stretch;
}

.setting-slider input {
  width: 100%;
  accent-color: var(--red-bright);
}

.settings-note {
  margin-top: 14px;
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 3, 6, 0.74);
  opacity: 0;
  transition: opacity 180ms ease;
}

.modal-backdrop.is-visible {
  opacity: 1;
}

.modal {
  width: min(100%, 390px);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  background: #17101f;
  box-shadow: var(--shadow);
}

.modal p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.65;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(calc(100% - 32px), 420px);
  transform: translate(-50%, 18px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 16px;
  background: rgba(24, 17, 31, 0.96);
  color: var(--text);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.42);
  opacity: 0;
  text-align: center;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast[data-tone="success"] {
  border-color: rgba(120, 215, 166, 0.45);
}

.toast[data-tone="warning"] {
  border-color: rgba(241, 189, 101, 0.52);
}

@media (min-width: 760px) {
  .app-shell {
    padding: 28px;
  }

  .game-frame {
    width: min(100%, 920px);
    min-height: min(720px, calc(100dvh - 56px));
  }

  .scene {
    padding: 42px 48px;
  }

  .scene-title .title-content {
    width: min(100%, 440px);
  }

  .scene-title {
    align-items: center;
  }

  .scene-create,
  .scene-settings {
    max-width: 620px;
    margin-inline: auto;
  }

  .scene-village {
    display: flex;
    flex-direction: column;
  }

  .village-grid {
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    align-items: stretch;
  }

  .story-card {
    min-height: 260px;
    display: flex;
    flex-direction: column;
  }

  .story-card .quest-meta {
    margin-top: auto;
  }

  .hero-card {
    max-width: 560px;
  }
}

@media (max-width: 370px) {
  .scene {
    padding-inline: 16px;
  }

  .hero-card {
    grid-template-columns: 1fr;
  }

  .hero-avatar {
    width: 58px;
    height: 58px;
  }
}
