:root {
  --bg: #f4efe6;
  --panel: rgba(255, 251, 245, 0.8);
  --panel-strong: rgba(255, 250, 243, 0.94);
  --paper: rgba(255, 255, 253, 0.98);
  --paper-edge: rgba(128, 98, 64, 0.14);
  --line: rgba(92, 70, 43, 0.12);
  --text: #2b2117;
  --muted: #6d5c4b;
  --accent: #c85f3d;
  --accent-soft: rgba(200, 95, 61, 0.16);
  --accent-deep: #8c331b;
  --sage: #36584c;
  --gold: #d2a743;
  --shadow: 0 18px 45px rgba(74, 51, 30, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Plus Jakarta Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(210, 167, 67, 0.22), transparent 32%),
    radial-gradient(circle at 85% 12%, rgba(54, 88, 76, 0.16), transparent 26%),
    linear-gradient(145deg, #f6f2ea 0%, #e8ddcc 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

.page-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
  display: grid;
  grid-template-columns: minmax(280px, 332px) minmax(0, 1fr);
  gap: 26px;
}

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

.panel-card,
.reader-view,
.empty-state {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 14px;
  align-self: start;
  position: sticky;
  top: 18px;
}

.panel-card {
  padding: 19px;
}

.hero-card {
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.58), rgba(255, 247, 236, 0.92)),
    linear-gradient(135deg, rgba(200, 95, 61, 0.06), rgba(54, 88, 76, 0.07));
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

h1,
h2,
h3,
.chunk-content {
  font-family: "Noto Serif SC", serif;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.12;
}

.hero-copy,
.empty-copy p,
.reader-hint,
.validation-copy,
.control-hint {
  color: var(--muted);
  line-height: 1.65;
}

.field {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
}

.field span,
.section-label,
.metric-label,
.stats-label,
.chunk-index {
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  border: 1px solid rgba(92, 70, 43, 0.18);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
  padding: 12px 14px;
  color: var(--text);
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(200, 95, 61, 0.5);
  box-shadow: 0 0 0 4px rgba(200, 95, 61, 0.12);
  transform: translateY(-1px);
}

.file-field input {
  padding: 14px;
}

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

.toggle-stack,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.control-hint {
  margin: 10px 0 0;
  font-size: 0.84rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(92, 70, 43, 0.12);
}

.toggle input {
  margin: 0;
  accent-color: var(--accent);
}

.button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(43, 33, 23, 0.08);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.button.primary {
  background: linear-gradient(135deg, #ca6642, #a9492d);
  color: #fff9f5;
}

.button.secondary {
  background: rgba(54, 88, 76, 0.12);
  color: var(--sage);
}

.button.ghost {
  background: transparent;
  color: var(--accent-deep);
  border: 1px dashed rgba(140, 51, 27, 0.24);
}

.stats-card {
  background:
    radial-gradient(circle at top right, rgba(210, 167, 67, 0.18), transparent 30%),
    var(--panel-strong);
}

.stats-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.stats-header h2 {
  margin: 4px 0 0;
  font-size: 1.28rem;
}

.progress-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(54, 88, 76, 0.14);
  color: var(--sage);
  font-weight: 800;
}

.progress-track {
  height: 12px;
  margin: 20px 0 18px;
  border-radius: 999px;
  background: rgba(92, 70, 43, 0.08);
  overflow: hidden;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #d2a743 0%, #ca6642 55%, #8c331b 100%);
  transition: width 0.35s ease;
}

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

.stats-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 0.96rem;
}

.stats-actions {
  display: grid;
  gap: 10px;
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.backup-hint {
  margin: 0;
  font-size: 0.83rem;
  line-height: 1.55;
  color: var(--muted);
}

.reader-panel {
  min-height: calc(100vh - 56px);
}

.empty-state,
.reader-view {
  min-height: calc(100vh - 56px);
}

.empty-state {
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(155deg, rgba(255, 251, 245, 0.88), rgba(255, 247, 236, 0.92)),
    linear-gradient(145deg, rgba(200, 95, 61, 0.06), rgba(54, 88, 76, 0.08));
}

.empty-copy {
  position: relative;
  z-index: 1;
  max-width: 640px;
  text-align: center;
}

.empty-copy h2 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 5vw, 3.2rem);
}

.empty-orbit {
  position: absolute;
  border-radius: 999px;
  filter: blur(8px);
  opacity: 0.9;
  animation: float 9s ease-in-out infinite;
}

.orbit-one {
  width: 320px;
  height: 320px;
  top: -90px;
  left: -60px;
  background: radial-gradient(circle, rgba(200, 95, 61, 0.26), transparent 66%);
}

.orbit-two {
  width: 420px;
  height: 420px;
  right: -120px;
  bottom: -120px;
  background: radial-gradient(circle, rgba(54, 88, 76, 0.22), transparent 66%);
  animation-delay: -3s;
}

.reader-view {
  padding: 24px 24px 28px;
  background:
    linear-gradient(180deg, rgba(247, 241, 232, 0.84), rgba(255, 251, 245, 0.94)),
    var(--panel-strong);
}

body.reading-mode .control-panel .panel-card {
  background: rgba(255, 250, 243, 0.68);
  box-shadow: 0 14px 28px rgba(74, 51, 30, 0.08);
}

body.reading-mode .hero-copy,
body.reading-mode .backup-hint,
body.reading-mode .reader-hint {
  font-size: 0.92rem;
}

.hidden {
  display: none;
}

.reader-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}

.reader-header h2 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.reader-hint {
  max-width: 320px;
  margin: 0;
  font-size: 0.9rem;
}

.chunk-list {
  display: grid;
  gap: 22px;
}

