:root {
  --paper: #f7f0df;
  --paper-deep: #efe2c5;
  --ink: #231c18;
  --muted: #75675a;
  --red: #7d1824;
  --red-dark: #4b0e16;
  --gold: #b78a35;
  --gold-soft: #dfc27a;
  --green: #315b48;
  --shadow: rgba(58, 28, 20, 0.18);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(rgba(247, 240, 223, 0.82), rgba(239, 226, 197, 0.9)),
    radial-gradient(circle at top, rgba(183, 138, 53, 0.18), transparent 34rem),
    linear-gradient(180deg, #f9f3e5 0%, #efe2c5 100%);
  color: var(--ink);
  font-family: "Songti SC", "Noto Serif SC", "STSong", "SimSun", serif;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app {
  width: min(100%, 480px);
  min-height: 100svh;
  margin: 0 auto;
  background: rgba(247, 240, 223, 0.96);
  box-shadow: 0 0 28px var(--shadow);
  position: relative;
  overflow-x: hidden;
}

.screen {
  min-height: 100svh;
  padding: 18px 14px calc(82px + env(safe-area-inset-bottom));
}

.home {
  display: grid;
  align-content: center;
  gap: 28px;
  text-align: center;
  padding: 36px 24px;
}

.palace-frame {
  border: 1px solid rgba(183, 138, 53, 0.48);
  background:
    linear-gradient(90deg, rgba(125, 24, 36, 0.08), transparent 18%, transparent 82%, rgba(125, 24, 36, 0.08)),
    rgba(255, 252, 244, 0.52);
  padding: 26px 18px;
  border-radius: var(--radius);
  box-shadow: 0 16px 36px rgba(66, 35, 20, 0.12);
}

.seal {
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  color: var(--gold-soft);
  background: var(--red);
  border: 2px solid var(--gold);
  border-radius: 50%;
  font-size: 30px;
  line-height: 1;
}

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

h1 {
  font-size: clamp(34px, 10vw, 48px);
  letter-spacing: 0;
  color: var(--red-dark);
  line-height: 1.15;
}

.subtitle {
  margin-top: 18px;
  color: var(--muted);
  line-height: 1.85;
  font-size: 17px;
}

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

.btn {
  min-height: 48px;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: #fff9ed;
  color: var(--red-dark);
  padding: 12px 16px;
  box-shadow: 0 4px 0 rgba(183, 138, 53, 0.25);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(183, 138, 53, 0.25);
}

.btn.primary {
  background: linear-gradient(180deg, #8e2230, #63131d);
  color: #fff8e9;
  border-color: #c79a45;
}

.btn.ghost {
  background: transparent;
  box-shadow: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
}

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: linear-gradient(145deg, #fff7e9, #ddc079);
  color: var(--red-dark);
  font-size: 24px;
  flex: 0 0 auto;
}

.name-line {
  font-size: 19px;
  color: var(--red-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-line,
.day-pill,
.small {
  color: var(--muted);
  font-size: 13px;
}

.day-pill {
  border: 1px solid rgba(183, 138, 53, 0.52);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 249, 237, 0.7);
  flex: 0 0 auto;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.stat {
  border: 1px solid rgba(183, 138, 53, 0.35);
  background: linear-gradient(180deg, rgba(255, 249, 237, 0.9), rgba(239, 226, 197, 0.72));
  border-radius: var(--radius);
  padding: 8px 10px;
  min-height: 42px;
}

.stat b {
  display: block;
  color: var(--red-dark);
  font-size: 16px;
  font-family: Georgia, "Times New Roman", serif;
}

.card {
  border: 1px solid rgba(183, 138, 53, 0.52);
  background:
    linear-gradient(180deg, rgba(255, 252, 244, 0.95), rgba(247, 238, 216, 0.94)),
    var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 14px 24px rgba(66, 35, 20, 0.12);
  padding: 16px;
}

.palace-bg {
  background:
    linear-gradient(180deg, rgba(255, 252, 244, 0.9), rgba(247, 238, 216, 0.96)),
    radial-gradient(circle at top left, rgba(125, 24, 36, 0.18), transparent 40%),
    linear-gradient(135deg, rgba(183, 138, 53, 0.18), transparent);
}

.story-title {
  color: var(--red-dark);
  font-size: 22px;
  margin-bottom: 10px;
}

.story-place {
  color: var(--gold);
  font-size: 15px;
  margin-bottom: 12px;
}

.story-text {
  white-space: pre-line;
  line-height: 1.8;
  font-size: 17px;
}

.choices {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.choice {
  text-align: left;
  line-height: 1.45;
}

.choice span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 480px);
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: rgba(75, 14, 22, 0.96);
  border-top: 1px solid var(--gold);
  padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
  z-index: 10;
}

.tab {
  min-height: 44px;
  color: #f9edd3;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  font-size: 11px;
}

.tab.active {
  color: var(--red-dark);
  background: var(--gold-soft);
}

.form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--red-dark);
}

input {
  width: 100%;
  border: 1px solid rgba(183, 138, 53, 0.65);
  border-radius: var(--radius);
  background: #fffaf0;
  color: var(--ink);
  min-height: 46px;
  padding: 10px 12px;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(183, 138, 53, 0.55);
  border-radius: var(--radius);
  background: #fffaf0;
  color: var(--red-dark);
  padding: 8px 10px;
}

.origin-grid,
.location-grid,
.chamber-grid,
.shop-grid,
.list {
  display: grid;
  gap: 10px;
}

.origin,
.location,
.chamber-action {
  text-align: left;
}

.location,
.chamber-action {
  min-height: 74px;
}

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

.shop-item {
  min-height: 82px;
  text-align: left;
}

.location strong,
.origin strong,
.chamber-action strong {
  display: block;
  font-size: 16px;
}

.location span,
.origin span,
.chamber-action span,
.shop-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 4px;
}

.storage-group {
  border-top: 1px solid rgba(183, 138, 53, 0.28);
  padding-top: 10px;
  margin-top: 10px;
}

.storage-group h3 {
  color: var(--red-dark);
  font-size: 16px;
  margin: 0;
}

.origin.selected {
  background: rgba(125, 24, 36, 0.1);
  border-color: var(--red);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title {
  color: var(--red-dark);
  font-size: 22px;
}

.person,
.skill-row,
.archive-row,
.result-row {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid rgba(183, 138, 53, 0.3);
  padding: 12px 0;
}

.person:last-child,
.skill-row:last-child,
.archive-row:last-child,
.result-row:last-child {
  border-bottom: 0;
}

.person-head,
.row-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.mini-avatar {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  margin-right: 8px;
  color: var(--gold-soft);
  background: var(--red-dark);
}

.relationship-bars {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 6px 8px;
  align-items: center;
}

.gift-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

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

.relationship-bars label {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.tag {
  border: 1px solid rgba(183, 138, 53, 0.5);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(255, 249, 237, 0.7);
}

.meter {
  height: 7px;
  border-radius: 999px;
  background: rgba(183, 138, 53, 0.25);
  overflow: hidden;
}

.meter > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--red), var(--gold));
}

