:root {
  color-scheme: light;
  --ink: #252c34;
  --muted: #5c6268;
  --line: #c8c3ba;
  --paper: #f4f1eb;
  --canvas: #24282d;
  --accent: #2476a8;
  --accent-dark: #174f78;
  --accent-pale: #e0ecf5;
  --copper: #b96732;
  --amber: #805005;
  --amber-pale: #fff0cc;
  --red: #a12d27;
  --red-pale: #ffe3dc;
  --shadow: 0 12px 28px rgba(0, 0, 0, .22);
  --granite: radial-gradient(circle at 1px 1px, rgba(255,255,255,.07) .7px, transparent 1px),
    radial-gradient(circle at 3px 4px, rgba(0,0,0,.16) .7px, transparent 1px),
    linear-gradient(125deg, #343b43, #24282d 60%, #3b3734);
  --wood: repeating-linear-gradient(2deg, transparent 0 7px, rgba(18,9,4,.16) 8px 9px, transparent 10px 22px),
    repeating-linear-gradient(178deg, rgba(219,151,92,.1) 0 1px, transparent 2px 16px),
    linear-gradient(105deg, #493022, #795034 48%, #3a281e);
}

* { box-sizing: border-box; }

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--canvas);
  background-image: var(--granite);
  background-size: 7px 9px, 11px 13px, auto;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell { width: min(100% - 36px, 1020px); margin: 0 auto; padding: 24px 0 36px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.topbar .brand { color: #fff4e5; }
.topbar .eyebrow { color: #e7ad79; }
.brand-mark { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid #d79660; border-radius: 10px; color: #fff; background: linear-gradient(135deg, #b96732, #754323); font-size: 2rem; font-weight: 700; line-height: 1; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
.brand strong { display: block; margin-top: 2px; font-size: 1.2rem; letter-spacing: -0.03em; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }

h1, h2, p { margin-top: 0; }
h1 { max-width: 640px; margin-bottom: 12px; font-size: clamp(2rem, 5vw, 3.35rem); line-height: 1.04; letter-spacing: -0.055em; }
h2 { margin-bottom: 0; font-size: 1.18rem; line-height: 1.25; letter-spacing: -0.025em; }

.hero { display: flex; align-items: end; justify-content: space-between; gap: 28px; margin-bottom: 22px; padding: 28px; border: 1px solid #926546; border-top: 4px solid var(--copper); border-radius: 14px; color: #fff6ea; background: var(--wood); box-shadow: var(--shadow); }
.hero .eyebrow { color: #ffd2a5; }
.hero-copy { max-width: 630px; margin: 0; color: #f1dfce; font-size: 1rem; line-height: 1.65; }
.hero-reference { flex: 0 0 220px; display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; border: 1px solid #788694; border-radius: 10px; background-image: var(--granite); background-size: 7px 9px, 11px 13px, auto; }
.hero-reference > span:first-child { color: #e2e5e8; font-size: .75rem; font-weight: 700; }
.hero-reference strong { color: #ffbe78; font-size: 1.75rem; letter-spacing: -.04em; }
.hero-reference small { font-size: .85rem; font-weight: 650; }
.hero-reference .reference-note { color: #d5d9de; font-size: .7rem; line-height: 1.4; }

.card { min-width: 0; padding: 22px; border: 1px solid #c5beb4; border-radius: 14px; background-color: var(--paper); background-image: radial-gradient(circle at 2px 3px, rgba(64,53,40,.035) .7px, transparent 1px); background-size: 13px 11px; box-shadow: var(--shadow); }
.setup-card { border-top: 4px solid var(--copper); }
.reading-card { border-top: 4px solid var(--accent); }
.chart-card { border-top: 4px solid #6b7480; }
.setup-card { margin-bottom: 16px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-heading .eyebrow { margin-bottom: 5px; }
.section-copy { max-width: 760px; margin: 10px 0 20px; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.step-badge, .status-pill { display: inline-flex; align-items: center; white-space: nowrap; padding: 7px 10px; border-radius: 6px; color: var(--accent-dark); background: var(--accent-pale); font-size: .65rem; font-weight: 850; letter-spacing: .08em; }
.step-badge { color: #773b1a; background: #f6dec7; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.field { display: flex; min-width: 0; flex-direction: column; gap: 7px; color: var(--ink); font-size: .83rem; font-weight: 750; }
.field > span { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.unit { color: var(--muted); font-size: .7rem; font-weight: 700; }
.field input { width: 100%; min-height: 49px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 8px; outline: none; color: var(--ink); background: #fffdfa; font-size: 1rem; font-weight: 650; transition: border-color .15s, box-shadow .15s; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(36,118,168,.2); }
.field input::placeholder { color: #73716e; }
.field small { color: var(--muted); font-size: .72rem; font-weight: 450; line-height: 1.4; }

.actions-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 17px; }
.button { min-height: 44px; padding: 10px 16px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; font-size: .82rem; font-weight: 800; transition: transform .15s ease, background .15s ease, box-shadow .15s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible { outline: 3px solid #d17b3f; outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-primary { border-color: #225e87; color: white; background: linear-gradient(180deg, #226c9b, var(--accent-dark)); box-shadow: 0 4px 12px rgba(23,79,120,.2); }
.button-primary:hover:not(:disabled) { background: #123f62; }
.button-quiet { border-color: var(--line); color: var(--ink); background: #e8e3db; }
.button-quiet:hover:not(:disabled) { background: #dcd5ca; }
.install-button { border-color: #9b724c; color: #fff1df; background: #493427; }
.install-button:hover:not(:disabled) { background: #63432e; }
.button-text { border-color: transparent; color: var(--muted); background: transparent; }
.inline-message { flex: 1 1 220px; color: var(--muted); font-size: .75rem; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr); gap: 16px; margin-bottom: 16px; align-items: stretch; }
.reading-card, .recommendation-card { display: flex; flex-direction: column; }
.reading-card .section-heading, .recommendation-card .section-heading { margin-bottom: 18px; }
.current-field { margin-top: 2px; }
.current-field input { min-height: 58px; font-size: 1.3rem; }
.reading-card .actions-row { margin-top: 16px; }
.reading-card .app-message { margin: auto 0 0; padding-top: 17px; color: var(--muted); font-size: .74rem; line-height: 1.5; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #287db1; box-shadow: 0 0 0 5px #dceaf5; }

.recommendation-card { border-top: 4px solid var(--accent); }
.recommendation-card.is-warning { border-top-color: #d79724; }
.recommendation-card.is-critical { border-top-color: var(--red); }
.recommendation-card.is-alert { box-shadow: 0 12px 32px rgba(179, 92, 57, .1); }
.status-pill { color: #364f66; background: #dde6ee; }
.is-warning .status-pill { color: var(--amber); background: var(--amber-pale); }
.is-critical .status-pill { color: var(--red); background: var(--red-pale); }
.alert-banner { min-height: 76px; display: flex; align-items: center; margin: 0 0 16px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #e9e4dc; font-size: .83rem; font-weight: 600; line-height: 1.55; }
.alert-banner.warning { border-color: #d39b39; color: var(--amber); background: var(--amber-pale); }
.alert-banner.critical { border-color: #d26955; color: var(--red); background: var(--red-pale); }
.trend-card { margin-top: 22px; }
.trend-card .metrics { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.alert-banner.normal { border-color: #8baccc; color: #204d70; background: var(--accent-pale); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { display: flex; min-height: 75px; flex-direction: column; justify-content: center; gap: 7px; padding: 12px; border: 1px solid #d5cab9; border-bottom: 3px solid var(--copper); border-radius: 9px; background: #fffaf1; }
.metric span { color: var(--muted); font-size: .68rem; font-weight: 700; }
.metric strong { font-size: clamp(.9rem, 1.55vw, 1.08rem); letter-spacing: -.025em; line-height: 1.25; overflow-wrap: anywhere; }
.direction-active { color: var(--accent-dark); }
.msl-context { margin: 12px 2px 0; color: var(--muted); font-size: .7rem; line-height: 1.45; }
.resolution-actions { margin-top: auto; padding-top: 14px; }

.chart-card { padding-bottom: 18px; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 14px; }
.chart-key { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.chart-key i { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.chart-key.reference-key i { width: 18px; height: 0; border-top: 2px dashed #d79724; border-radius: 0; background: none; }
.chart-key.dock-move-key i { width: 9px; height: 9px; border: 1px solid #fff; border-radius: 1px; background: #d79724; transform: rotate(45deg); }
.chart-wrap { overflow: hidden; width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; min-height: 185px; overflow: visible; }
.chart-wrap circle { fill: var(--accent); stroke: #fff; stroke-width: 2px; }
.chart-wrap circle.latest-halo { fill: var(--accent); fill-opacity: .2; stroke: none; }
.chart-wrap circle.latest-point { fill: var(--accent-dark); stroke: #fff; stroke-width: 3px; }
.chart-wrap circle.reading-point { fill: var(--accent); }
.chart-wrap polygon.dock-move-marker { fill: #c78311; stroke: #fff; stroke-width: 2px; }
.history-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 14px; }
.history-item { display: flex; min-width: 0; flex-direction: column; gap: 5px; padding: 11px 13px; border: 1px solid #d2cbc1; border-radius: 9px; background: #fffaf3; }
.history-item strong { overflow: hidden; color: var(--ink); font-size: .73rem; text-overflow: ellipsis; }
.history-item time { color: var(--muted); font-size: .68rem; }
.history-item.move { border-left: 3px solid var(--copper); }
.empty-state { grid-column: 1 / -1; margin: 0; padding: 16px 4px; color: var(--muted); font-size: .8rem; }
.footer-note { display: flex; justify-content: space-between; gap: 12px; padding: 16px 3px 0; color: #ddd5ca; font-size: .7rem; }

@media (max-width: 740px) {
  .app-shell { width: min(100% - 28px, 600px); padding-top: 16px; }
  .hero { align-items: stretch; flex-direction: column; gap: 16px; }
  .hero-reference { flex-basis: auto; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; gap: 13px; }
  .card { padding: 18px; border-radius: 17px; }
  .setup-card { padding: 18px; }
}

@media (max-width: 460px) {
  .app-shell { width: min(100% - 22px, 600px); }
  .topbar { margin-bottom: 20px; }
  .brand-mark { width: 40px; height: 40px; }
  .install-button { min-height: 40px; padding: 8px 11px; font-size: .72rem; }
  h1 { font-size: 2.25rem; }
  .actions-row { align-items: stretch; flex-direction: column; }
  .actions-row .button { width: 100%; }
  .inline-message { flex-basis: auto; }
  .history-list { grid-template-columns: 1fr; }
  .footer-note { flex-direction: column; }
  .status-pill { font-size: .58rem; }
  .hero { padding: 20px; }
  .chart-card .section-heading { align-items: flex-start; flex-direction: column; }
  .chart-legend { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
