/* =========================================================
   INKWELL — eBook Maker System
   Design tokens: deep ink-blue + white, book-spine motifs
   ========================================================= */

:root {
  --navy: #0B1F4D;
  --navy-soft: #16296B;
  --blue: #2A5CDB;
  --blue-light: #5B8DEF;
  --sky: #EAF2FF;
  --sky-deep: #DCE9FF;
  --white: #FFFFFF;
  --paper: #FBFCFF;
  --ink: #122047;
  --ink-soft: #4C5A82;
  --line: #DCE4F5;
  --gold: #F2B705;
  --success: #1E9E6B;
  --danger: #D6455F;
  --warn: #B9860B;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(11, 31, 77, 0.06), 0 1px 1px rgba(11,31,77,0.04);
  --shadow-md: 0 8px 24px rgba(11, 31, 77, 0.10);
  --shadow-lg: 0 20px 48px rgba(11, 31, 77, 0.16);
  --shadow-book: 6px 6px 0 rgba(11,31,77,0.10), 0 12px 30px rgba(11,31,77,0.14);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--navy); margin: 0 0 .5em; font-weight: 600; }
p { margin: 0 0 1em; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
ul { padding-left: 1.2em; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--navy); color: #fff;
  padding: .6em 1em; z-index: 1000; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.shell { width: min(1160px, 92%); margin: 0 auto; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  font-family: var(--font-body); font-weight: 600; font-size: .95rem;
  padding: .75em 1.4em; border-radius: 999px; border: 1.5px solid transparent;
  cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, background .15s ease, color .15s ease;
  line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--navy); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-outline { background: transparent; border-color: var(--blue); color: var(--blue); }
.btn-outline:hover { background: var(--sky); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--line); }
.btn-ghost:hover { background: var(--sky); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: .55em 1.1em; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------------- Header / Nav ---------------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(251,252,255,0.86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: .9em 0; }
.brand { display: flex; align-items: center; gap: .55em; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; color: var(--navy); }
.main-nav { display: flex; align-items: center; gap: 1.6em; }
.nav-link { color: var(--ink); font-weight: 500; font-size: .95rem; }
.nav-link:hover { color: var(--blue); text-decoration: none; }
.nav-toggle { display: none; flex-direction: column; gap: 5px; background: none; border: none; cursor: pointer; padding: 6px; }
.nav-toggle span { width: 22px; height: 2px; background: var(--navy); border-radius: 2px; }

/* ---------------- Hero ---------------- */
.hero {
  position: relative; overflow: hidden;
  background: radial-gradient(circle at 85% -10%, var(--sky) 0%, transparent 55%), var(--white);
  padding: 5.5em 0 4em;
}
.hero-grid { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 3em; align-items: center; }
.eyebrow {
  display: inline-flex; align-items: center; gap: .5em;
  font-family: var(--font-mono); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--blue); background: var(--sky); border: 1px solid var(--sky-deep);
  padding: .4em .9em; border-radius: 999px; margin-bottom: 1.1em;
}
.hero h1 { font-size: clamp(2.2rem, 4vw, 3.3rem); line-height: 1.08; letter-spacing: -.01em; }
.hero h1 em { font-style: normal; color: var(--blue); }
.hero-lede { font-size: 1.12rem; color: var(--ink-soft); max-width: 46ch; }
.hero-actions { display: flex; gap: 1em; margin-top: 1.6em; flex-wrap: wrap; }
.hero-stats { display: flex; gap: 2.2em; margin-top: 2.6em; }
.hero-stat b { display: block; font-family: var(--font-display); font-size: 1.6rem; color: var(--navy); }
.hero-stat span { font-size: .82rem; color: var(--ink-soft); }

/* Signature element: layered open book */
.book-hero { position: relative; display: flex; justify-content: center; align-items: center; height: 420px; }
.open-book { position: relative; width: 340px; height: 260px; perspective: 1400px; }
.open-book .spine {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 6px; margin-left: -3px;
  background: var(--navy); border-radius: 3px; z-index: 3;
}
.open-book .page {
  position: absolute; top: 0; width: 168px; height: 100%;
  background: linear-gradient(180deg, #fff, var(--sky) 180%);
  border: 1px solid var(--line); box-shadow: var(--shadow-md);
}
.open-book .page.left { right: 50%; border-radius: 10px 2px 2px 10px; transform-origin: right center; animation: pageFloatL 6s ease-in-out infinite; }
.open-book .page.right { left: 50%; border-radius: 2px 10px 10px 2px; transform-origin: left center; animation: pageFloatR 6s ease-in-out infinite; }
.open-book .page-lines { padding: 26px 20px; }
.open-book .page-lines span { display: block; height: 7px; border-radius: 4px; background: var(--sky-deep); margin-bottom: 10px; }
.open-book .page-lines span:nth-child(1){width: 92%;} 
.open-book .page-lines span:nth-child(2){width: 78%;}
.open-book .page-lines span:nth-child(3){width: 85%;}
.open-book .page-lines span:nth-child(4){width: 60%;}
.floating-chip {
  position: absolute; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); padding: .6em .9em; font-size: .78rem; font-weight: 600; color: var(--navy);
  display: flex; align-items: center; gap: .5em;
}
.floating-chip.chip-1 { top: 6%; left: 2%; animation: floatY 5s ease-in-out infinite; }
.floating-chip.chip-2 { bottom: 8%; right: 0%; animation: floatY 5.5s ease-in-out infinite reverse; }
.floating-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.floating-chip .dot.blue { background: var(--blue); }

