:root {
  --ink: #21302b;
  --muted: #66736f;
  --line: #d7ded8;
  --paper: #fffdf7;
  --surface: #f6f8f4;
  --green: #3f8f72;
  --green-dark: #2e6d58;
  --coral: #df6d57;
  --gold: #f3bf45;
  --blue: #5c6f96;
  --shadow: 0 18px 45px rgba(33, 48, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: linear-gradient(180deg, #f8fbf8 0%, #fffdf7 42%, #f4f7fb 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: rgba(255, 253, 247, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 260px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  color: #fff;
  background: var(--green);
  border: 3px solid #bee3ce;
  border-radius: 8px;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 2px;
  font-size: 1.15rem;
  line-height: 1.2;
}

.brand-block p,
.section-heading p,
.reader-toolbar p {
  margin-bottom: 0;
  color: var(--muted);
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nav-button,
.command-button,
.primary-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  box-shadow: none;
}

.nav-button.active,
.command-button:hover {
  border-color: var(--green);
  background: #eaf6ef;
}

.primary-button {
  border-color: var(--green-dark);
  color: #fff;
  background: var(--green);
  font-weight: 700;
}

.primary-button:hover {
  background: var(--green-dark);
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading h2 {
  margin-bottom: 6px;
  font-size: 1.7rem;
}

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

.stat-card,
.form-panel,
.story-card,
.book-page,
.review-item {
  background: rgba(255, 253, 247, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 16px;
}

.stat-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1.55rem;
}

.stat-card span {
  color: var(--muted);
}

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

.story-card {
  overflow: hidden;
}

.story-cover {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #e4ece7;
}

.story-card-body {
  padding: 16px;
}

.story-card h3 {
  margin-bottom: 8px;
  font-size: 1.08rem;
}

.story-summary {
  min-height: 72px;
  color: var(--muted);
  line-height: 1.45;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  color: var(--ink);
  background: #eef4f0;
  border: 1px solid #d6e3db;
  font-size: 0.82rem;
  white-space: nowrap;
}

.pill.public {
  background: #fff3ce;
  border-color: #f1cf72;
}

.pill.private {
  background: #edf1fa;
  border-color: #cfd9ee;
}

.pill.review {
  background: #ffe9e2;
  border-color: #f1b8a9;
}

.story-actions,
.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.form-panel {
  padding: 18px;
}

.compact-panel {
  max-width: 860px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cdd7d1;
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  font-weight: 500;
}

textarea {
  margin: 14px 0;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid #bee3ce;
  border-color: var(--green);
}

.status-text {
  min-height: 24px;
  color: var(--muted);
}

.reader-shell {
  display: grid;
  gap: 14px;
}

.reader-toolbar {
  display: grid;
  grid-template-columns: 120px 1fr 120px;
  align-items: center;
  gap: 16px;
}

.reader-toolbar h2 {
  margin-bottom: 4px;
  text-align: center;
}

.reader-toolbar p {
  text-align: center;
}

.path-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
}

.path-button {
  min-height: 34px;
  border: 1px solid #cfd9ee;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--ink);
  background: #f4f6fb;
}

.book-page {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  min-height: 620px;
  overflow: hidden;
}

.page-art-wrap {
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf6ef;
}

.page-art {
  width: 100%;
  max-height: 520px;
  border: 1px solid #cdd7d1;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
}

.page-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 40px;
}

.page-copy p {
  margin-bottom: 0;
  white-space: pre-line;
  font-size: 1.18rem;
  line-height: 1.75;
}

.choice-panel {
  display: grid;
  gap: 12px;
}

.choice-button {
  min-height: 58px;
  border: 2px solid #d4dcb9;
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  background: #fffbea;
  text-align: left;
  font-weight: 800;
}

.choice-button:hover {
  border-color: var(--gold);
  background: #fff2c2;
}

.hidden {
  display: none !important;
}

.global-status {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(420px, calc(100% - 36px));
  border: 1px solid #cfd9ee;
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  background: #fffdf7;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.global-status.visible {
  opacity: 1;
  transform: translateY(0);
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
  margin: 18px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.check-grid legend {
  padding: 0 8px;
  font-weight: 800;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
}

.check-grid input {
  width: 18px;
  height: 18px;
}

.review-list {
  display: grid;
  gap: 14px;
}

.review-item {
  padding: 16px;
}

.review-item h3 {
  margin-bottom: 8px;
}

.empty-state {
  padding: 24px;
  border: 1px dashed #bac8c0;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 253, 247, 0.72);
}

@media (max-width: 920px) {
  .app-header,
  .section-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .top-nav {
    justify-content: flex-start;
  }

  .stats-grid,
  .story-grid,
  .book-page,
  .form-grid,
  .check-grid {
    grid-template-columns: 1fr;
  }

  .reader-toolbar {
    grid-template-columns: 1fr;
  }

  .reader-toolbar h2,
  .reader-toolbar p {
    text-align: left;
  }

  .book-page {
    min-height: auto;
  }

  .page-copy {
    padding: 24px;
  }
}

@media (max-width: 560px) {
  main {
    width: min(100% - 20px, 1180px);
    margin-top: 18px;
  }

  .app-header {
    padding: 14px;
  }

  .nav-button,
  .command-button,
  .primary-button {
    width: 100%;
  }

  .story-actions,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
