:root {
  --paper: #EDF1F5;
  --surface: #FFFFFF;
  --field: #F5F7FA;
  --ink: #14213D;
  --muted: #56657C;
  --line: #CBD5E1;
  --hover: #E3E9F0;
  --tape: #F5C518;
  --tape-ink: #1B1B12;
  --focus: #2F6FEB;
  --warn: #9A3412;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0D1525;
    --surface: #141F35;
    --field: #0F192C;
    --ink: #E7ECF3;
    --muted: #9AA8BD;
    --line: #26354F;
    --hover: #1C2944;
    --tape: #F2C230;
    --tape-ink: #17150B;
    --focus: #86A9FF;
    --warn: #FDBA74;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 17px;
  line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.top {
  max-width: 1180px; margin: 0 auto; padding: 22px 24px 18px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: 'Barlow Condensed', sans-serif; font-weight: 600; font-size: 30px;
  text-decoration: none; line-height: 1;
}
.mark {
  width: 36px; height: 22px; border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, var(--tape-ink) 0 1.5px, transparent 1.5px 6px) 4px 0 / 100% 7px no-repeat,
    var(--tape);
}
.search { position: relative; flex: 1; min-width: 220px; max-width: 460px; }
.search input {
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.qres {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; max-height: 380px; overflow: auto;
  box-shadow: 0 14px 36px rgba(13, 21, 37, .22);
}
.qres button {
  display: flex; justify-content: space-between; gap: 12px; width: 100%;
  text-align: left; padding: 9px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer;
}
.qres button:hover, .qres button:focus-visible { background: var(--hover); }
.qres .in { color: var(--muted); font-size: 14px; white-space: nowrap; }
.qres .quick { font-weight: 600; box-shadow: inset 3px 0 0 var(--tape); }
.qres .none { padding: 9px 10px; color: var(--muted); }
.prec { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 15px; margin-left: auto; }
.prec select {
  height: 40px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); padding: 0 8px; color: var(--ink);
}

/* Layout */
.layout {
  max-width: 1180px; margin: 0 auto; padding: 0 24px 40px;
  display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 28px; align-items: start;
}
.rail { position: sticky; top: 16px; }
.rail h2 { font-size: 14px; font-weight: 500; color: var(--muted); margin: 18px 10px 6px; }
.rail .grp:first-child h2 { margin-top: 4px; }
.rail button {
  display: block; width: 100%; text-align: left; padding: 7px 10px;
  border: 0; border-radius: 8px; background: none; cursor: pointer; font-size: 16px;
}
.rail button:hover { background: var(--hover); }
.rail button[aria-current="true"] {
  background: var(--surface); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--tape), 0 0 0 1px var(--line);
}

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 30px 32px 34px; min-height: 520px;
}
.cat { font-family: 'Barlow Condensed', sans-serif; font-weight: 600; font-size: 46px; line-height: 1; margin: 0 0 8px; }
.desc { color: var(--muted); margin: 0; max-width: 64ch; }

