/**
 * Suite 21: Electronics & Circuit 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,
.color-band-badge,
.resistor-display,
.voltage-display,
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.6vw, 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;
}

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

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

img, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

[hidden] {
  display: none !important;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--terracotta);
  outline-offset: 2px;
}

::selection {
  background: var(--terracotta-light);
  color: var(--terracotta-dark);
}

/* Precision Craftsman Ruler Ticks */
.ruler-ticks {
  height: 14px;
  width: 100%;
  background-image: 
    repeating-linear-gradient(90deg, var(--line-dark) 0px, var(--line-dark) 1px, transparent 1px, transparent 12px),
    repeating-linear-gradient(90deg, var(--terracotta) 0px, var(--terracotta) 1.5px, transparent 1.5px, transparent 48px);
  background-size: 100% 8px, 100% 14px;
  background-position: bottom left;
  background-repeat: no-repeat;
  border-bottom: 1px solid var(--line-dark);
  margin-block: 10px 24px;
  opacity: 0.85;
}

/* Layout container */
.wrap {
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header & Navigation */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand small {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--terracotta);
  text-transform: uppercase;
}

nav#navigation {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 14px;
  font-weight: 500;
}

nav#navigation a {
  color: var(--ink-muted);
  padding: 4px 0;
  transition: color 0.15s ease;
  position: relative;
}

nav#navigation a:hover {
  color: var(--ink);
}

nav#navigation a[aria-current="true"] {
  color: var(--terracotta);
  font-weight: 600;
}

nav#navigation a[aria-current="true"]::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--terracotta);
}

.nav-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease;
}

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

.skip {
  position: absolute;
  top: -60px;
  left: 20px;
  background: var(--terracotta);
  color: #fff;
  padding: 8px 14px;
  z-index: 1000;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: top 0.2s;
}

.skip:focus {
  top: 10px;
}

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

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

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

.crumb-sep {
  opacity: 0.5;
}

/* Hero Section */
.hero {
  padding: 40px 0 24px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper-soft);
  color: var(--terracotta);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 14px;
}

.hero p.lead {
  font-size: clamp(16px, 1.8vw, 19px);
  color: var(--ink-muted);
  max-width: 720px;
  line-height: 1.6;
}

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

.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;
}

.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);
  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: 300px;
  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-popover-close:hover {
  color: var(--ink);
}

.stash-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 220px;
  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);
}

.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: 24px 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;
}

.controls-card h3 {
  font-size: 18px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

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

.form-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}

.form-group .unit-badge {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--ink-muted);
  font-weight: normal;
}

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

.form-control {
  width: 100%;
  padding: 10px 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;
}

.range-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  flex-grow: 1;
  accent-color: var(--terracotta);
}

.unit-toggle {
  display: inline-flex;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 4px;
}

.unit-toggle button {
  background: var(--paper);
  border: none;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  transition: all 0.15s ease;
}

.unit-toggle button.active {
  background: var(--ink);
  color: var(--paper);
}

/* Quick LED Color Selector Chips */
.led-color-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.led-chip {
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-dark);
  background: var(--paper);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.led-chip:hover {
  border-color: var(--terracotta);
}

.led-chip.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.led-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* 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-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
  margin-bottom: 4px;
}

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

.metric-box .metric-sub {
  font-size: 12px;
  color: var(--ink-light);
}

/* SVG Interactive Diagrams */
.diagram-container {
  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-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.diagram-badge {
  font-size: 11px;
  font-family: var(--mono);
  background: var(--paper-soft);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
}

.diagram-svg-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  background: #fdfcf9;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
}

/* Color Code Bands Bar Visual */
.resistor-band-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-top: 12px;
}

.resistor-bands-graphic {
  display: flex;
  align-items: center;
  background: #e6dfcf;
  border: 2px solid #a89f8d;
  border-radius: 12px;
  height: 38px;
  padding: 0 16px;
  position: relative;
  gap: 10px;
}

.resistor-lead {
  width: 24px;
  height: 4px;
  background: #a8a8a8;
}

.resistor-band {
  width: 10px;
  height: 38px;
  border-radius: 1px;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.4), inset 0 -1px 2px rgba(0,0,0,0.3);
}

.resistor-band-info {
  display: flex;
  flex-direction: column;
}

.resistor-band-summary {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.resistor-band-detail {
  font-size: 11px;
  color: var(--ink-muted);
}

/* Advisory Alert Box */
.advisory-box {
  background: var(--paper-warm);
  border-left: 4px solid var(--terracotta);
  padding: 14px 18px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
}

.advisory-box.warn {
  border-left-color: #d97706;
  background: #fef9ee;
}

.advisory-box strong {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

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

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: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

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

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

/* Guide Articles */
.guide-article {
  max-width: 760px;
  margin: 32px auto 64px;
}

.guide-article h2 {
  margin-top: 36px;
  margin-bottom: 14px;
}

.guide-article p {
  font-size: 16px;
  line-height: 1.75;
  margin-bottom: 20px;
}

.guide-article ul {
  padding-left: 24px;
  margin-bottom: 24px;
}

.guide-article li {
  margin-bottom: 8px;
}

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

.footer-top {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1.2fr;
  gap: 36px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--line);
}

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

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

.footer-top a {
  display: block;
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 8px;
  transition: color 0.15s ease;
}

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

.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 24px;
  font-size: 12px;
  color: var(--ink-light);
}

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

  .header,
  .footer,
  .skip,
  .nav-cta,
  .preset-strip,
  .workbench-stash-toolbar,
  .stash-popover,
  button,
  .unit-toggle,
  .led-color-chips {
    display: none !important;
  }

  .calculator-layout {
    display: block;
  }

  .controls-card,
  .metric-box,
  .diagram-container,
  .advisory-box {
    border: 1px solid #999 !important;
    box-shadow: none !important;
    background: #fff !important;
    page-break-inside: avoid;
    margin-bottom: 16pt;
  }

  .metric-box .metric-value {
    color: #000 !important;
  }

  .wrap {
    max-width: 100%;
    padding: 0;
  }
}