@keyframes pageFloatL { 0%,100% { transform: rotateY(0deg);} 50% { transform: rotateY(-4deg);} }
@keyframes pageFloatR { 0%,100% { transform: rotateY(0deg);} 50% { transform: rotateY(4deg);} }
@keyframes floatY { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-8px);} }

@media (prefers-reduced-motion: reduce) {
  .open-book .page, .floating-chip { animation: none !important; }
}

/* ---------------- Sections ---------------- */
.section { padding: 4.5em 0; }
.section-head { max-width: 60ch; margin-bottom: 2.6em; }
.section-head .eyebrow { margin-bottom: .8em; }
.section-alt { background: var(--white); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.4em; }
.feature-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 1.8em; transition: transform .18s ease, box-shadow .18s ease;
}
.feature-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.feature-icon {
  width: 42px; height: 42px; border-radius: 10px; background: var(--sky);
  display: flex; align-items: center; justify-content: center; color: var(--blue); margin-bottom: 1em;
}
.feature-card h3 { font-size: 1.1rem; margin-bottom: .4em; }
.feature-card p { color: var(--ink-soft); font-size: .95rem; margin-bottom: 0; }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.2em; counter-reset: step; }
.step { position: relative; padding: 1.6em 1.4em 1.4em; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius-md); }
.step::before {
  counter-increment: step; content: counter(step);
  font-family: var(--font-display); font-weight: 700; font-size: 1.1rem;
  width: 34px; height: 34px; border-radius: 50%; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; margin-bottom: .9em;
}
.step h4 { font-size: 1rem; margin-bottom: .3em; }
.step p { color: var(--ink-soft); font-size: .9rem; margin-bottom: 0; }

