:root {
  --bg: #f3f7f5;
  --panel: #ffffff;
  --panel-soft: #f5f7f8;
  --text: #33434c;
  --muted: #4d5a60;
  --line: #dce3e6;
  --primary: #147587;
  --primary-dark: #095d68;
  --history: #6b4c7a;
  --amber: #b58b3b;
  --paper: #ffffff;
  --shadow: 0 12px 28px rgba(51, 67, 76, 0.1);
  --font-body: "Source Sans Pro", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: Poppins, "Source Sans Pro", system-ui, sans-serif;
}

body.dark {
  --bg: #1f282d;
  --panel: #28333a;
  --panel-soft: #222c32;
  --text: #f2f6f7;
  --muted: #b8c4c8;
  --line: #3d4b52;
  --primary: #4bb3c2;
  --primary-dark: #95d8df;
  --history: #b898c3;
  --amber: #d6b46d;
  --paper: #ffffff;
  --shadow: 0 16px 35px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(20, 117, 135, 0.12), transparent 32rem),
    linear-gradient(315deg, rgba(107, 76, 122, 0.1), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

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

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
}

button {
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 800;
  min-height: 42px;
  padding: 0 14px;
}

button:hover {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--line));
  color: var(--primary-dark);
}

input,
select,
textarea {
  background: var(--panel);
  color: var(--text);
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

.app-header {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr auto;
  margin: 0 auto;
  max-width: 1320px;
  padding: 28px clamp(16px, 4vw, 44px) 18px;
}

.header-brand {
  align-items: center;
  display: grid;
  gap: 18px;
  grid-template-columns: 82px minmax(0, 1fr);
  min-width: 0;
}

.brand-logo {
  display: block;
  height: 82px;
  object-fit: contain;
  width: 82px;
}

.title-block {
  max-width: 820px;
}

.kicker,
.card-kicker {
  color: var(--primary-dark);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin: 0 0 5px;
  text-transform: uppercase;
}

h1,
h2 {
  font-family: var(--font-display);
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 0.98;
}

h2 {
  font-size: 1.55rem;
}

.step-title {
  align-items: center;
  display: flex;
  gap: 11px;
}

.step-number {
  display: block;
  flex: 0 0 42px;
  height: 42px;
  width: 42px;
}

.preview-help {
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 600;
  margin: 8px 0 0 53px;
  max-width: 720px;
}

.subtitle {
  color: var(--muted);
  font-size: 1.12rem;
  font-weight: 700;
  margin: 12px 0 0;
}

.header-actions,
.file-actions,
.export-actions,
.preview-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.header-icon-button {
  align-items: center;
  display: inline-flex;
  height: 42px;
  justify-content: center;
  padding: 0;
  width: 42px;
}

.language-button {
  font-size: 0.82rem;
  letter-spacing: 0;
}

.about-button {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.22rem;
  font-style: italic;
  font-weight: 900;
  line-height: 1;
  padding-bottom: 2px;
}

.step-one-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.step-one-actions > button,
.step-one-actions .file-picker,
.step-one-actions .file-picker span {
  height: 100%;
  width: 100%;
}

.step-one-actions > button,
.step-one-actions .file-picker span {
  justify-content: center;
  padding-left: 8px;
  padding-right: 8px;
  text-align: center;
}

.image-note {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0;
}

.primary-button {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
  color: #fff;
}

.export-versions {
  display: grid;
  gap: 12px;
}

.download-panel {
  background: color-mix(in srgb, var(--primary) 7%, var(--panel));
  border: 2px solid color-mix(in srgb, var(--primary) 58%, var(--line));
  border-top-width: 6px;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(32, 71, 80, 0.12);
  display: grid;
  gap: 16px;
  margin: 20px;
  padding: 22px 24px 24px;
}

.download-panel-head {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
}

.download-panel-head h2 {
  color: var(--text);
  font-size: 1.7rem;
  margin: 2px 0 0;
}

.export-row {
  align-items: center;
  border-top: 1px solid color-mix(in srgb, var(--primary) 24%, var(--line));
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(150px, 0.5fr) minmax(0, 1.5fr);
  padding-top: 12px;
}

.export-row > strong {
  color: var(--text);
  font-size: 1rem;
}

.export-row .export-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.export-row .export-actions button {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  min-height: 48px;
}

.export-row .export-actions button:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #ffffff;
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(320px, 0.95fr) minmax(260px, 0.55fr);
  margin: 0 auto;
  max-width: 1320px;
  padding: 0 clamp(16px, 4vw, 44px) 20px;
}

