:root {
  --bg: #0b0f17; --card: #131a26; --card2: #1a2332; --line: #243044; --text: #e8edf5; --muted: #8a97ab;
  --accent: #5b9dff; --accent2: #8b5cf6; --good: #34d399; --warn: #fbbf24; --bad: #f87171;
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); color-scheme: dark; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; -webkit-user-select: none; user-select: none; }
textarea, input { -webkit-user-select: text; user-select: text; }
#app { max-width: 560px; margin: 0 auto; padding: calc(14px + var(--sat)) calc(16px + var(--sar)) calc(28px + var(--sab)) calc(16px + var(--sal)); display: flex; flex-direction: column; gap: 14px; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 0; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.02em; font-weight: 750; }
.badge { font-size: 12px; color: var(--good); border: 1px solid rgba(52,211,153,.4); border-radius: 99px; padding: 3px 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 16px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
.canvas-wrap { position: relative; height: 150px; border-radius: 14px; background: #0d1320; border: 1px solid var(--line); overflow: hidden; }
#contour { width: 100%; height: 100%; display: block; }
.canvas-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #3a4a63; font-size: 14px; pointer-events: none; }
.canvas-empty.hide { display: none; }
.meter { position: relative; height: 14px; margin: 12px 2px 0; border-radius: 99px; background: #0d1320; border: 1px solid var(--line); overflow: hidden; }
.meter-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: linear-gradient(90deg, var(--good), var(--warn) 75%, var(--bad)); transition: width 60ms linear; }
.meter-label { position: absolute; right: 8px; top: -1px; font-size: 10px; line-height: 14px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.rec { position: relative; display: block; margin: 18px auto 4px; width: 148px; height: 148px; border-radius: 50%; border: 0; padding: 0; color: #fff; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #7db2ff, var(--accent) 45%, var(--accent2)); box-shadow: 0 10px 30px rgba(91,157,255,.35), inset 0 -6px 14px rgba(0,0,0,.25);
  font: inherit; touch-action: manipulation; transition: transform .12s; }
.rec:active { transform: scale(.96); }
.rec[disabled] { opacity: .6; }
.rec.recording { background: radial-gradient(circle at 35% 30%, #ff8d8d, var(--bad) 50%, #d4436b); box-shadow: 0 10px 30px rgba(248,113,113,.4); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.03); } }
.ring { position: absolute; inset: -9px; width: calc(100% + 18px); height: calc(100% + 18px); transform: rotate(-90deg); pointer-events: none; }
.ring-bg { fill: none; stroke: transparent; stroke-width: 3; }
.ring-fg { fill: none; stroke: #fff; stroke-opacity: .9; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 289; stroke-dashoffset: 289; }
.rec.recording .ring-bg { stroke: rgba(255,255,255,.12); }
.rec-icon { display: block; width: 34px; height: 34px; margin: 0 auto 6px; border-radius: 50%; background: #fff; }
.rec.recording .rec-icon { border-radius: 8px; width: 28px; height: 28px; margin-bottom: 10px; }
.rec-text { font-size: 18px; font-weight: 650; }
.status { min-height: 22px; text-align: center; margin: 10px 0 0; color: var(--muted); font-size: 15px; }
.status.err { color: var(--bad); }
.eyebrow { color: var(--muted); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.res-name { margin: 4px 0 10px; font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; }
.conf-row { display: flex; align-items: center; gap: 12px; }
.conf-track { flex: 1; height: 12px; border-radius: 99px; background: #0d1320; border: 1px solid var(--line); overflow: hidden; }
.conf-bar { height: 100%; width: 0; border-radius: 99px; background: var(--good); transition: width .5s ease; }
.conf-bar.mid { background: var(--warn); } .conf-bar.low { background: var(--bad); }
.conf-text { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 90px; text-align: right; }
.note { margin: 8px 0 0; color: var(--muted); font-size: 14px; min-height: 0; }
.top-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.top-list li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 12px 14px; background: var(--card2); border-radius: 14px; min-height: 48px; }
.top-list .rank { color: var(--muted); font-weight: 700; }
.top-list .dist { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.top-list li.first { outline: 1px solid rgba(91,157,255,.5); }
.meta { color: var(--muted); font-size: 13px; margin: 12px 0; word-break: break-word; }
.btn { appearance: none; border: 0; border-radius: 14px; min-height: 52px; padding: 0 20px; font: inherit; font-weight: 650; font-size: 17px; color: var(--text); cursor: pointer; touch-action: manipulation; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.btn.secondary { background: var(--card2); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid rgba(248,113,113,.4); min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn:active { filter: brightness(1.15); }
#againBtn { width: 100%; }
summary { cursor: pointer; font-weight: 650; font-size: 17px; min-height: 44px; display: flex; align-items: center; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "+"; display: inline-grid; place-items: center; width: 28px; height: 28px; margin-right: 10px; border-radius: 50%; background: var(--card2); color: var(--accent); font-size: 20px; }
details[open] summary::before { content: "\2212"; }
form { display: grid; gap: 8px; padding-top: 6px; }
label { font-weight: 600; font-size: 14px; margin-top: 6px; }
input, textarea { width: 100%; background: #0d1320; color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 16px; /* 16px stops iOS zoom */ min-height: 48px; }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.muted { color: var(--muted); font-weight: 400; } .small { font-size: 13px; margin: 0; }
code { background: #0d1320; border-radius: 6px; padding: 1px 5px; font-size: .92em; }
.form-msg { min-height: 20px; margin: 0; font-size: 14px; color: var(--bad); } .form-msg.ok { color: var(--good); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.list-title { font-size: 15px; margin: 16px 0 8px; color: var(--muted); font-weight: 650; }
.tune-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.tune-list li { display: flex; align-items: center; gap: 10px; background: var(--card2); border-radius: 14px; padding: 8px 8px 8px 14px; min-height: 52px; }
.tune-list .nm { flex: 1; min-width: 0; } .tune-list .nm b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tune-list .nm small { color: var(--muted); }
.tune-list .tag { font-size: 11px; color: var(--accent); border: 1px solid rgba(91,157,255,.4); border-radius: 99px; padding: 1px 8px; margin-left: 6px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: #0d1320; color: var(--text); font-size: 16px; cursor: pointer; touch-action: manipulation; }
.foot { text-align: center; color: #56627a; font-size: 12px; padding: 8px 8px 0; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { .rec.recording { animation: none; } .conf-bar { transition: none; } }
@media (min-width: 700px) { body { font-size: 17px; } }
