:root {
  color-scheme: dark;
  --bg: #11110f;
  --panel: #1a1916;
  --panel-strong: #22201b;
  --text: #f2eadb;
  --muted: #b9ad9b;
  --line: #383228;
  --gold: #d7a84c;
  --red: #b9483f;
  --jade: #6aa889;
  --blue: #6f8fb9;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(215, 168, 76, 0.15), transparent 32rem),
    linear-gradient(135deg, #11110f 0%, #171511 48%, #101416 100%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1720px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 22px;
}

.file-warning {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: -8px 0 18px;
  border: 1px solid rgba(215, 168, 76, 0.48);
  border-radius: 8px;
  background: rgba(32, 29, 23, 0.96);
  color: var(--muted);
  padding: 12px 14px;
  line-height: 1.5;
}

.file-warning[hidden] {
  display: none;
}

.file-warning strong {
  color: var(--text);
}

.file-warning button {
  margin-left: auto;
  min-height: 34px;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: #11110f;
  color: var(--text);
  padding: 0 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 3vw, 2.55rem);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: #12110f;
  font-size: 0.86rem;
  font-weight: 800;
}

.status-pill.ready {
  border-color: rgba(106, 168, 137, 0.5);
  color: #b8e1c9;
}

.status-pill.offline {
  border-color: rgba(215, 168, 76, 0.45);
  color: #efd18a;
}

.icon-button,
.secondary-action,
.chip {
  border: 1px solid var(--line);
  background: #171612;
  color: var(--text);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
}

.icon-button:hover,
.secondary-action:hover,
.chip:hover {
  border-color: var(--gold);
}

.danger:hover {
  border-color: var(--red);
  color: #ffd9d6;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 270px;
  gap: 16px;
  align-items: start;
}

.control-panel,
.quick-panel,
.output-panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(26, 25, 22, 0.92);
  box-shadow: var(--shadow);
}

.control-panel,
.quick-panel {
  position: sticky;
  top: 16px;
  border-radius: 8px;
  padding: 16px;
}

.output-panel {
  min-height: calc(100vh - 116px);
  border-radius: 8px;
  overflow: hidden;
}

.panel-section + .panel-section {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.library-section {
  padding-bottom: 2px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
}

.section-title span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(215, 168, 76, 0.5);
  border-radius: 50%;
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 800;
}

.section-title h2 {
  margin: 0;
  font-size: 1rem;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10100e;
  color: var(--text);
  padding: 0 10px;
}

.compact-textarea {
  min-height: 92px;
  font: inherit;
  line-height: 1.55;
}

.toggle-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.library-list {
  display: grid;
  gap: 8px;
}

.library-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11110f;
  color: var(--muted);
  padding: 10px;
  text-align: left;
}

.library-item.active {
  border-color: var(--gold);
  color: var(--text);
  background: #201d17;
}

.library-item strong {
  display: block;
  color: inherit;
  font-size: 0.94rem;
  line-height: 1.35;
}

.library-item span {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
}