.danger-meter > i {
  background: linear-gradient(90deg, #9d1f2e, #d66a3f);
}

.message-card {
  margin-top: 12px;
}

.message {
  line-height: 1.65;
}

.message span {
  color: var(--muted);
  font-size: 12px;
}

.intel-box {
  border: 1px solid rgba(183, 138, 53, 0.38);
  background: rgba(255, 249, 237, 0.62);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 12px;
}

.intel-box h3 {
  color: var(--red-dark);
  font-size: 16px;
  margin: 0 0 8px;
}

.notice {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: min(calc(100% - 28px), 448px);
  transform: translateX(-50%);
  color: #fff9ed;
  background: rgba(35, 28, 24, 0.92);
  border: 1px solid rgba(223, 194, 122, 0.58);
  border-radius: var(--radius);
  padding: 12px 14px;
  z-index: 20;
  line-height: 1.55;
}

.access-card {
  text-align: left;
}

.access-card input {
  text-transform: uppercase;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  letter-spacing: 1px;
  text-align: center;
}

.error-text {
  color: var(--red);
  font-size: 14px;
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

.ending-name {
  color: var(--red-dark);
  font-size: 26px;
  margin-bottom: 10px;
}

.ending-badge {
  display: inline-block;
  color: var(--red-dark);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 5px 10px;
  margin-bottom: 14px;
}

.loading {
  min-height: 100svh;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
}

@media (min-width: 420px) {
  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