.panel,
.preview-shell {
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  align-content: start;
  align-self: stretch;
  display: grid;
  gap: 14px;
  padding: 18px;
}

.settings-panel {
  grid-column: 2;
  grid-row: 1;
}

.preview-shell {
  grid-column: 1 / -1;
  overflow: hidden;
}

.panel-head,
.preview-toolbar {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.check-grid label,
.file-picker {
  color: var(--muted);
  font-weight: 800;
}

.format-hint {
  background: color-mix(in srgb, var(--primary) 8%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
  border-radius: 8px;
  display: grid;
  gap: 3px;
  padding: 11px;
}

.format-hint span {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.file-picker input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.file-picker span {
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-display);
  font-weight: 800;
  min-height: 42px;
  padding: 0 14px;
}

.segmented {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
}

.segmented--density {
  grid-template-columns: repeat(2, 1fr);
}

.segmented--axis-date-size {
  grid-template-columns: repeat(3, 1fr);
}

.segmented button {
  border-color: transparent;
  min-width: 0;
  padding: 0 8px;
}

.segmented button.is-active {
  background: var(--primary);
  color: #fff;
}

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

.palette-button {
  align-items: center;
  display: flex;
  gap: 9px;
  justify-content: flex-start;
  min-width: 0;
  padding: 8px 10px;
}

.palette-button.is-active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(62, 133, 151, 0.16);
  color: #ffffff;
}

.palette-button.is-active:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #ffffff;
}

.palette-button.is-active > span:last-child,
.palette-button.is-active:hover > span:last-child {
  color: #ffffff;
}

.palette-swatches {
  border: 1px solid var(--line);
  border-radius: 5px;
  display: grid;
  flex: 0 0 54px;
  grid-template-columns: repeat(5, 1fr);
  height: 22px;
  overflow: hidden;
}

.palette-swatches i {
  background: var(--swatch);
  display: block;
}

.check-grid {
  display: grid;
  gap: 10px;
}

.check-grid label {
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: flex;
  gap: 9px;
  min-height: 42px;
  padding: 8px 10px;
}

.check-grid input {
  accent-color: var(--primary);
  min-height: auto;
  width: auto;
}

.status-box {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
  min-height: 44px;
  padding: 10px;
}

.celebration-icon,
.download-success-icon {
  display: inline-block;
  height: 22px;
  margin-right: 7px;
  object-fit: contain;
  vertical-align: -5px;
  width: 22px;
}

body.dark .celebration-icon,
body.dark .download-success-icon {
  filter: invert(1);
}

.image-status:empty {
  display: none;
}

.image-status.is-loading {
  align-items: center;
  display: flex;
  gap: 10px;
}

.image-status.is-loading::before {
  animation: status-spin 0.8s linear infinite;
  border: 3px solid color-mix(in srgb, var(--primary) 24%, var(--line));
  border-radius: 50%;
  border-top-color: var(--primary);
  content: "";
  flex: 0 0 18px;
  height: 18px;
  width: 18px;
}

@keyframes status-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .image-status.is-loading::before {
    animation-duration: 1.8s;
  }
}

.preview-toolbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
}

#markerCount {
  color: var(--muted);
  font-weight: 800;
  margin: 0;
}

#resetLayout {
  min-height: 36px;
}

.sheet {
  background: var(--paper);
  color: #26343b;
  display: grid;
  gap: 18px;
  margin: 0;
  min-height: 560px;
  overflow: auto;
  padding: 24px;
}

.preview-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(2, minmax(520px, 1fr));
}

.preview-pane {
  display: grid;
  gap: 10px;
}