.slider-row {
  display: grid;
  grid-template-columns: 58px 1fr 34px;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

input[type="range"] {
  accent-color: var(--gold);
  width: 100%;
}

output {
  color: var(--text);
  text-align: right;
}

.primary-action {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #d7a84c, #a74039);
  color: #15100b;
  font-weight: 900;
}

.secondary-action {
  width: 100%;
  margin-top: 10px;
}

.secondary-action.loading,
.primary-action.loading,
.chip.loading {
  opacity: 0.72;
  pointer-events: none;
}

.cover-strip {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 220px;
  background: linear-gradient(135deg, rgba(34, 32, 27, 0.95), rgba(16, 20, 22, 0.95));
  border-bottom: 1px solid var(--line);
}

.ink-scene {
  position: relative;
  overflow: hidden;
  min-height: 220px;
  background:
    linear-gradient(180deg, rgba(17, 17, 15, 0.05), rgba(17, 17, 15, 0.9)),
    radial-gradient(circle at 50% 32%, rgba(215, 168, 76, 0.28), transparent 4.5rem),
    linear-gradient(135deg, #23211b, #121819);
}

.moon {
  position: absolute;
  left: 82px;
  top: 34px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #e8d49e;
  box-shadow: 0 0 42px rgba(232, 212, 158, 0.35);
}

.mountain {
  position: absolute;
  bottom: 0;
  width: 180px;
  height: 115px;
  background: #25221c;
  transform: rotate(45deg);
}

.mountain-a {
  left: -35px;
  bottom: -64px;
}

.mountain-b {
  right: -55px;
  bottom: -50px;
  background: #181d1b;
}

.sword {
  position: absolute;
  left: 126px;
  top: 76px;
  width: 7px;
  height: 118px;
  background: linear-gradient(180deg, #e6e0d1, #7d8e9c);
  transform: rotate(27deg);
  box-shadow: 0 0 18px rgba(232, 212, 158, 0.25);
}

.sword::after {
  content: "";
  position: absolute;
  left: -19px;
  top: 78px;
  width: 45px;
  height: 7px;
  border-radius: 999px;
  background: var(--gold);
}

.cover-copy {
  align-self: center;
  padding: 28px 32px;
}

.cover-copy h2 {
  margin-bottom: 10px;
  font-size: clamp(1.6rem, 3vw, 3rem);
  line-height: 1.12;
}

.cover-copy p:last-child {
  max-width: 780px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: #151410;
  overflow-x: auto;
}

.tab {
  min-width: 120px;
  min-height: 48px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: inset 0 -3px 0 var(--gold);
}

.tab-content {
  display: none;
  padding: 26px;
}

.tab-content.active {
  display: block;
}

.empty-state {
  min-height: 340px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}

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

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 16, 14, 0.68);
  padding: 16px;
}

.card h3 {
  margin-bottom: 8px;
  color: #f7d992;
  font-size: 1.03rem;
}

.card p,
.card li {
  color: var(--muted);
  line-height: 1.65;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.card ul,
.card ol {
  margin: 0;
  padding-left: 1.2rem;
}

.card textarea,
.inline-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10100e;
  color: var(--text);
  padding: 10px;
}

.inline-input {
  min-height: 40px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #11110f;
}

.stat strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 1.2rem;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11110f;
  padding: 12px;
}

.score-card strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 1.35rem;
}

.meter {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #29251d;
}

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

.quality-result {
  display: grid;
  gap: 14px;
}

.quality-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

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

.quote-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(16, 16, 14, 0.72);
}

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

.episode-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.episode-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171612;
  color: var(--text);
  padding: 0 10px;
  font-size: 0.86rem;
}

.episode + .episode {
  margin-top: 16px;
}

textarea {
  width: 100%;
  min-height: 460px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10100e;
  color: var(--text);
  padding: 18px;
  line-height: 1.8;
  font: 1rem/1.8 ui-serif, Georgia, "Times New Roman", serif;
}

.chip {
  width: 100%;
  margin-bottom: 8px;
  text-align: left;
}

.memory-box {
  min-height: 260px;
  color: var(--muted);
  line-height: 1.65;
  font-size: 0.92rem;
}

.memory-box ul {
  margin: 0;
  padding-left: 1.1rem;
}

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

.tracker-item {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 130px;
  gap: 10px;
  align-items: center;
}

.tracker-item select {
  min-height: 38px;
}

.tracker-item .inline-input {
  min-height: 38px;
}

.ai-block {
  border-left: 3px solid var(--jade);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 44px));
  border: 1px solid rgba(215, 168, 76, 0.5);
  border-radius: 8px;
  background: #191712;
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  transform: translateY(16px);
  opacity: 0;
  transition: 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .quick-panel {
    position: static;
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .cover-strip {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .grid-two,
  .stat-row,
  .score-grid,
  .tracker-item {
    grid-template-columns: 1fr;
  }

  .cover-copy {
    padding: 22px;
  }
}
