/**
 * Bookbinding & Paper Grain Lab - Craftsman Paper Theme
 * Palette: #faf8f2 paper, #253d32 ink, #b56842 terracotta
 * Typography: Georgia serif headings, System sans body, Tabular monospace numbers
 */

:root {
  --paper: #faf8f2;
  --paper-card: #fdfcf9;
  --paper-soft: #ede8dc;
  --paper-warm: #f4efe4;
  --ink: #253d32;
  --ink-muted: #536259;
  --ink-light: #7b8880;
  --line: #d8dcce;
  --line-dark: #b8bdac;
  --terracotta: #b56842;
  --terracotta-dark: #964e2b;
  --terracotta-light: #f7ede8;
  --terracotta-glow: rgba(181, 104, 66, 0.15);

  --serif: Georgia, Cambria, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(37, 61, 50, 0.06);
  --shadow-md: 0 4px 12px rgba(37, 61, 50, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 25px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Monospace numerals throughout the application */
.num,
.code-num,
.metric-value,
.station-pos,
.fraction-text,
input[type="number"],
.ruler-tick-num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

h1, h2, h3, h4, p {
  margin-top: 0;
}

h1, h2 {
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

h1 {
  font-size: clamp(32px, 4vw, 52px);
  color: var(--ink);
}

h2 {
  font-size: clamp(22px, 2.8vw, 34px);
  color: var(--ink);
}

h3 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 400;
  color: var(--ink);
}

em {
  font-style: italic;
  color: var(--terracotta);
}

a {
  color: inherit;
  text-decoration: none;
}

/* Container & Header */
.wrap {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 24px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.brand svg {
  flex-shrink: 0;
}

.brand span {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand small {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--terracotta);
  text-transform: uppercase;
  margin-top: 2px;
}

nav {
  display: flex;
  align-items: center;
  gap: 20px;
}

nav a {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  padding: 6px 4px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
}

nav a:hover,
nav a[aria-current="true"] {
  color: var(--terracotta);
  border-bottom-color: var(--terracotta);
}

.nav-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--terracotta);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.nav-cta:hover {
  background: var(--terracotta-dark);
}

.skip {
  position: absolute;
  top: -100px;
  left: 20px;
  padding: 8px 16px;
  background: var(--terracotta);
  color: #fff;
  z-index: 100;
}

.skip:focus {
  top: 12px;
}

/* Breadcrumbs */
.crumb {
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 20px 0 12px;
}

.crumb a {
  color: var(--ink-muted);
}

.crumb a:hover {
  color: var(--terracotta);
  text-decoration: underline;
}

/* Precision Ruler Ticks */
.ruler-ticks {
  position: relative;
  height: 18px;
  width: 100%;
  margin: 12px 0 20px;
  border-top: 1px solid var(--line-dark);
  background-image: repeating-linear-gradient(
    90deg,
    var(--line-dark) 0px,
    var(--line-dark) 1px,
    transparent 1px,
    transparent 8px
  );
  opacity: 0.75;
}

.ruler-ticks::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
  background-image: repeating-linear-gradient(
    90deg,
    var(--ink) 0px,
    var(--ink) 1.5px,
    transparent 1.5px,
    transparent 32px
  );
}

/* Hero Section */
.hero {
  padding: 44px 0 28px;
  border-bottom: 1px solid var(--line);
}

.hero p.lead {
  font-size: 18px;
  line-height: 1.55;
  color: var(--ink-muted);
  max-width: 720px;
  margin-bottom: 24px;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--ink);
  color: var(--paper);
}

.btn-primary:hover {
  background: var(--terracotta);
}

.btn-secondary {
  background: var(--paper-soft);
  color: var(--ink);
  border-color: var(--line);
}

.btn-secondary:hover {
  background: var(--line);
}

.btn-outline {
  background: transparent;
  border-color: var(--line-dark);
  color: var(--ink);
}

.btn-outline:hover {
  border-color: var(--terracotta);
  color: var(--terracotta);
}

/* Cards & Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 24px;
  margin: 36px 0;
}

.tool-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
}

.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--terracotta);
  box-shadow: var(--shadow-md);
}

.tool-card-num {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--terracotta);
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.tool-card h3 {
  margin-bottom: 8px;
}

.tool-card p {
  color: var(--ink-muted);
  font-size: 14px;
  margin-bottom: 16px;
  flex-grow: 1;
}

.tool-card .formula-tag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 10px;
  background: var(--paper-soft);
  border-radius: var(--radius-sm);
  color: var(--ink);
  margin-bottom: 16px;
  display: block;
  overflow-x: auto;
  white-space: nowrap;
}

/* Scenario Preset Strip */
.preset-strip {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.preset-strip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.preset-strip-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--terracotta);
  display: flex;
  align-items: center;
  gap: 6px;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-chip {
  background: var(--paper);
  border: 1px solid var(--line-dark);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.preset-chip:hover {
  border-color: var(--terracotta);
  color: var(--terracotta-dark);
  background: var(--terracotta-light);
}

.preset-chip.active,
.preset-chip[aria-pressed="true"] {
  background: var(--terracotta);
  color: #fff;
  border-color: var(--terracotta-dark);
  font-weight: 600;
}

/* LocalStorage Project Stash Toolbar */
.workbench-stash-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.stash-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
}

