:root {
  --cream: #F5F3ED;
  --paper: #FFFFFF;
  --ink: #1C2128;
  --ink-soft: #5B6068;
  --navy: #1B3A4B;
  --navy-dark: #12262F;
  --amber: #D98324;
  --line: #DCD9CF;
  --line-strong: #C3BFAF;
  --green: #2E7D4F; --green-bg: #E5F3EA;
  --yellow: #B98900; --yellow-bg: #FBF1D8;
  --red: #B23A2E; --red-bg: #FBE7E4;
  --blue: #1457D9;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--cream); color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
body {
  display: flex; flex-direction: column; min-height: 100vh;
}

/* ── Header ── */
.app-header {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: .75rem 1.25rem; background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 10;
}
.header-left { min-width: 0; }
.eyebrow {
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--navy); font-weight: 700; margin: 0 0 .15rem;
}
h1 {
  font-family: 'Fraunces', Georgia, serif; font-weight: 600;
  font-size: clamp(16px, 2.2vw, 22px); margin: 0;
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.chart-subtitle {
  font-family: 'Inter', sans-serif; font-size: 12.5px;
  color: var(--ink-soft); font-weight: 500;
}
.header-actions {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.header-btn {
  text-decoration: none; color: var(--navy);
  font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line-strong); padding: 7px 13px; border-radius: 8px;
  background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: all .15s ease; white-space: nowrap;
}
.header-btn:hover { background: var(--cream); border-color: var(--navy); }

/* ── Main Layout ── */
.main-layout {
  flex: 1 1 auto; display: flex; min-height: 0;
  max-width: 1560px; width: 100%; margin: 0 auto;
  padding: 18px 20px; gap: 20px;
}

/* ── Sidebar Controls ── */
.sidebar {
  flex: 0 0 380px; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.card-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-soft); margin: 0 0 14px;
}

/* ── Result Status Card ── */
.result-card {
  border-width: 2px; transition: all .2s ease;
}
.result-card.status-correct {
  border-color: var(--green); background: #F6FBF7;
}
.result-card.status-incorrect {
  border-color: var(--red); background: #FDF6F5;
}
.status-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
}
.status-indicator {
  font-size: 20px; line-height: 1;
}
.status-correct .status-indicator { color: var(--green); }
.status-incorrect .status-indicator { color: var(--red); }
.status-title {
  font-family: 'Fraunces', serif; font-size: 18px; font-weight: 700;
  letter-spacing: -.01em;
}
.status-correct .status-title { color: var(--green); }
.status-incorrect .status-title { color: var(--red); }
.status-desc {
  font-size: 12.5px; color: var(--ink-soft); margin: 0 0 10px; line-height: 1.4;
}
.status-details {
  font-size: 11.5px; color: var(--ink); background: rgba(0,0,0,0.03);
  padding: 8px 10px; border-radius: 6px; font-family: 'JetBrains Mono', monospace;
  line-height: 1.5;
}


/* ── Fields & Number Inputs ── */
.field-group {
  margin-bottom: 16px;
}
.field-group:last-child { margin-bottom: 0; }
.field-group > label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px;
}
.input-row {
  display: flex; align-items: center; gap: 0;
  border: 1.5px solid var(--line-strong); border-radius: 8px;
  overflow: hidden; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.input-row:focus-within {
  border-color: var(--navy); box-shadow: 0 0 0 3px rgba(27,58,75,0.1);
}
.input-row input[type="number"] {
  flex: 1; border: none; outline: none; padding: 9px 12px;
  font-size: 15px; font-weight: 700; font-family: 'JetBrains Mono', monospace;
  color: var(--navy); background: transparent;
  -moz-appearance: textfield;
}
.input-row input[type="number"]::-webkit-inner-spin-button,
.input-row input[type="number"]::-webkit-outer-spin-button {
  opacity: 1; cursor: pointer;
}
.input-unit {
  padding: 0 12px 0 6px; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); white-space: nowrap; user-select: none;
}
.field-meta {
  font-size: 11px; color: var(--ink-soft); margin-top: 4px;
}

/* ── Actions Card ── */
.action-row {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
}
.btn {
  flex: 1 1 auto; padding: 8px 12px; font-size: 12.5px; font-weight: 600;
  border-radius: 8px; border: 1px solid var(--line-strong);
  cursor: pointer; font-family: 'Inter', sans-serif;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: all .15s;
}
.btn-secondary { background: #fff; color: var(--ink); }
.btn-secondary:hover { background: var(--cream); border-color: var(--ink-soft); }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: var(--navy-dark); }

.toggle-row {
  display: flex; flex-direction: column; gap: 8px;
  padding-top: 10px; border-top: 1px solid var(--line);
}
.toggle-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink); cursor: pointer; user-select: none;
}
.toggle-label input { cursor: pointer; accent-color: var(--navy); }
.coords-readout {
  margin-top: 10px; padding: 8px 10px; border-radius: 6px;
  background: var(--cream); font-size: 11.5px; font-family: 'JetBrains Mono', monospace;
  color: var(--ink-soft);
}

/* ── Stage Section ── */
.stage-section {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.04);
}
.stage-header {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: #FAF9F5; border-bottom: 1px solid var(--line);
}
.stage-tag {
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
}
.zoom-controls {
  display: flex; align-items: center; gap: 5px;
}
.zoom-btn {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: #fff;
  cursor: pointer; font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--navy);
}
.zoom-btn:hover { background: var(--cream); }
.zoom-fit { width: auto; padding: 0 8px; font-size: 11px; }
.zoom-level {
  font-size: 12px; font-weight: 600; font-family: monospace;
  min-width: 44px; text-align: center; color: var(--ink-soft);
}

/* ── Viewport & Canvas ── */
.canvas-viewport {
  flex: 1 1 auto; overflow: auto; min-height: 0;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px; background: #EDEBE4;
}
.plot-stage {
  position: relative; flex-shrink: 0;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
  border-radius: 4px; overflow: hidden; background: #fff;
  transform-origin: top center; transition: width .1s, height .1s;
}
#chartImg {
  display: block; width: 100%; height: 100%; user-select: none;
}
#plotCanvas {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
}

/* ── Print Media Styles ── */
@media print {
  @page { size: portrait; margin: 8mm; }
  body { background: #fff !important; }
  .app-header, .sidebar, .stage-header { display: none !important; }
  .main-layout { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
  .stage-section { border: none !important; box-shadow: none !important; }
  .canvas-viewport { padding: 0 !important; background: transparent !important; }
  .plot-stage { box-shadow: none !important; }
}

/* ── Mobile Responsive ── */
@media (max-width: 980px) {
  .main-layout { flex-direction: column; padding: 12px; }
  .sidebar { flex: 0 0 auto; max-width: 100%; width: 100%; }
  .app-header { padding: .6rem .85rem; }
  .canvas-viewport { padding: 12px; }
}
