:root {
  --bg: #0d0f14; --panel: #161a22; --line: #262c38; --text: #e8ebf1; --muted: #8a93a6;
  --t0: #5b6475; --t1: #d8a73a; --t2: #3fb07a; --t3: #3aa6e0; --t4: #e0457b;
  --accent: #f0f2f7;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(1200px 600px at 50% -200px, #1c2230, var(--bg)); color: var(--text); min-height: 100vh; }
header, main, footer { max-width: 880px; margin: 0 auto; padding: 0 20px; }
header { padding-top: 36px; text-align: center; }
h1 { margin: 0; font-size: 2rem; letter-spacing: .02em; }
.sub { color: var(--muted); margin: 6px 0 26px; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
h2 span { color: var(--text); text-transform: none; letter-spacing: 0; font-size: .95rem; }

.inputs { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 10px; align-items: end; }
.field span { display: block; font-size: .75rem; color: var(--muted); margin: 0 0 5px 2px; text-transform: uppercase; letter-spacing: .1em; }
input { width: 100%; font-size: 1.15rem; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); outline: none; }
input:focus { border-color: #4b5875; box-shadow: 0 0 0 3px #4b587533; }
button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
button:hover { border-color: #4b5875; }
.swap { width: 46px; height: 48px; font-size: 1.3rem; }
.go { height: 48px; padding: 0 22px; background: var(--accent); color: #111; font-weight: 700; border: none; }
.go:hover { filter: brightness(.92); }
.go:disabled { opacity: .6; cursor: wait; }

.result { margin: 26px 0 8px; }
.card { --c: var(--t0); background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: 14px; padding: 22px; text-align: center; }
.pair { font-size: 1.15rem; color: var(--muted); }
.pair span:not(.sep) { color: var(--text); font-weight: 600; }
.sep { margin: 0 .4em; }
.pct { font-size: clamp(3rem, 11vw, 5.2rem); font-weight: 800; font-variant-numeric: tabular-nums; color: var(--c); line-height: 1.1; margin: 6px 0 2px; }
.tier { color: var(--muted); font-size: .95rem; }
.result.empty .pct { color: var(--line); }
.card.flash { animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(.97); opacity: .5; } to { transform: none; opacity: 1; } }

.meter { margin: 16px 4px 0; }
.track { position: relative; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--t0) 0 50%, var(--t1) 50% 80%, var(--t2) 80% 95%, var(--t3) 95% 99.6%, var(--t4) 99.6%); opacity: .35; }
.fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px; background: inherit; }
.needle { position: absolute; top: -5px; width: 4px; height: 22px; margin-left: -2px; border-radius: 2px; background: var(--text); left: 0; transition: left .45s cubic-bezier(.2,.8,.2,1); opacity: 0; }
.meter.on .track { opacity: 1; }
.meter.on .needle { opacity: 1; }
.scale { position: relative; height: 1.2em; font-size: .72rem; color: var(--muted); margin-top: 6px; }
.scale span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.scale span:first-child { transform: none; }
.scale span:last-child { transform: translateX(-100%); }
.result.stale .card, .result.stale .meter { opacity: .35; }
.error { color: #ff8a8a; text-align: center; margin: 12px 0 0; }

.neighbors { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 28px 0; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-height: 120px; }
.chips { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.chips li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 8px; background: #1d222c; border-left: 3px solid var(--c, var(--t0)); cursor: pointer; }
.chips li:hover { background: #232937; }
.chips li b { font-weight: 500; }
.chips li i { font-style: normal; font-variant-numeric: tabular-nums; color: var(--c); font-weight: 700; }

.history { margin-bottom: 30px; }
.hhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.hhead h2 { margin: 0; }
.sort { display: flex; gap: 6px; }
.sort button { font-size: .8rem; padding: 5px 10px; }
.sort button.on { background: var(--accent); color: #111; border-color: var(--accent); }
.sort .clear { color: var(--muted); }
.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hist li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c); cursor: pointer; }
.hist li:hover { border-color: #4b5875; border-left-color: var(--c); }
.hist .w { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist .w em { color: var(--muted); font-style: normal; margin: 0 .5em; }
.hist .s { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--c); }
.muted { color: var(--muted); font-size: .9rem; }

footer { color: var(--muted); font-size: .8rem; padding-bottom: 40px; border-top: 1px solid var(--line); padding-top: 16px; }
footer a { color: var(--text); }
.legend { display: flex; gap: 8px; flex-wrap: wrap; }
.legend span { padding: 2px 8px; border-radius: 6px; color: #111; font-weight: 600; }
.legend .t0 { background: var(--t0); color: var(--text); } .legend .t1 { background: var(--t1); } .legend .t2 { background: var(--t2); } .legend .t3 { background: var(--t3); } .legend .t4 { background: var(--t4); }

@media (max-width: 640px) {
  .inputs { grid-template-columns: 1fr auto; }
  .inputs .field:nth-of-type(2) { grid-column: 1; }
  .swap { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
  .go { grid-column: 1 / -1; }
  .neighbors { grid-template-columns: 1fr; }
}