.stash-btn:hover {
  background: var(--line);
  border-color: var(--line-dark);
}

.stash-btn.stash-save-btn {
  background: var(--paper);
  color: var(--terracotta);
  border-color: var(--line);
}

.stash-btn.stash-save-btn:hover {
  background: var(--terracotta-light);
  border-color: var(--terracotta);
}

.stash-popover-anchor {
  position: relative;
}

.stash-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 290px;
  background: var(--paper-card);
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 50;
  padding: 12px;
  font-size: 13px;
}

.stash-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.stash-popover-title {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.stash-popover-close {
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink-muted);
  line-height: 1;
}

.stash-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
}

.stash-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
  gap: 8px;
}

.stash-item:hover {
  background: var(--paper-soft);
}

.stash-item-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stash-item-name {
  font-weight: 600;
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stash-item-date {
  font-size: 10px;
  color: var(--ink-light);
  font-family: var(--mono);
}

.stash-delete-btn {
  background: transparent;
  border: none;
  color: var(--ink-light);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.stash-delete-btn:hover {
  color: #b3261e;
  background: #fde8e8;
}

.stash-empty {
  padding: 16px 8px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 12px;
}

/* Calculator Workspace Layout */
.calculator-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 32px;
  margin: 32px 0 48px;
}

@media (max-width: 880px) {
  .calculator-layout {
    grid-template-columns: 1fr;
  }
}

.controls-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  height: fit-content;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.form-group .hint {
  display: block;
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 4px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--paper);
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 14px;
  transition: border-color 0.15s ease;
}

.form-control:focus {
  border-color: var(--terracotta);
  background: #fff;
  outline: none;
}

/* Results Display Area */
.results-card {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.results-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.metric-box {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.metric-box.highlight {
  border-color: var(--terracotta);
  background: var(--paper-warm);
}

.metric-box .metric-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

.metric-box .metric-val {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-box.highlight .metric-val {
  color: var(--terracotta);
}

.metric-box .metric-sub {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 4px;
}

/* Diagrams */
.diagram-card {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.diagram-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.diagram-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
}

.svg-diagram-wrapper {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: auto;
}

.svg-diagram-wrapper svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Grain Warning Callout */
.grain-banner {
  background: #fdf6f0;
  border: 1px solid #e8c4b2;
  border-left: 4px solid var(--terracotta);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}

.grain-banner strong {
  color: var(--terracotta-dark);
}

/* Table Styles */
.data-table-wrap {
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-card);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

table.data-table th,
table.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

table.data-table th {
  background: var(--paper-soft);
  font-weight: 600;
  color: var(--ink);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

table.data-table tr:last-child td {
  border-bottom: none;
}

table.data-table tr:hover td {
  background: var(--paper-warm);
}

/* Article & Guide Content */
.guide-article {
  max-width: 820px;
  margin: 32px auto 60px;
}

.guide-article h1 {
  margin-bottom: 16px;
}

.guide-article .lead {
  font-size: 18px;
  color: var(--ink-muted);
  line-height: 1.6;
  margin-bottom: 32px;
}

.guide-section {
  margin-bottom: 40px;
}

.guide-section h2 {
  font-size: 24px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

/* Footer */
.footer {
  background: var(--paper-card);
  border-top: 1px solid var(--line);
  padding: 48px 0 24px;
  margin-top: 64px;
  font-size: 13px;
}

.footer-top {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 36px;
  margin-bottom: 36px;
}

@media (max-width: 720px) {
  .footer-top {
    grid-template-columns: 1fr;
  }
}

.footer-top strong {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
  margin-bottom: 12px;
}

.footer-links {
  list-style: none;
  padding: 0;
  margin: 0;
}

.footer-links li {
  margin-bottom: 8px;
}

.footer-links a {
  color: var(--ink-muted);
  transition: color 0.15s ease;
}

.footer-links a:hover {
  color: var(--terracotta);
}

.footer-bottom {
  border-top: 1px solid var(--line);
  padding-top: 20px;
  display: flex;
  justify-content: space-between;
  color: var(--ink-light);
  font-size: 12px;
}

/* Print Styles */
@media print {
  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .header,
  .footer,
  .skip,
  .nav-cta,
  .hero-actions,
  .preset-strip,
  .workbench-stash-toolbar,
  .stash-popover,
  button,
  .form-group input,
  .form-group select {
    display: none !important;
  }

  .calculator-layout {
    display: block !important;
  }

  .controls-card {
    border: none !important;
    padding: 0 !important;
    margin-bottom: 20px !important;
  }

  .results-card {
    display: block !important;
  }

  .metric-box {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    margin-bottom: 12px !important;
    page-break-inside: avoid;
  }

  .svg-diagram-wrapper {
    border: 1px solid #999 !important;
    page-break-inside: avoid;
  }

  .ruler-ticks {
    display: none !important;
  }
}