/* Converter row */
.conv {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 14px; align-items: end; margin-top: 26px;
}
.field label { display: block; font-size: 15px; color: var(--muted); margin-bottom: 6px; }
.box {
  display: flex; align-items: stretch; min-height: 58px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--field);
}
.box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.box input {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 14px;
  font-family: 'Barlow Condensed', sans-serif; font-weight: 600; font-size: 30px;
  font-variant-numeric: tabular-nums;
}
.box input[type="datetime-local"] { font-size: 22px; }
.box input:focus, .box select:focus { outline: none; }
.box select {
  border: 0; border-left: 1px solid var(--line); background: transparent;
  padding: 0 10px; max-width: 46%; font-size: 16px; cursor: pointer; border-radius: 0 12px 12px 0;
}
.box select:only-child { max-width: none; width: 100%; border-left: 0; border-radius: 12px; padding: 0 14px; }
select option, select optgroup { background: var(--surface); color: var(--ink); }
.swap {
  width: 46px; height: 46px; margin-bottom: 6px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; transition: transform .25s ease;
}
.swap:hover { background: var(--hover); }
.swap.spin { transform: rotate(180deg); }
.swap svg { width: 20px; height: 20px; }
.when { margin-top: 16px; max-width: 360px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.ghost { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.ghost:hover { background: var(--hover); }
.ghost[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

/* The tape: the one loud element */
.tape {
  position: relative; margin-top: 24px; padding: 32px 20px 16px;
  background: var(--tape); color: var(--tape-ink); border-radius: 8px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
}
.tape::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 18px; opacity: .75;
  background:
    repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 100px) 20px 0 / 100% 18px no-repeat,
    repeating-linear-gradient(90deg, currentColor 0 1.5px, transparent 1.5px 50px) 20px 0 / 100% 12px no-repeat,
    repeating-linear-gradient(90deg, currentColor 0 1px, transparent 1px 10px) 20px 0 / 100% 7px no-repeat;
}
.tape-text {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 600; font-size: 34px; line-height: 1.15;
  overflow-wrap: anywhere; font-variant-numeric: tabular-nums; min-width: 0;
}
.tape-text .u { font-weight: 500; font-size: .6em; margin-left: .2em; }
.tape-text .eq { font-weight: 500; margin: 0 .3em; opacity: .65; }
.tape-text .small { display: block; font-family: 'Barlow', sans-serif; font-weight: 500; font-size: 16px; margin-top: 4px; }
.tape.empty .tape-text { font-family: 'Barlow', sans-serif; font-size: 20px; font-weight: 500; }
.tape.empty .copy { visibility: hidden; }
.tape .copy {
  flex: none; border: 0; background: var(--tape-ink); color: var(--tape);
  border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer;
}
.formula { color: var(--muted); margin: 14px 0 0; font-size: 16px; }
.warn { color: var(--warn); margin: 10px 0 0; }

/* Everything-at-once table */
.sub { font-size: 19px; font-weight: 600; margin: 34px 0 8px; }
.all { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.all th, .all td { padding: 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; vertical-align: middle; }
.all tr:last-child th, .all tr:last-child td { border-bottom: 0; }
.all .pick { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 8px; cursor: pointer; border-radius: 6px; }
.all .pick:hover { background: var(--hover); }
.all .sym { color: var(--muted); margin-left: 8px; font-size: 15px; }
.all tr.on th { box-shadow: inset 3px 0 0 var(--tape); }
.all tr.on .pick { font-weight: 600; }
.all td.v {
  text-align: right; padding: 10px 8px; overflow-wrap: break-word; word-break: break-word;
  font-family: 'Barlow Condensed', sans-serif; font-weight: 500; font-size: 21px;
}
.all td.c { width: 1%; padding-left: 6px; }
.all td.nw { white-space: nowrap; }
.all td.t { padding: 10px 8px; color: var(--muted); text-align: right; white-space: nowrap; font-size: 15px; }
.mini { border: 1px solid var(--line); background: none; border-radius: 7px; padding: 4px 10px; font-size: 14px; cursor: pointer; color: var(--muted); }
.mini:hover { background: var(--hover); color: var(--ink); }

.foot {
  max-width: 1180px; margin: 0 auto; padding: 0 24px 40px; color: var(--muted); font-size: 15px;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.foot p { margin: 0; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .top { padding: 16px 16px 12px; gap: 12px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .layout { grid-template-columns: 1fr; padding: 0 16px 32px; gap: 14px; }
  .rail { position: static; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
  .rail .grp { display: contents; }
  .rail h2 { display: none; }
  .rail button { width: auto; white-space: nowrap; border: 1px solid var(--line); background: var(--surface); }
  .rail button[aria-current="true"] { box-shadow: inset 0 -3px 0 var(--tape); border-color: var(--ink); }
  .panel { padding: 22px 18px 26px; border-radius: 14px; }
  .cat { font-size: 38px; }
  .conv { grid-template-columns: 1fr; gap: 10px; }
  .swap { justify-self: center; margin: 0; transform: rotate(90deg); }
  .swap.spin { transform: rotate(270deg); }
  .tape { flex-direction: column; align-items: flex-start; }
  .tape-text { font-size: 28px; }
  .foot { padding: 0 16px 32px; }
  .all .sym { display: block; margin-left: 0; font-size: 14px; }
  .all td.t { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