.cta-band {
  background: linear-gradient(120deg, var(--navy), var(--navy-soft));
  border-radius: var(--radius-lg); color: #fff; padding: 3em; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1.1em;
}
.cta-band h2 { color: #fff; }
.cta-band p { color: #C6D3F2; max-width: 50ch; }

/* ---------------- Footer ---------------- */
.site-footer { border-top: 1px solid var(--line); padding: 2.4em 0; margin-top: 2em; }
.footer-inner { text-align: center; display: flex; flex-direction: column; align-items: center; gap: .4em; }
.footer-brand { display: flex; align-items: center; gap: .5em; font-weight: 700; color: var(--navy); font-family: var(--font-display); }
.footer-note, .footer-copy { color: var(--ink-soft); font-size: .85rem; margin: 0; }

/* ---------------- Auth pages ---------------- */
.auth-wrap {
  min-height: calc(100vh - 200px);
  display: flex; align-items: center; justify-content: center; padding: 3em 0;
  background: radial-gradient(circle at 10% 0%, var(--sky) 0%, transparent 45%);
}
.auth-card {
  width: min(420px, 92vw); background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2.4em 2.2em;
}
.auth-card h1 { font-size: 1.5rem; margin-bottom: .25em; }
.auth-sub { color: var(--ink-soft); font-size: .92rem; margin-bottom: 1.6em; }
.field { margin-bottom: 1.2em; }
.field label { display: block; font-size: .85rem; font-weight: 600; color: var(--navy); margin-bottom: .4em; }
.field input, .field select, .field textarea {
  width: 100%; padding: .75em .9em; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--font-body); font-size: .95rem; background: var(--paper); color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(42,92,219,.12); background: #fff;
}
.field-hint { font-size: .78rem; color: var(--ink-soft); margin-top: .35em; }
.auth-foot { text-align: center; margin-top: 1.4em; font-size: .9rem; color: var(--ink-soft); }
.divider-or { display:flex; align-items:center; gap:.8em; margin:1.4em 0; color:var(--ink-soft); font-size:.8rem; }
.divider-or::before, .divider-or::after { content:''; flex:1; height:1px; background:var(--line); }

.alert {
  padding: .9em 1.1em; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1.2em;
  border: 1px solid transparent; display: flex; gap: .6em; align-items: flex-start;
}
.alert-error { background: #FDEEF0; border-color: #F4C6CE; color: #8A2438; }
.alert-success { background: #EAFBF3; border-color: #BEE9D4; color: #146443; }
.alert-info { background: var(--sky); border-color: var(--sky-deep); color: var(--navy-soft); }
.alert ul { margin: .3em 0 0; padding-left: 1.1em; }

/* ---------------- App shell (dashboard/editor/admin) ---------------- */
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 140px); }
.app-sidebar {
  background: var(--navy); color: #EAF2FF; padding: 1.8em 1.4em;
  display: flex; flex-direction: column; gap: .3em;
}
.app-sidebar .side-title { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: #7C93D0; margin: 1.2em 0 .5em; }
.side-link {
  display: flex; align-items: center; gap: .7em; padding: .7em .8em; border-radius: var(--radius-sm);
  color: #DCE6FA; font-size: .92rem; font-weight: 500;
}
.side-link:hover, .side-link.active { background: rgba(255,255,255,.09); text-decoration: none; color: #fff; }
.app-main { padding: 2.4em; background: var(--paper); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1em; margin-bottom: 2em; flex-wrap: wrap; }
.page-head h1 { font-size: 1.8rem; margin-bottom: .2em; }
.page-head p { color: var(--ink-soft); margin: 0; }

/* Bookshelf grid (signature dashboard element) */
.shelf-toolbar { display: flex; gap: 1em; margin-bottom: 1.6em; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.search-box { position: relative; flex: 1; min-width: 220px; max-width: 340px; }
.search-box input { width: 100%; padding: .7em 1em .7em 2.3em; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; }
.search-box svg { position: absolute; left: .8em; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }

.bookshelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2em 1.6em; }
.book {
  position: relative; cursor: pointer; text-decoration: none; color: inherit; display: block;
}
.book-cover {
  aspect-ratio: 2/3; border-radius: 4px 8px 8px 4px; position: relative; overflow: hidden;
  box-shadow: var(--shadow-book); transition: transform .2s ease, box-shadow .2s ease;
  display: flex; flex-direction: column; justify-content: flex-end; padding: 1em;
  background-size: cover; background-position: center;
}
.book:hover .book-cover { transform: translateY(-6px) rotate(-1deg); box-shadow: var(--shadow-lg); text-decoration:none; }
.book-cover::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 10px;
  background: linear-gradient(90deg, rgba(0,0,0,.25), transparent);
}
.book-cover::after {
  content: ''; position: absolute; right: 6px; top: 4px; bottom: 4px; width: 3px;
  background: repeating-linear-gradient(180deg, rgba(255,255,255,.6) 0 2px, transparent 2px 4px);
}
.book-cover .cover-title { font-family: var(--font-display); font-weight: 700; font-size: 1rem; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.35); line-height: 1.2; }
.book-cover .cover-author { font-size: .75rem; color: rgba(255,255,255,.85); margin-top: .3em; }
.book-meta { margin-top: .8em; }
.book-meta .book-title { font-weight: 600; font-size: .92rem; color: var(--navy); }
.book-status { display: inline-flex; align-items:center; gap:.35em; font-size: .72rem; font-weight: 600; padding: .2em .6em; border-radius: 999px; margin-top: .3em; }
.status-draft { background: #FFF3DC; color: var(--warn); }
.status-validated { background: var(--sky); color: var(--blue); }
.status-published { background: #E4F8EE; color: var(--success); }
.status-archived { background: #F1F1F5; color: var(--ink-soft); }

.book-add {
  aspect-ratio: 2/3; border-radius: 8px; border: 2px dashed var(--line); background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5em;
  color: var(--blue); font-weight: 600; font-size: .9rem; transition: border-color .15s, background .15s;
}
.book-add:hover { border-color: var(--blue); background: var(--sky); text-decoration: none; }

.empty-state { text-align: center; padding: 5em 1em; color: var(--ink-soft); }
.empty-state svg { margin-bottom: 1em; }

/* Stat cards */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.2em; margin-bottom: 2em; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-md); padding: 1.4em; }
.stat-card b { display: block; font-family: var(--font-display); font-size: 1.7rem; color: var(--navy); }
.stat-card span { font-size: .82rem; color: var(--ink-soft); }

/* ---------------- Editor ---------------- */
.editor-shell { display: grid; grid-template-columns: 250px 1fr 320px; gap: 0; min-height: calc(100vh - 68px); }
.editor-rail { background: #fff; border-right: 1px solid var(--line); padding: 1.4em; }
.editor-rail h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin-bottom: 1em; }
.chapter-list { list-style: none; padding: 0; margin: 0 0 1em; display: flex; flex-direction: column; gap: .4em; }
.chapter-list li {
  display: flex; align-items: center; justify-content: space-between; gap: .4em;
  padding: .65em .8em; border-radius: var(--radius-sm); cursor: grab; font-size: .88rem; color: var(--ink);
}
.chapter-list li:hover, .chapter-list li.active { background: var(--sky); }
.chapter-list li .chapter-num { font-family: var(--font-mono); font-size: .74rem; color: var(--blue); margin-right: .5em; }
.chapter-list li .chapter-del { opacity: 0; background: none; border: none; color: var(--danger); cursor: pointer; }
.chapter-list li:hover .chapter-del { opacity: 1; }

.editor-canvas { padding: 1.6em 2em; overflow-y: auto; background: var(--paper); }
.editor-toolbar {
  display: flex; gap: .3em; flex-wrap: wrap; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: .5em; margin-bottom: 1em; position: sticky; top: 0; z-index: 5;
}
.editor-toolbar button {
  border: none; background: transparent; width: 34px; height: 34px; border-radius: 6px; cursor: pointer;
  color: var(--navy); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem;
}
.editor-toolbar button:hover { background: var(--sky); }
.editor-toolbar .tb-sep { width: 1px; background: var(--line); margin: 4px 6px; }

.chapter-title-input {
  width: 100%; font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; color: var(--navy);
  border: none; background: transparent; margin-bottom: .6em; padding: .2em 0;
}
.chapter-title-input:focus { outline: none; }

.content-area {
  min-height: 420px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 2em; font-size: 1.02rem; line-height: 1.75; box-shadow: var(--shadow-sm);
}
.content-area:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px rgba(42,92,219,.1); }
.content-area img { border-radius: 8px; margin: 1em 0; }

.editor-side { background: #fff; border-left: 1px solid var(--line); padding: 1.6em; overflow-y: auto; }
.editor-side h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin-bottom: 1em; }
.cover-drop {
  aspect-ratio: 2/3; border: 2px dashed var(--line); border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; text-align: center; color: var(--ink-soft);
  cursor: pointer; background: var(--sky); background-size: cover; background-position: center; margin-bottom: 1em; font-size: .85rem; padding: 1em;
}
.cover-drop:hover { border-color: var(--blue); }
.side-actions { display: flex; flex-direction: column; gap: .7em; margin-top: 1.4em; }
.autosave-note { font-size: .78rem; color: var(--ink-soft); display: flex; align-items: center; gap: .4em; margin-top: .8em; }
.autosave-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }

/* Preview modal-ish panel */
.preview-frame { border: 1px solid var(--line); border-radius: var(--radius-md); width: 100%; height: 70vh; background: #fff; }

/* ---------------- Tables (admin) ---------------- */
.table-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
table.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data-table th {
  text-align: left; background: var(--sky); color: var(--navy); font-size: .75rem; text-transform: uppercase;
  letter-spacing: .05em; padding: .9em 1.1em; border-bottom: 1px solid var(--line);
}
table.data-table td { padding: .9em 1.1em; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--paper); }
.pill { display: inline-flex; padding: .25em .7em; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.pill-admin { background: #EFE3FF; color: #5B2AAE; }
.pill-author { background: var(--sky); color: var(--blue); }
.pill-active { background: #E4F8EE; color: var(--success); }
.pill-suspended { background: #FDEEF0; color: var(--danger); }
.row-actions { display: flex; gap: .5em; }
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 6px; width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink-soft);
}
.icon-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ---------------- Responsive ---------------- */
@media (max-width: 980px) {
  .hero-grid { grid-template-columns: 1fr; }
  .book-hero { height: 300px; }
  .feature-grid { grid-template-columns: repeat(2, 1fr); }
  .steps { grid-template-columns: repeat(2, 1fr); }
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { flex-direction: row; flex-wrap: wrap; }
  .editor-shell { grid-template-columns: 1fr; }
  .editor-rail, .editor-side { border: none; border-bottom: 1px solid var(--line); }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .main-nav { position: fixed; inset: 64px 0 auto 0; background: #fff; flex-direction: column; align-items: stretch;
    padding: 1em; border-bottom: 1px solid var(--line); transform: translateY(-130%); transition: transform .2s ease; gap: .4em; }
  .main-nav.open { transform: translateY(0); }
  .nav-toggle { display: flex; }
  .feature-grid, .steps { grid-template-columns: 1fr; }
  .app-main { padding: 1.4em; }
  .stat-row { grid-template-columns: 1fr 1fr; }
}