.chunk-card {
  padding: 8px 0 10px;
  border-radius: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  transform-origin: top center;
  animation: reveal 0.42s ease both;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(198px, 228px);
  grid-template-areas:
    "meta aside"
    "content aside";
  gap: 12px 18px;
  align-items: start;
}

.chunk-card + .chunk-card {
  border-top: 1px solid rgba(92, 70, 43, 0.08);
  padding-top: 26px;
}

.chunk-card.locked {
  opacity: 0.52;
  filter: saturate(0.7);
  pointer-events: none;
}

.chunk-card.completed {
  border-color: transparent;
  background: transparent;
}

.chunk-meta {
  grid-area: meta;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 0;
}

.chunk-index {
  margin: 0 0 4px;
  font-size: 0.71rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.chunk-title {
  margin: 0;
  font-size: 0.94rem;
  color: rgba(43, 33, 23, 0.62);
}

.chunk-status {
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(200, 95, 61, 0.09);
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 0.76rem;
}

.chunk-content {
  grid-area: content;
  position: relative;
  padding: 42px clamp(28px, 4vw, 58px) 46px 64px;
  border-radius: 30px;
  background:
    linear-gradient(180deg, var(--paper), rgba(255, 252, 247, 0.98)),
    rgba(255, 255, 255, 0.94);
  border: 1px solid var(--paper-edge);
  box-shadow:
    0 30px 52px rgba(92, 70, 43, 0.09),
    0 0 0 14px rgba(255, 255, 255, 0.28);
  font-size: 1.18rem;
  line-height: 2.12;
  letter-spacing: 0.01em;
  min-height: 390px;
  display: grid;
  align-content: start;
}

.chunk-content::before {
  content: "";
  position: absolute;
  top: 26px;
  bottom: 26px;
  left: 28px;
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(210, 167, 67, 0.95), rgba(200, 95, 61, 0.92));
}

.chunk-content p {
  width: min(100%, 40em);
  margin: 0;
}

.chunk-content p + p {
  margin-top: 1.55em;
}

.reflection-panel {
  grid-area: aside;
  width: 100%;
  margin: 0;
  padding: 10px 11px 11px;
  display: grid;
  gap: 8px;
  border-radius: 16px;
  background: rgba(251, 245, 236, 0.76);
  border: 1px solid rgba(92, 70, 43, 0.08);
  box-shadow: 0 10px 22px rgba(92, 70, 43, 0.05);
  position: sticky;
  top: 20px;
  align-self: start;
}

.chunk-card.completed .chunk-content {
  border-color: rgba(54, 88, 76, 0.2);
  box-shadow:
    0 26px 46px rgba(71, 101, 88, 0.08),
    0 0 0 14px rgba(246, 255, 250, 0.3);
}

.chunk-card.completed .reflection-panel {
  border-color: rgba(54, 88, 76, 0.14);
  background: rgba(246, 252, 249, 0.84);
}

.tag-panel {
  display: grid;
  gap: 6px;
}

.section-label {
  margin: 0;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.84;
}

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

.tag-chip {
  border: 1px solid rgba(54, 88, 76, 0.14);
  border-radius: 999px;
  padding: 5px 9px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--sage);
  font-weight: 700;
  font-size: 0.74rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.tag-chip:hover {
  transform: translateY(-1px);
}

.tag-chip.active {
  background: rgba(54, 88, 76, 0.14);
  border-color: rgba(54, 88, 76, 0.26);
}

.note-field textarea {
  min-height: 44px;
  padding: 8px 10px;
  font-size: 0.84rem;
  line-height: 1.45;
  resize: vertical;
  transition: min-height 0.22s ease;
}

.note-field textarea:focus {
  min-height: 94px;
}

.inline-text-field {
  margin-top: 16px;
}

.completion-row {
  display: grid;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(92, 70, 43, 0.08);
}

.completion-toggle {
  background: rgba(255, 255, 255, 0.78);
  padding: 6px 9px;
  font-size: 0.82rem;
  justify-content: flex-start;
}

.validation-copy {
  margin: 0;
  font-size: 0.74rem;
  min-height: 1.2em;
  max-width: none;
  text-align: left;
}

.validation-copy.warning {
  color: var(--accent-deep);
}

.validation-copy.success {
  color: var(--sage);
}

code {
  font-family: "Plus Jakarta Sans", sans-serif;
  background: rgba(54, 88, 76, 0.08);
  padding: 2px 6px;
  border-radius: 8px;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes float {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, 18px, 0);
  }
}

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

  .control-panel {
    position: static;
  }

  .empty-state,
  .reader-view {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
    padding: 12px 0 22px;
    gap: 16px;
  }

  .panel-card,
  .reader-view {
    padding: 18px;
  }

  .field-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .backup-actions {
    flex-direction: column;
  }

  .reader-header,
  .chunk-meta {
    flex-direction: column;
    align-items: start;
  }

  .chunk-card {
    padding: 0;
    grid-template-columns: 1fr;
    grid-template-areas:
      "meta"
      "content"
      "aside";
    gap: 14px;
  }

  .chunk-card + .chunk-card {
    padding-top: 18px;
  }

  .chunk-content {
    min-height: auto;
    padding: 28px 20px 28px 34px;
    font-size: 1.02rem;
    line-height: 1.9;
    box-shadow:
      0 18px 34px rgba(92, 70, 43, 0.09),
      0 0 0 8px rgba(255, 255, 255, 0.24);
  }

  .chunk-content::before {
    top: 16px;
    bottom: 16px;
    left: 14px;
  }

  .reflection-panel {
    padding: 10px;
    position: static;
  }

  .validation-copy {
    max-width: none;
    text-align: left;
  }
}
