/* ==========================================================================
   Unit Converter -- design tokens + component styles that Tailwind's
   utility classes can't (or shouldn't) express. Layout/spacing lives in
   the HTML via Tailwind; identity lives here.
   ========================================================================== */

:root {
  --bg: #F7F7F4;
  --panel: #FFFFFF;
  --panel-raised: #FFFFFF;
  --ink: #1C2127;
  --ink-muted: #6B7280;
  --hairline: #E4E3DE;
  --accent: #2F6690;
  --accent-ink: #FFFFFF;
  --gauge: #D98E2B;
  --gauge-soft: #F4E4C9;
  --danger: #B3452C;
  --success: #3A7D5C;
  --readout-bg: #12151A;
  --readout-ink: #EDEAE2;
  --readout-tick: #3A4048;
  --focus-ring: #2F6690;
  --shadow-sm: 0 1px 2px rgba(28, 33, 39, 0.06);
  --shadow-md: 0 6px 20px rgba(28, 33, 39, 0.08);
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

.dark {
  --bg: #12151A;
  --panel: #1A1E24;
  --panel-raised: #20252C;
  --ink: #EDEEF0;
  --ink-muted: #97A0AC;
  --hairline: #2A2F37;
  --accent: #6FA8D6;
  --accent-ink: #0C1116;
  --gauge: #E3A94C;
  --gauge-soft: #3A2E19;
  --danger: #E08A6F;
  --success: #6FC79A;
  --readout-bg: #0A0C0F;
  --readout-ink: #F2EFE6;
  --readout-tick: #2A2F37;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100dvh; }

.font-display { font-family: var(--font-display); }
.font-mono { font-family: var(--font-mono); }

::selection { background: var(--gauge-soft); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* Focus visibility -- never rely on color alone */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ----------------------------- App shell ------------------------------ */

.app-header {
  background: var(--panel);
  border-bottom: 1px solid var(--hairline);
}

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(155deg, var(--accent), #1D435F);
  display: grid; place-items: center;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.category-btn {
  width: 100%;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  color: var(--ink-muted);
  font-size: 0.875rem;
  text-align: left;
  border: 1px solid transparent;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.category-btn:hover { background: var(--panel-raised); color: var(--ink); }
.category-btn.is-active {
  background: var(--panel-raised);
  color: var(--ink);
  border-color: var(--hairline);
  font-weight: 600;
}
.category-btn.is-active .category-icon { color: var(--accent); }
.category-icon { width: 18px; height: 18px; flex-shrink: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

/* ------------------------- Instrument readout -------------------------- */
/* Signature element: the result value renders like a digital caliper/
   multimeter readout -- mono digits on a near-black inset panel with a
   tick-mark rule above it, echoing the "measuring instrument" subject. */

.readout {
  background: var(--readout-bg);
  border-radius: 12px;
  padding: 1rem 1.1rem 0.9rem;
  position: relative;
  overflow: hidden;
}

.readout__ticks {
  height: 10px;
  background-image: repeating-linear-gradient(
    90deg,
    var(--readout-tick) 0, var(--readout-tick) 1px,
    transparent 1px, transparent 10px
  );
  margin-bottom: 0.6rem;
  opacity: 0.9;
}

.readout__value {
  font-family: var(--font-mono);
  color: var(--readout-ink);
  font-size: clamp(1.5rem, 4vw, 2.15rem);
  line-height: 1.15;
  word-break: break-word;
  letter-spacing: -0.01em;
}

.readout__unit {
  font-family: var(--font-mono);
  color: var(--gauge);
  font-size: 0.95rem;
  margin-left: 0.4rem;
}

.input-shell {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
}

.input-shell input[type="text"] {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  padding: 0.75rem 0.9rem;
  border: none;
  background: transparent;
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
.input-shell input[type="text"]:focus { outline: none; }
.input-shell:focus-within { border-color: var(--accent); }

.unit-trigger {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0 0.9rem;
  border-left: 1px solid var(--hairline);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  white-space: nowrap;
  background: var(--panel-raised);
  min-width: 118px;
  justify-content: space-between;
}
.unit-trigger:hover { background: var(--gauge-soft); }

/* Swap control -- a small dial that spins on activation */
.swap-btn {
  width: 42px; height: 42px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--panel);
  display: grid; place-items: center;
  color: var(--accent);
  transition: transform 220ms ease, background-color 150ms ease;
  flex-shrink: 0;
}
.swap-btn:hover { background: var(--gauge-soft); }
.swap-btn.is-spinning { transform: rotate(180deg); }

.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--panel);
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  color: var(--ink);
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.precision-btn {
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink-muted);
}
.precision-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.icon-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--panel);
}
.icon-btn:hover { background: var(--panel-raised); border-color: var(--accent); color: var(--accent); }
.icon-btn.is-favorited { color: var(--gauge); border-color: var(--gauge); }

table.conv-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 0.875rem; }
table.conv-table th, table.conv-table td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--hairline); }
table.conv-table th { color: var(--ink-muted); font-family: var(--font-body); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* --------------------------------- Modal -------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 12, 15, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 60;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}
.modal-panel {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 30rem;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
}
@media (min-width: 640px) {
  .modal-panel { border-radius: 18px; }
}

.unit-option {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  text-align: left;
}
.unit-option:hover { background: var(--panel-raised); }
.unit-option.is-selected { background: var(--gauge-soft); }
.unit-option .symbol { font-family: var(--font-mono); color: var(--ink-muted); font-size: 0.8125rem; }

/* --------------------------------- Toast -------------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.875rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 80;
  box-shadow: var(--shadow-md);
}
#toast.toast--visible { opacity: 1; transform: translate(-50%, 0); }

/* ----------------------------- Scrollbars ------------------------------ */

.thin-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.thin-scroll::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 999px; }

.skeleton {
  background: linear-gradient(90deg, var(--hairline) 25%, var(--panel-raised) 37%, var(--hairline) 63%);
  background-size: 400% 100%;
  animation: skeleton-wave 1.4s ease infinite;
  border-radius: 8px;
}
@keyframes skeleton-wave {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
