:root {
  --bg: #0a0a0a;
  --elev: #111111;
  --text: #f7f7f7;
  --muted: #9a9a9a;
  --line: rgba(255, 255, 255, 0.14);
  --track: #2a2a2a;
  --ink: #3e78ff;
  --ink-deep: #163a86;
  --tattoo: "New Rocker", "Palatino Linotype", Palatino, serif;
  --font: Inter, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  padding:
    calc(18px + env(safe-area-inset-top))
    20px
    calc(32px + env(safe-area-inset-bottom));
}

.search-wrap { position: relative; }

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 44px 0 14px;
  background: var(--elev);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
}

.search:focus-within { border-color: var(--ink); }

.search svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 16px;
}

.search input::-webkit-search-cancel-button { display: none; }

.search input::placeholder { color: #8a8a8a; }

.clear {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.results {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  max-height: min(52vh, 380px);
  overflow: auto;
  background: #111111;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.result, .move {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.result:last-child, .move:last-child { border-bottom: 0; }

.result > span:first-child,
.move > span:first-child {
  min-width: 0;
  flex: 1;
}

.result.active, .result:hover, .move:hover { background: rgba(255, 255, 255, 0.04); }

.result strong, .move strong {
  display: block;
  font-size: 15px;
  font-weight: 650;
}

.result small, .move small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.result-side, .move-side {
  flex: none;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
}

.result-side span, .move-side span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.ratio-row .move-side {
  max-width: 46%;
  white-space: normal;
  line-height: 1.25;
}

.ratio-notes {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.ratio-notes p {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
}

.ratio-notes .ok { color: var(--ink); }
.ratio-notes .gap { color: var(--text); }

.progress {
  display: block;
  flex: 1 0 100%;
  width: 100%;
  margin-top: 2px;
  padding-top: 9px;
}

.progress-track {
  position: relative;
  display: block;
  height: 8px;
  border-radius: 99px;
  background: var(--track);
}

.progress-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--ink);
  transition: width 0.35s ease;
}

.progress-tick {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: rgba(0, 0, 0, 0.55);
}

.progress-arrow {
  display: block;
  position: absolute;
  z-index: 1;
  top: -8px;
  left: clamp(7px, var(--at), calc(100% - 7px));
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid #f4f4f4;
  transform: translateX(-50%);
}

.progress-labels {
  position: relative;
  display: block;
  height: 14px;
  margin-top: 5px;
}

.progress-labels span {
  position: absolute;
  top: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%);
}

.progress-labels span[data-index="0"] { transform: translateX(0); }
.progress-labels span[data-index="3"] { transform: translateX(-100%); }
.progress-labels span.on { color: var(--ink); }

.empty-results {
  margin: 0;
  padding: 16px 14px;
  color: var(--muted);
  font-size: 14px;
}

.global-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-top: 26px;
}

h1 {
  margin: 0;
  font-family: var(--tattoo);
  font-size: 36px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 0.9;
}

.date {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.sex {
  display: flex;
  flex: none;
  padding: 3px;
  background: var(--elev);
  border-radius: 999px;
}

.sex button {
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.sex button[aria-pressed="true"] {
  background: #f4f4f4;
  color: #0a0a0a;
}

.ring {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 18px auto 8px;
}

.ring svg { display: block; width: 100%; height: 100%; }

.ring-track, .ring-value {
  fill: none;
  stroke-width: 10;
}

.ring-track { stroke: var(--track); }

.ring-value {
  stroke: var(--ink);
  stroke-linecap: round;
  filter: none;
  transition: stroke-dasharray 0.45s ease, stroke 0.45s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-pct {
  margin: 0;
  color: var(--ink);
  font-family: var(--tattoo);
  font-size: 56px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 0.85;
}

.ring-pct.is-empty {
  color: var(--muted);
  font-family: var(--font);
  font-size: 42px;
  font-weight: 600;
  line-height: 1;
}

.ring-level {
  min-height: 22px;
  margin: 6px 0 0;
  font-family: var(--tattoo);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
}

.ring-delta {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.portrait {
  margin: 6px 8px 0;
  color: #d5d5d5;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
}

.lines { margin-top: 22px; }

.meter {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: center;
  width: 100%;
  padding: 16px 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.meter:last-child { border-bottom: 1px solid var(--line); }

.meter:active { opacity: 0.72; }

.meter-score {
  display: grid;
  place-items: center;
  height: 44px;
  border-radius: 12px;
  background: #f4f4f4;
  color: var(--ink-deep);
  font-family: var(--tattoo);
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
}

.meter-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meter > span:last-child { min-width: 0; }

.meter-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 650;
}

.meter-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter-name svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: #f2f2f2;
}

.meter-level {
  margin-left: auto;
  flex-shrink: 0;
  font-family: var(--tattoo);
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter-add {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.balance-state {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.balance-state.gap { color: var(--text); }

.meter-track {
  position: relative;
  height: 10px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--track);
}

.meter-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  transition: width 0.45s ease, background 0.45s ease;
}

.tick {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--bg);
}

.hint, .foot {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.foot { margin-top: 28px; font-size: 12px; }

.tone-games,
.tone-elite,
.tone-rx,
.tone-inter { color: var(--ink); }
.tone-low,
.tone-none { color: var(--muted); }

.meter-score.tone-games,
.meter-score.tone-elite,
.meter-score.tone-rx,
.meter-score.tone-inter { color: var(--ink-deep); }
.meter-score.tone-low,
.meter-score.tone-none { color: #3a3a3a; }

.fill-games,
.fill-elite,
.fill-rx,
.fill-inter { background: var(--ink); }
.fill-low { background: #6e6e6e; }

.up { color: var(--ink); }
.down { color: #d4d4d4; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-card {
  width: min(480px, 100%);
  max-height: min(88vh, 760px);
  overflow: auto;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  background: #101010;
  border-radius: 22px 22px 0 0;
}

.grabber {
  width: 42px;
  height: 4px;
  margin: 6px auto 10px;
  border-radius: 99px;
  background: #4a4a4a;
}

.sheet-bar {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.sheet-bar h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  padding: 8px 0;
}

.sheet-bar .text-btn:last-child { justify-self: end; }

.sheet-note {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
}

.editor-input, .clock {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.editor-input input, .clock input {
  width: 140px;
  border: 0;
  border-bottom: 2px solid var(--ink);
  background: transparent;
  font-size: 42px;
  font-weight: 700;
  text-align: center;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.clock input { width: 88px; }

.unit, .clock span {
  color: var(--muted);
  font-size: 20px;
  font-weight: 650;
}

.live {
  min-height: 22px;
  margin: 14px 0 0;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}

.refs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0;
  padding: 0;
  list-style: none;
}

.refs li {
  padding: 8px 4px;
  border-radius: 12px;
  background: #161616;
  text-align: center;
}

.refs li span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.refs li strong {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.refs li.on { box-shadow: inset 0 0 0 1px currentColor; }

.save {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: #f4f4f4;
  color: #0a0a0a;
  font-size: 16px;
  font-weight: 750;
}

.save:disabled { opacity: 0.38; }

.delete {
  display: block;
  width: 100%;
  margin-top: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  padding: 12px;
}

.moves { margin: 0 -18px; }

@media (min-width: 640px) {
  .sheet { align-items: center; padding: 24px; }
  .sheet-card { border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .ring-value, .meter-fill, .progress-fill { transition: none; }
}