.preview-pane-head {
  align-items: end;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.preview-pane-head h3 {
  color: #26343b;
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0;
  margin: 0;
}

body.dark .sheet {
  color: var(--text);
}

.sheet.is-portrait .timeline-svg {
  min-width: 0;
  width: 100%;
}

.sheet.is-portrait .preview-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.sheet.is-portrait .preview-pane {
  min-width: 0;
}

.timeline-svg {
  background: #ffffff;
  border: 1px solid #dce3e6;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(51, 67, 76, 0.08);
  display: block;
  height: auto;
  max-width: none;
  width: 100%;
}

.sheet .timeline-export-credit {
  display: none;
}

.timeline-card-node {
  cursor: grab;
  touch-action: none;
}

.preview-pane--student .timeline-card-node {
  cursor: default;
}

.timeline-card-node:focus-visible rect,
.timeline-card-node.is-dragging rect {
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.2));
  stroke-width: 3;
}

.timeline-card-node.is-dragging {
  cursor: grabbing;
}

.timeline-resize-handle {
  cursor: nwse-resize;
}

.timeline-card-node.is-resizing {
  cursor: nwse-resize;
}

.timeline-period-handle {
  cursor: ew-resize;
  touch-action: none;
}

.timeline-period--vertical .timeline-period-handle {
  cursor: ns-resize;
}

.timeline-period.is-resizing .timeline-period-bar,
.timeline-period-handle:hover {
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.24));
}

@media (max-width: 1180px) {
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .sheet.is-portrait .preview-grid {
    grid-template-columns: 1fr;
  }
}

.bank-item {
  border: 1px solid #dce3e6;
  border-radius: 8px;
  font-weight: 800;
  padding: 8px 10px;
}

.empty-state {
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 800;
  padding: 34px;
}

.site-footer {
  align-items: center;
  border-top: 1px solid var(--border);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  font-size: 0.92rem;
  gap: 12px;
  justify-content: center;
  line-height: 1.55;
  margin: 4px clamp(16px, 4vw, 44px) 30px;
  padding-top: 20px;
  text-align: center;
}

.site-footer p {
  margin: 0;
  max-width: 940px;
}

.site-footer a {
  color: var(--primary-dark);
  text-decoration-color: color-mix(in srgb, var(--primary-dark) 35%, transparent);
  text-decoration-line: underline;
  text-underline-offset: 3px;
}

.license-icons {
  display: inline-flex;
  gap: 7px;
  text-decoration: none !important;
}

.license-icon {
  align-items: center;
  background: var(--panel);
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--primary-dark);
  display: inline-flex;
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 900;
  height: 32px;
  justify-content: center;
  letter-spacing: 0;
  min-width: 32px;
  padding: 0 8px;
}

.about-overlay {
  align-items: center;
  background: rgba(17, 24, 32, 0.52);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 50;
}

.about-overlay[hidden] {
  display: none;
}

.about-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
  max-width: 560px;
  overflow: hidden;
  width: min(100%, 560px);
}

.about-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 16px 18px;
}

.about-head h2 {
  color: var(--primary-dark);
  font-size: 1.25rem;
}

.about-close {
  align-items: center;
  background: transparent;
  border-radius: 50%;
  display: inline-flex;
  font-size: 1.25rem;
  height: 34px;
  justify-content: center;
  line-height: 1;
  min-height: 34px;
  padding: 0;
  width: 34px;
}

.about-content {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.about-content p {
  line-height: 1.5;
  margin: 0;
}

.about-lead {
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 900;
}

.about-content a {
  color: var(--primary-dark);
}

@media (max-width: 900px) {
  .app-header,
  .workspace {
    grid-template-columns: 1fr;
  }

  .settings-panel,
  .preview-shell {
    grid-column: 1;
    grid-row: auto;
  }

  .header-actions {
    justify-content: start;
  }

  .header-brand {
    gap: 13px;
    grid-template-columns: 62px minmax(0, 1fr);
  }

  .brand-logo {
    height: 62px;
    width: 62px;
  }

  .export-row {
    grid-template-columns: 1fr;
  }

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

@media print {
  @page {
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .app-header,
  .editor-panel,
  .settings-panel,
  .preview-toolbar,
  .download-panel,
  .about-overlay,
  .site-footer {
    display: none !important;
  }

  .workspace,
  .preview-shell,
  .sheet,
  .preview-grid,
  .preview-pane {
    display: block;
    margin: 0;
    max-width: none;
    padding: 0;
  }

  .preview-shell,
  .sheet,
  .timeline-svg {
    border: 0;
    box-shadow: none;
  }

  .timeline-svg {
    width: 100%;
  }

}
