:root {
  --bg: #f7f5ef;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #637083;
  --line: #d8ded8;
  --brand: #126b63;
  --brand-strong: #0b4d48;
  --accent: #c64f2d;
  --warn: #b35d00;
  --bad: #9e1b32;
  --ok: #236a3a;
  --soft: #e7f0ee;
  --shadow: 0 14px 30px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}

button.secondary {
  background: #eef2f1;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.ghost {
  background: transparent;
  color: var(--brand-strong);
  border: 1px solid var(--line);
}

button.danger {
  background: var(--bad);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline-color: var(--brand);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
}

.login-hero {
  padding: 72px;
  background: linear-gradient(135deg, rgba(18, 107, 99, 0.96), rgba(18, 107, 99, 0.72)), url("https://images.unsplash.com/photo-1524995997946-a1c2e315a42f?auto=format&fit=crop&w=1600&q=80");
  background-size: cover;
  background-position: center;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.login-hero h1 {
  margin: 0 0 12px;
  font-size: clamp(42px, 7vw, 86px);
  line-height: 0.95;
}

.login-hero p {
  max-width: 720px;
  margin: 0;
  font-size: 21px;
  line-height: 1.5;
}

.login-panel {
  background: var(--panel);
  padding: 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}

.login-panel h2 {
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: #162522;
  color: #e8f1ef;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: grid;
  gap: 4px;
}

.brand strong {
  font-size: 24px;
}

.brand span, .user-card span {
  color: #a8b8b5;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: #e8f1ef;
  border: 1px solid transparent;
}

.nav button.active {
  background: #223b37;
  border-color: #33544f;
}

.user-card {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.main {
  padding: 28px;
  overflow: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1, .section h2, .section h3 {
  margin: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

.panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.card {
  padding: 16px;
}

.card h3 {
  margin: 0 0 8px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--soft);
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
}

.badge.warn {
  background: #fff4df;
  color: var(--warn);
}

.badge.bad {
  background: #fde8ec;
  color: var(--bad);
}

.badge.ok {
  background: #e6f3e9;
  color: var(--ok);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tabs button {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.tabs button.active {
  background: var(--brand);
  color: #fff;
}

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

.chapter-list, .suggestion-list {
  display: grid;
  gap: 10px;
}

.chapter-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  cursor: pointer;
}

.chapter-item.active {
  border-color: var(--brand);
  background: var(--soft);
}

.block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.question {
  border-left: 4px solid var(--brand);
}

.preview-pages {
  background: #d9dedb;
  padding: 18px;
  display: grid;
  gap: 18px;
  max-height: 72vh;
  overflow: auto;
}

.page {
  width: min(100%, 660px);
  min-height: 880px;
  background: #fff;
  margin: 0 auto;
  padding: 64px 54px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.page h1, .page h2 {
  font-family: Georgia, serif;
}

.page p {
  line-height: 1.65;
}

.cover-canvas {
  aspect-ratio: 1.62 / 1;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #12453f, #e6b164 52%, #f3efe2);
  display: grid;
  grid-template-columns: 1fr 0.16fr 1fr;
  overflow: hidden;
}

.cover-back, .cover-spine, .cover-front {
  padding: 28px;
  color: #12211f;
}

.cover-spine {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.24);
  writing-mode: vertical-rl;
  font-weight: 900;
  letter-spacing: 0;
}

.cover-front {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.16);
}

.cover-title {
  font-family: Georgia, serif;
  font-size: clamp(30px, 5vw, 58px);
  line-height: 1;
  margin: 0;
}

.cover-subtitle {
  font-size: 18px;
  max-width: 330px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #162522;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.hidden {
  display: none !important;
}

@media (max-width: 1120px) {
  .editor-layout, .grid.three {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 760px) {
  .login-shell, .grid.two {
    grid-template-columns: 1fr;
  }

  .login-hero {
    min-height: 42vh;
    padding: 30px;
  }

  .main {
    padding: 18px;
  }

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

@media print {
  body * {
    visibility: hidden;
  }

  #printArea, #printArea * {
    visibility: visible;
  }

  #printArea {
    position: absolute;
    inset: 0;
  }

  .page {
    box-shadow: none;
    width: auto;
    min-height: auto;
    page-break-after: always;
  }
}
