:root {
  --blue: #2e3465;
  --blue-deep: #0d356f;
  --blue-ink: #102c5b;
  --gold: #b59a5b;
  --gold-light: #d8c38a;
  --cream: #f7f2e8;
  --cream-soft: #fbf8f1;
  --paper: #fffdf8;
  --ink: #172033;
  --muted: #6e7480;
  --line: #ddd7ca;
  --line-strong: #c9c0af;
  --success: #2e7355;
  --warning: #a56a10;
  --danger: #a43a35;
  --shadow: 0 20px 60px rgba(20, 30, 55, 0.12);
  --radius: 14px;
  --radius-small: 8px;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  background: var(--cream-soft);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 28px;
  color: white;
  background: var(--blue-deep);
  border-bottom: 3px solid var(--gold);
}

.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 50%;
  font-family: var(--font-serif);
  font-size: 26px;
  transform: rotate(180deg);
}
.brand-name { font-family: var(--font-serif); font-size: 22px; line-height: 1; }
.brand-subtitle { margin-top: 4px; color: rgba(255,255,255,.68); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.version-chip { padding: 6px 10px; border: 1px solid rgba(255,255,255,.28); border-radius: 999px; color: rgba(255,255,255,.8); font-size: 12px; }
.count-badge { min-width: 20px; height: 20px; display: inline-grid; place-items: center; margin-left: 8px; border-radius: 999px; background: var(--gold); color: #15264a; font-size: 11px; font-weight: 700; }

.workspace {
  min-height: calc(100vh - 79px);
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
}

.control-panel {
  min-width: 0;
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.panel-section { padding: 24px 28px; border-bottom: 1px solid var(--line); }
.intro-section { padding-top: 30px; padding-bottom: 26px; background: linear-gradient(180deg, #fffdf8, #faf6ed); }
.compact-section { padding-top: 18px; padding-bottom: 18px; }
.actions-section { border-bottom: 0; }

.eyebrow, .step-number {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; color: var(--blue-ink); font-family: var(--font-serif); font-size: clamp(29px, 2.3vw, 39px); line-height: 1.05; font-weight: 400; }
h2 { margin-bottom: 0; color: var(--blue-ink); font-family: var(--font-serif); font-size: 22px; font-weight: 400; }
h3 { color: var(--blue-ink); font-family: var(--font-serif); font-size: 21px; font-weight: 400; }
.section-copy { margin-bottom: 0; color: var(--muted); font-size: 13px; }

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

.dropzone {
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 20px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #faf7f0;
  text-align: center;
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.is-dragging { border-color: var(--gold); background: #fffaf0; transform: translateY(-1px); }
.dropzone strong { color: var(--blue-ink); font-size: 14px; }
.dropzone span { color: var(--muted); font-size: 12px; }
.dropzone-icon { width: 45px; height: 45px; display: grid; place-items: center; margin-bottom: 5px; border: 1px solid var(--gold); border-radius: 9px; color: var(--blue-ink); background: white; font-size: 10px; font-weight: 800; letter-spacing: .08em; box-shadow: 0 8px 20px rgba(20,30,55,.08); }

.file-summary { display: grid; grid-template-columns: 92px 1fr; gap: 13px; margin-top: 14px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.file-thumbnail-wrap { height: 68px; display: grid; place-items: center; overflow: hidden; border-radius: 6px; background: #eee9df; }
.file-thumbnail-wrap canvas { max-width: 100%; max-height: 100%; object-fit: contain; }
.file-details { min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.file-details strong { overflow: hidden; color: var(--blue-ink); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.file-details span { color: var(--muted); font-size: 11px; }

.field-grid { display: grid; gap: 13px; }
.two-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
.field { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.field > span { color: #4e5666; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.field input, .field select {
  width: 100%;
  min-height: 43px;
  padding: 9px 11px;
  color: var(--ink);
  background: #f1ede5;
  border: 1px solid #d5cdbf;
  border-radius: var(--radius-small);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.field input:focus, .field select:focus { border-color: var(--gold); background: white; box-shadow: 0 0 0 3px rgba(181,154,91,.14); }
.input-unit-wrap { position: relative; }
.input-unit-wrap input { padding-right: 54px; }
.input-unit-wrap > span { position: absolute; top: 50%; right: 11px; transform: translateY(-50%); color: #777b83; font-size: 11px; pointer-events: none; }

.spine-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 16px; padding: 14px; border-left: 3px solid var(--gold); border-radius: 0 9px 9px 0; background: #f7f1e4; }
.spine-card > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.spine-label { color: var(--muted); font-size: 11px; }
.spine-card strong { color: var(--blue-ink); font-family: var(--font-serif); font-size: 24px; font-weight: 400; }
.spine-card small { color: var(--muted); font-size: 10px; }
.switch-control { display: flex; align-items: center; gap: 8px; flex-shrink: 0; color: #4e5666; font-size: 11px; }
.switch-control input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { position: relative; width: 34px; height: 19px; border-radius: 999px; background: #bfc1c6; transition: background .2s ease; }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.2); transition: transform .2s ease; }
.switch-control input:checked + .switch-ui { background: var(--blue-deep); }
.switch-control input:checked + .switch-ui::after { transform: translateX(15px); }
#manualSpineField { margin-top: 12px; }

.validation-panel { display: flex; gap: 11px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 9px; background: #f7f5ef; }
.validation-dot { width: 9px; height: 9px; flex-shrink: 0; margin-top: 4px; border-radius: 50%; background: #9b9da3; }
.validation-panel strong { color: var(--blue-ink); font-size: 12px; }
.validation-panel p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.validation-panel.success { border-color: rgba(46,115,85,.28); background: rgba(46,115,85,.07); }
.validation-panel.success .validation-dot { background: var(--success); }
.validation-panel.warning { border-color: rgba(165,106,16,.3); background: rgba(181,154,91,.1); }
.validation-panel.warning .validation-dot { background: var(--warning); }
.validation-panel.error { border-color: rgba(164,58,53,.28); background: rgba(164,58,53,.07); }
.validation-panel.error .validation-dot { background: var(--danger); }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 14px; border: 1px solid transparent; border-radius: 5px; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { color: white; background: var(--blue-deep); box-shadow: 0 8px 18px rgba(13,53,111,.18); }
.button-primary:hover:not(:disabled) { box-shadow: 0 11px 24px rgba(13,53,111,.24); }
.button-secondary { color: var(--blue-deep); background: transparent; border-color: var(--blue-deep); }
.button-ghost { color: white; background: transparent; border-color: rgba(255,255,255,.36); }
.button-large { width: 100%; min-height: 48px; }
.button-small { min-height: 36px; padding: 7px 12px; }
.actions-section { display: grid; gap: 10px; }
.text-button { padding: 0; color: var(--blue-deep); background: transparent; border: 0; font-size: 11px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.privacy-note { margin: 2px 0 0; color: var(--muted); font-size: 10px; text-align: center; }

.viewer-panel { min-width: 0; min-height: 720px; display: flex; flex-direction: column; padding: 26px 28px 22px; background: radial-gradient(circle at 50% 35%, #fffdf8 0%, #f5efe3 55%, #e9e1d3 100%); }
.viewer-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 17px; }
.viewer-header h2 { font-size: 29px; }
.viewer-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(46,115,85,.1); }
.viewer-status.is-working .status-dot { background: var(--gold); box-shadow: 0 0 0 4px rgba(181,154,91,.15); }
.viewer-status.is-error .status-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(164,58,53,.12); }

.viewer-stage { position: relative; min-height: 520px; flex: 1; overflow: hidden; border: 1px solid rgba(181,154,91,.55); border-radius: 18px; background: linear-gradient(145deg, rgba(255,255,255,.74), rgba(250,245,235,.5)); box-shadow: inset 0 0 70px rgba(97,73,36,.06), var(--shadow); }
.three-container { position: absolute; inset: 0; }
.three-container canvas { display: block; width: 100%; height: 100%; }
.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; color: var(--muted); text-align: center; pointer-events: none; transition: opacity .25s ease; }
.empty-state.is-hidden { opacity: 0; }
.empty-state h3 { margin: 18px 0 6px; }
.empty-state p { margin: 0; font-size: 13px; }
.empty-book { position: relative; width: 150px; height: 180px; transform: rotateY(-18deg) rotateX(7deg) rotateZ(-4deg); filter: drop-shadow(18px 22px 18px rgba(30,35,50,.17)); }
.empty-book span { position: absolute; inset: 0; border-radius: 3px 8px 8px 3px; }
.empty-book span:nth-child(1) { background: var(--blue-deep); transform: translateZ(8px); }
.empty-book span:nth-child(2) { inset: 7px -5px 7px 8px; background: repeating-linear-gradient(to bottom, #f5f0e5 0 3px, #e4ded2 3px 4px); transform: translate(8px,4px); }
.empty-book span:nth-child(3) { width: 5px; left: auto; background: var(--gold); }

.viewer-toolbar { position: absolute; left: 50%; bottom: 18px; z-index: 5; display: flex; align-items: center; gap: 6px; padding: 7px; transform: translateX(-50%); border: 1px solid rgba(255,255,255,.6); border-radius: 11px; background: rgba(13,53,111,.91); box-shadow: 0 10px 30px rgba(10,28,60,.22); backdrop-filter: blur(12px); }
.view-button { min-width: 42px; height: 35px; padding: 0 9px; color: rgba(255,255,255,.76); background: transparent; border: 0; border-radius: 6px; font-size: 11px; font-weight: 700; }
.view-button:hover, .view-button.is-active { color: var(--blue-ink); background: white; }
.icon-button { min-width: 35px; font-size: 17px; }
.export-button { color: white; background: var(--gold); }
.export-button:hover { color: var(--blue-ink); background: var(--gold-light); }
.export-button:disabled { opacity: .38; cursor: not-allowed; }
.toolbar-separator { width: 1px; height: 22px; margin: 0 2px; background: rgba(255,255,255,.26); }

.loading-overlay { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--blue-ink); background: rgba(250,247,239,.86); backdrop-filter: blur(7px); }
.loader { width: 38px; height: 38px; border: 3px solid rgba(181,154,91,.3); border-top-color: var(--blue-deep); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.viewer-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 14px; color: var(--muted); font-size: 11px; }
.viewer-footer p { margin: 0; }
.book-spec-summary { display: flex; flex-wrap: wrap; gap: 8px; }
.book-spec-summary span { padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.58); }

.projects-dialog { width: min(680px, calc(100vw - 32px)); max-height: min(720px, calc(100vh - 50px)); padding: 0; overflow: hidden; border: 0; border-radius: 16px; color: var(--ink); background: var(--paper); box-shadow: 0 30px 90px rgba(9,24,55,.3); }
.projects-dialog::backdrop { background: rgba(7,22,50,.58); backdrop-filter: blur(5px); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 23px 26px 15px; border-bottom: 1px solid var(--line); }
.dialog-close { width: 35px; height: 35px; border: 1px solid var(--line); border-radius: 50%; color: var(--blue-ink); background: white; font-size: 23px; line-height: 1; }
.dialog-intro { margin: 0; padding: 14px 26px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.projects-list { max-height: 520px; overflow-y: auto; padding: 14px 18px 20px; }
.project-card { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 14px; align-items: center; padding: 14px 8px; border-bottom: 1px solid var(--line); }
.project-card:last-child { border-bottom: 0; }
.project-card h3 { margin: 0 0 3px; font-family: var(--font-sans); font-size: 14px; font-weight: 700; }
.project-card p { margin: 0; color: var(--muted); font-size: 11px; }
.project-actions { display: flex; gap: 7px; }
.project-actions button { min-height: 34px; padding: 6px 10px; border-radius: 5px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.open-project { color: white; background: var(--blue-deep); border: 1px solid var(--blue-deep); }
.delete-project { color: var(--danger); background: white; border: 1px solid rgba(164,58,53,.35); }
.empty-projects { padding: 45px 20px; color: var(--muted); text-align: center; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: grid; gap: 9px; pointer-events: none; }
.toast { min-width: 260px; max-width: 380px; padding: 12px 14px; border-left: 3px solid var(--gold); border-radius: 7px; color: var(--ink); background: white; box-shadow: 0 13px 38px rgba(18,31,56,.2); font-size: 12px; animation: toastIn .2s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.is-hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 370px minmax(0,1fr); }
  .panel-section { padding-left: 22px; padding-right: 22px; }
  .viewer-panel { padding-left: 20px; padding-right: 20px; }
  .viewer-toolbar { width: max-content; max-width: calc(100% - 20px); overflow-x: auto; }
}

@media (max-width: 800px) {
  .app-header { padding: 11px 16px; }
  .version-chip { display: none; }
  .workspace { display: block; }
  .control-panel { border-right: 0; }
  .viewer-panel { min-height: 650px; }
  .viewer-stage { min-height: 480px; }
}

@media (max-width: 540px) {
  .brand-subtitle { display: none; }
  .app-header { min-height: 64px; }
  .header-actions .button { padding: 6px 9px; font-size: 9px; }
  .workspace { min-height: calc(100vh - 67px); }
  .panel-section { padding: 21px 17px; }
  .two-columns { grid-template-columns: 1fr; }
  .spine-card { align-items: flex-start; flex-direction: column; }
  .viewer-panel { min-height: 610px; padding: 20px 12px 15px; }
  .viewer-header h2 { font-size: 24px; }
  .viewer-status { display: none; }
  .viewer-stage { min-height: 430px; }
  .viewer-footer { align-items: flex-start; flex-direction: column; }
  .viewer-footer p { display: none; }
  .view-button { min-width: 38px; padding: 0 7px; }
  .toolbar-separator { display: none; }
}
