:root {
  --bg: #f4f0e8;
  --surface: #fffdf8;
  --ink: #202127;
  --muted: #666b73;
  --line: #d8d0c2;
  --jade: #1d6f63;
  --jade-dark: #134e49;
  --coral: #a7473e;
  --gold: #a66b16;
  --shadow: 0 18px 45px rgba(33, 31, 27, 0.12);
}

* {
  box-sizing: border-box;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: linear-gradient(180deg, #fffaf0 0%, var(--bg) 46%, #eae5da 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  min-height: 100vh;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.boot-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--jade-dark);
  font-weight: 700;
}

.reader,
.status-panel,
.history-panel {
  min-width: 0;
}

.reader {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.reader-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 2px 0;
}

.kicker {
  margin: 0 0 6px;
  color: var(--jade-dark);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.12;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.turn-pill,
.icon-button,
.submit-button {
  border: 1px solid var(--line);
  border-radius: 8px;
}

.turn-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  width: 44px;
  height: 44px;
  background: var(--surface);
  color: var(--jade-dark);
  font-size: 22px;
}

.story-surface {
  position: relative;
  min-height: 420px;
  padding: 28px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 253, 248, 0.82)),
    repeating-linear-gradient(90deg, rgba(166, 107, 22, 0.06) 0 1px, transparent 1px 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.story-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  color: var(--gold);
  font-size: 14px;
  font-weight: 800;
}

.story-text {
  margin: 0;
  white-space: pre-wrap;
  color: #242326;
  font-family: Georgia, "Times New Roman", "STSong", "SimSun", serif;
  font-size: 20px;
  line-height: 1.92;
}

.loading-cover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 253, 248, 0.78);
  color: var(--jade-dark);
  font-weight: 800;
  backdrop-filter: blur(2px);
}

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

.choice-button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  min-height: 104px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  line-height: 1.5;
  box-shadow: 0 8px 22px rgba(33, 31, 27, 0.07);
}

.choice-button:hover:not(:disabled) {
  border-color: rgba(29, 111, 99, 0.55);
  background: #fbfff9;
}

.choice-button span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--jade);
  color: white;
  font-weight: 900;
}

.action-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 12px;
}

textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.55;
  outline: none;
}

textarea:focus {
  border-color: var(--jade);
  box-shadow: 0 0 0 3px rgba(29, 111, 99, 0.13);
}

.submit-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 92px;
  padding: 0 18px;
  background: var(--jade);
  color: white;
  font-weight: 800;
}

.submit-button:hover:not(:disabled) {
  background: var(--jade-dark);
}

.error-box,
.warning-box {
  padding: 13px 15px;
  border-radius: 8px;
  line-height: 1.5;
}

.error-box {
  border: 1px solid rgba(167, 71, 62, 0.42);
  background: #fff2ef;
  color: #812f28;
}

.warning-box {
  border: 1px solid rgba(166, 107, 22, 0.36);
  background: #fff8e8;
  color: #71490f;
}

.warning-box p {
  margin: 0;
}

.status-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding-right: 2px;
}

.history-panel {
  grid-column: 1 / -1;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 8px 22px rgba(33, 31, 27, 0.06);
}

.history-panel h2,
.panel-section h2 {
  margin: 0 0 12px;
  color: var(--jade-dark);
  font-size: 16px;
  line-height: 1.3;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  border: 1px solid rgba(216, 208, 194, 0.9);
  border-radius: 8px;
  background: var(--surface);
}

.history-item summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  color: var(--ink);
  list-style: none;
  cursor: pointer;
}

.history-item summary::-webkit-details-marker {
  display: none;
}

.history-item summary span {
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.history-item summary strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item[open] summary strong {
  overflow: visible;
  white-space: normal;
}

.history-item p {
  margin: 0;
  padding: 0 12px 12px;
  white-space: pre-wrap;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", "STSong", "SimSun", serif;
  font-size: 15px;
  line-height: 1.72;
}

.panel-section {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 8px 22px rgba(33, 31, 27, 0.06);
}

.panel-section h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.panel-section p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.compact-list {
  display: grid;
  gap: 9px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.compact-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.compact-list strong {
  color: var(--ink);
  font-size: 13px;
}

.relation-list {
  display: grid;
  gap: 12px;
}

.relation-row {
  display: grid;
  gap: 6px;
}

.relation-row > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.relation-row span {
  color: var(--gold);
}

meter {
  width: 100%;
  height: 8px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(19, 78, 73, 0.18);
  border-top-color: var(--jade-dark);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .status-panel {
    max-height: none;
  }
}

@media (max-width: 760px) {
  body {
    background: linear-gradient(180deg, #fffaf0 0%, #f3ede2 100%);
  }

  .app-shell {
    gap: 14px;
    min-height: 100dvh;
    padding: calc(10px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom));
  }

  .reader-header {
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    gap: 10px;
    margin: -10px -12px 0;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    background: rgba(255, 250, 240, 0.92);
    border-bottom: 1px solid rgba(216, 208, 194, 0.78);
    backdrop-filter: blur(10px);
  }

  .kicker {
    margin-bottom: 2px;
    font-size: 11px;
  }

  h1 {
    font-size: 22px;
    line-height: 1.1;
  }

  .turn-pill {
    min-height: 34px;
    padding: 0 10px;
    font-size: 13px;
  }

  .icon-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
  }

  .story-surface {
    min-height: 52dvh;
    padding: 18px 16px;
    box-shadow: 0 10px 26px rgba(33, 31, 27, 0.09);
  }

  .story-label {
    margin-bottom: 12px;
    font-size: 13px;
  }

  .story-text {
    font-size: 17px;
    line-height: 1.86;
  }

  .choice-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .choice-button {
    grid-template-columns: 32px minmax(0, 1fr);
    min-height: 72px;
    padding: 14px;
    line-height: 1.48;
    box-shadow: 0 6px 18px rgba(33, 31, 27, 0.06);
  }

  .choice-button span {
    width: 32px;
    height: 32px;
  }

  .action-form {
    position: sticky;
    bottom: 0;
    z-index: 15;
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 0 -12px;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    background: rgba(244, 240, 232, 0.94);
    border-top: 1px solid rgba(216, 208, 194, 0.86);
    backdrop-filter: blur(10px);
  }

  textarea {
    min-height: 78px;
    max-height: 138px;
    resize: none;
    font-size: 16px;
  }

  .submit-button {
    min-height: 48px;
    width: 100%;
  }

  .status-panel {
    gap: 10px;
    padding-bottom: 8px;
  }

  .history-panel {
    grid-column: auto;
    padding: 13px;
    box-shadow: none;
  }

  .history-item summary {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .history-item summary strong {
    white-space: normal;
  }

  .panel-section {
    padding: 13px;
    box-shadow: none;
  }

  .panel-section p,
  .compact-list li,
  .relation-row > div {
    font-size: 13px;
  }
}
