/* Unit Converter — "measuring tape" theme */
:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1b1f24;
  --muted: #6b6f76;
  --line: #e3ded2;
  --tape: #f5b700;
  --tape-ink: #1b1f24;
  --tape-soft: #fff4cc;
  --danger: #c4372c;
  --shadow: 0 1px 2px rgba(27, 31, 36, .06), 0 8px 24px rgba(27, 31, 36, .06);
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1b1e23;
    --surface-2: #22262c;
    --ink: #ecebe6;
    --muted: #9a9ea6;
    --line: #2f343b;
    --tape-soft: #3a3214;
    --danger: #ff7a6e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header with ruler ---------- */
.site-header {
  background: var(--tape);
  color: var(--tape-ink);
  position: relative;
}

.site-header .inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--tape-ink);
  color: var(--tape);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 20px;
  flex-shrink: 0;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.site-header p {
  margin: 4px 0 0;
  font-size: .95rem;
  opacity: .75;
}

/* ruler ticks along the bottom edge of the header */
.ruler {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 18px;
  background-image:
    repeating-linear-gradient(to right, var(--tape-ink) 0 2px, transparent 2px 100px),
    repeating-linear-gradient(to right, var(--tape-ink) 0 1.5px, transparent 1.5px 50px),
    repeating-linear-gradient(to right, var(--tape-ink) 0 1px, transparent 1px 10px);
  background-size: 100% 18px, 100% 11px, 100% 6px;
  background-repeat: no-repeat;
  background-position: 20px bottom;
  opacity: .8;
}

/* ---------- Layout ---------- */
main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-head h2,
.quick h2 {
  margin: 0;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  font-size: .9rem;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
}

.btn:active { transform: translateY(1px); }

.btn:focus-visible,
.field:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--tape);
  outline-offset: 2px;
}

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

.btn-primary:hover { background: #000; }

@media (prefers-color-scheme: dark) {
  .btn-primary { background: var(--tape); color: var(--tape-ink); }
  .btn-primary:hover { background: #ffc828; }
}

/* ---------- Conversion card ---------- */
#conversion-rows {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.conversion-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop-in .2s ease-out;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  flex-wrap: wrap;
}

.chip-select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b6f76' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 32px 6px 14px;
  cursor: pointer;
}

.chip-select.category-select {
  background-color: var(--tape-soft);
  border-color: transparent;
}

.chip-sep {
  color: var(--muted);
  font-size: .85rem;
}

.remove-row {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.remove-row:hover { background: var(--line); color: var(--ink); }

.row-body {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 12px;
  padding: 16px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.side-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  transition: border-color .15s ease, box-shadow .15s ease;
  overflow: hidden;
}

.field:focus-within {
  border-color: var(--tape);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tape) 25%, transparent);
}

.field.is-result {
  background: var(--tape-soft);
  border-color: transparent;
}

.value-input {
  font-family: var(--mono);
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: none;
  padding: 12px 14px 4px;
  width: 100%;
  min-width: 0;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.value-input::-webkit-outer-spin-button,
.value-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.value-input[type=number] { -moz-appearance: textfield; }

.unit-select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: .9rem;
  color: var(--muted);
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b6f76' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: none;
  padding: 2px 34px 10px 14px;
  cursor: pointer;
  width: 100%;
}

.unit-select:hover { color: var(--ink); }

.swap-btn {
  align-self: center;
  margin-top: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .25s ease, background .15s ease;
}

.swap-btn:hover { background: var(--tape); color: var(--tape-ink); border-color: var(--tape); }
.swap-btn.spin { transform: rotate(180deg); }

.row-foot {
  padding: 0 16px 14px;
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.error-msg { color: var(--danger); }
.error-msg:empty { display: none; }

/* ---------- Quick picks ---------- */
.quick { margin-top: 40px; }
.quick h2 { margin-bottom: 12px; }

#quickList {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px 24px;
}

.quick-group h3 {
  margin: 0 0 8px;
  font-size: .9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-group h3::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--tape);
}

.quick-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-conv {
  font: inherit;
  font-family: var(--mono);
  font-size: .85rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}

.quick-conv:hover {
  background: var(--tape-soft);
  border-color: var(--tape);
  border-style: solid;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: .8rem;
  padding: 0 20px 32px;
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .site-header .inner { padding: 20px 16px 34px; }
  main { padding: 24px 16px 48px; }
  .row-body { grid-template-columns: 1fr; }
  .swap-btn { margin: 0 auto; transform: rotate(90deg); }
  .swap-btn.spin { transform: rotate(270deg); }
}
