:root {
  --ink: #0b0a12; --ink2: #14121f; --line: #2a2740; --text: #efeaf7; --dim: #9a93b4;
  --them: #ff9628; --you: #2882ff; --both: #ffffff; --warn: #ff4d6d;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", "Noto Serif CJK SC", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ink); color: var(--text); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--both); outline-offset: 2px; }

.app { position: relative; isolation: isolate; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 28px; max-width: 1360px; margin: 0 auto; padding: 14px 16px 28px; }
.top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; padding: 4px 0 10px; }
.mark { margin: 0; font: italic 600 26px/1 var(--serif); letter-spacing: -0.02em; }
.logo { width: 38px; height: 21px; align-self: center; margin-right: -4px; overflow: visible; }
.logo path { fill: none; stroke-width: 4.5; stroke-linecap: round; mix-blend-mode: screen; }
.logo .lo { stroke: var(--them); } .logo .lb { stroke: var(--you); }
@media (prefers-reduced-motion: no-preference) { .logo .lb { animation: weave 5.2s ease-in-out infinite; } }
@keyframes weave { 50% { transform: translateY(-2px) scaleY(.82); transform-origin: center; } }
.tag { margin: 0; color: var(--dim); font-size: 14px; }

.stage-col { min-width: 0; }
.stage { position: relative; height: min(56vh, 480px); min-height: 320px; overflow: visible; --meet: 0; }
/* the page itself is the stage: a light behind the ribbons that follows what the two voices do (--meet is the live in-tune share) */
.app::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .9; transition: opacity .6s;
  background:
    radial-gradient(60% 55% at 22% 34%, #ff96282e, transparent 70%),
    radial-gradient(50% 50% at 80% 40%, #2882ff00, transparent 70%),
    radial-gradient(40% 36% at 50% 38%, color-mix(in srgb, #fff calc(var(--meet) * 26%), transparent), transparent 70%); }
body[data-s="loop"] .app::before { background:
    radial-gradient(60% 55% at 22% 34%, #ff962845, transparent 70%),
    radial-gradient(40% 36% at 50% 38%, color-mix(in srgb, #fff calc(var(--meet) * 26%), transparent), transparent 70%); }
body[data-s="duet"] .app::before { background:
    radial-gradient(55% 55% at 18% 34%, #ff962842, transparent 70%),
    radial-gradient(55% 55% at 84% 40%, #2882ff40, transparent 70%),
    radial-gradient(44% 40% at 50% 38%, color-mix(in srgb, #fff calc(var(--meet) * 30%), transparent), transparent 72%); }
.stage::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: linear-gradient(90deg, transparent, #ffffff30 20%, #ffffff30 80%, transparent); pointer-events: none; }
/* the native's phonemes under its ribbon; the top is the canvas's staff bottom (PAD_B in app.js is 92: letters from 88 px under the picture's end) */
.phones { position: absolute; left: var(--gut, 0px); right: 0; top: calc(100% - 88px); height: 32px; pointer-events: none; }
.ph { position: absolute; top: 0; transform: translateX(-50%); font: 400 12px/14px var(--mono); color: var(--them); opacity: .72; white-space: nowrap; transition: color .25s, opacity .25s, transform .25s, text-shadow .25s; }
.ph.low { top: 15px; }
.ph.lit { color: var(--warn); opacity: 1; font-weight: 700; transform: translateX(-50%) scale(1.45); text-shadow: 0 0 10px #ff4d6dcc; }
@media (prefers-reduced-motion: reduce) { .ph { transition: none; } }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }
.phrase { position: absolute; left: 16px; right: 16px; top: 12px; pointer-events: none; font: italic 400 clamp(30px, 8.4vw, 64px)/1.04 var(--serif); letter-spacing: -0.02em; text-shadow: 0 2px 18px #000a; }
.phrase[lang="zh"], .phrase[lang="ru"] { font-style: normal; }
.strip { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 10px 2px 0; }
.legend { display: flex; align-items: center; gap: 6px; font: 12px/1 var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .08em; }
.legend .k { display: inline-flex; align-items: center; gap: 6px; margin-right: 10px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; }
.dot.them { background: var(--them); } .dot.you { background: var(--you); } .dot.both { background: var(--both); } .dot.ex { background: rgb(175 150 255); }
body[data-s="idle"] .legend .k.you, body:not([data-s="idle"]) .legend .k.ex, body:not([data-s]) .legend .k.you { display: none; }
.readout { display: grid; grid-template-columns: auto auto 1fr; column-gap: 22px; row-gap: 12px; align-items: end; }
.readout .when { text-align: right; } .readout .when b { justify-content: flex-end; }
.readout .detail { grid-column: 1 / -1; }
.readout { position: relative; }
/* before the first scored loop the readout is one sentence, in the room the numbers will take: nothing jumps when they come */
.invite { position: absolute; left: 0; right: 0; top: 0; height: 96px; margin: 0; display: flex; align-items: center; font: italic 400 22px/1.2 var(--serif); color: #e6e2f5; text-wrap: balance; }
body[data-r="on"] .invite { display: none; }
/* no voice heard in the loop: no timing either, its room kept */
.readout:has(#inTune[data-v="none"]) .when { visibility: hidden; }
body:not([data-r="on"]) .readout > div:not(.detail), body:not([data-r="on"]) .readout :is(.ceil, .gauge, .rise) { visibility: hidden; }
.strip .readout { flex: 1 1 100%; }
.readout b { display: flex; align-items: flex-end; justify-content: flex-start; white-space: nowrap; height: 38px; margin-bottom: 2px; font: 600 24px/1.1 var(--mono); font-variant-numeric: tabular-nums; }
.readout .tune b { font-size: 34px; color: #fff; text-shadow: 0 0 22px #ffffff55; }
.readout small { font: 11px/1 var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .08em; }
.readout small.ceil { display: block; margin-top: 6px; white-space: nowrap; font-size: 12px; letter-spacing: .06em; color: #c9c2e4; }
.gauge { display: block; visibility: hidden; position: relative; height: 6px; margin-top: 7px; border-radius: 9px; background: #ffffff14; overflow: visible; }
.gauge.on { visibility: visible; }
.gauge i:first-child { position: absolute; left: 0; top: 0; bottom: 0; width: var(--g-you, 0%); border-radius: 9px; background: linear-gradient(90deg, #2882ff, #fff); transition: width .6s; }
.gauge i:last-child { position: absolute; left: var(--g-nat, 0%); top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--them); box-shadow: 0 0 8px var(--them); }
.readout small.ceil:empty, .readout small.rise:empty { visibility: hidden; } .readout small.ceil:empty::before, .readout small.rise:empty::before { content: "\a0"; }
.trail { position: relative; display: flex; gap: 4px; align-items: flex-end; justify-content: flex-start; height: 48px; margin-top: 10px; padding-right: 54px; border-bottom: 1px solid #ffffff1f; }
.trail:empty { justify-content: flex-start; align-items: center; }
.trail:empty::before, .trail[style*="--nat"]:empty::before { content: "bars: your loops · line: two natives"; white-space: nowrap; position: static; transform: none; font: 12px/1 var(--mono); letter-spacing: .04em; color: var(--dim); }
.trail i { flex: 0 0 10px; height: max(2px, var(--h, 0%)); border-radius: 3px 3px 1px 1px; background: #2882ff; opacity: .55; transition: height .5s; }
.trail i:last-child { opacity: 1; background: linear-gradient(#fff, #2882ff); }
.trail[style*="--nat"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: var(--nat); border-top: 1px dashed var(--them); opacity: .8; pointer-events: none; }
.trail[style*="--nat"]::before { content: "natives"; position: absolute; right: 0; bottom: var(--nat); transform: translateY(-3px); font: 10px/1 var(--mono); letter-spacing: .06em; color: var(--them); }
.readout small.rise { display: block; margin-top: 6px; white-space: nowrap; font-size: 11px; letter-spacing: .04em; text-transform: none; color: #e6e2f5; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.btn { min-height: 52px; padding: 0 22px; border-radius: 14px; border: 1px solid var(--line); background: var(--ink2); cursor: pointer; font-weight: 600; font-size: 16px; letter-spacing: .01em; flex: 1 1 140px; transition: transform .08s, background .2s, box-shadow .2s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--them); color: #1a0e00; border-color: transparent; box-shadow: 0 0 28px #ff962855; flex: 2 1 170px; }
.btn.listen { background: transparent; color: var(--dim); flex: 1 1 100px; padding: 0 14px; white-space: nowrap; }
.controls .btn[hidden] { display: none !important; }
.btn.voice { background: #2882ff26; color: #8fc0ff; border-color: var(--you); }
/* listening is a state, not a button: a live dot and plain words in the button's own room */
.btn.voice[aria-pressed="true"] { display: inline-flex; flex-wrap: wrap; align-items: center; align-content: center; justify-content: center; gap: 4px 10px; padding: 0 4px; background: transparent; border-color: transparent; box-shadow: none; color: #8fc0ff; font-weight: 500; }
.btn.voice[aria-pressed="true"]::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--you); animation: live 1.4s ease-out infinite; }
.btn.voice[aria-pressed="true"]::after { content: "tap to stop"; flex: 0 0 100%; font: 11px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--dim); }
@keyframes live { from { box-shadow: 0 0 0 0 #2882ffaa; } to { box-shadow: 0 0 0 9px #2882ff00; } }
.btn.voice.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px #2882ff33; } }
.switch { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 4px; cursor: pointer; flex: 1 1 180px; color: var(--dim); font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 44px; height: 44px; margin: 0; cursor: pointer; }
.switch .track { position: relative; width: 46px; height: 26px; border-radius: 99px; background: var(--line); transition: background .2s; flex: none; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); transition: transform .2s; }
.switch input:checked + .track { background: #2a5bb0; }
.switch input:checked + .track .knob { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--both); outline-offset: 2px; }
.switch { position: relative; }

.hint { margin: 10px 2px 0; color: var(--dim); font-size: 14px; line-height: 1.45; }
.kept { margin: 14px 2px 0; color: var(--dim); font-size: 13px; letter-spacing: .02em; }
.send { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 12px 0 0; }
.send .btn.ghost { flex: 0 1 auto; min-height: 44px; margin-top: 0; font-size: 15px; color: var(--you); border-color: color-mix(in srgb, var(--you) 55%, transparent); }
.send-msg { color: var(--dim); font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.hint.warn { color: #ffb4c0; }
.credit { margin: 6px 2px 0; font: 12px/1.5 var(--mono); color: var(--dim); }
.credit a { color: var(--dim); }
.status { margin: 4px 2px 0; min-height: 1.3em; font-size: 13px; color: var(--warn); }

/* the offer: a quiet block under the loop's controls; the amber outline is the only thing that asks to be pressed */
.offer { position: relative; margin-top: 22px; padding: 18px 2px 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.offer::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; background: linear-gradient(90deg, transparent, #ffffff30 20%, #ffffff30 80%, transparent); }
.offer [hidden] { display: none !important; }
.offer h2 { margin: 0; font: italic 600 22px/1.15 var(--serif); letter-spacing: -0.01em; }
.offer p { margin: 0; }
.offer-lede { color: var(--text); font-size: 15px; line-height: 1.45; max-width: 52ch; }
.offer-price { font: 13px/1.4 var(--mono); color: var(--dim); }
.offer-price b { color: var(--them); font-weight: 600; font-size: 15px; letter-spacing: .01em; }
.btn.ghost { background: transparent; color: var(--them); border-color: var(--them); margin-top: 6px; }
.btn.ghost[aria-expanded="true"] { display: none; }
.offer-form { display: grid; gap: 6px; margin-top: 6px; }
.offer-form label { font: 11px/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--dim); }
.offer-form .row { display: flex; flex-wrap: wrap; gap: 10px; }
.offer-form input { flex: 2 1 200px; min-width: 0; min-height: 52px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--ink2); color: var(--text); font-size: 16px; }
.offer-form input::placeholder { color: #6f6a88; }
.offer-form input:focus-visible { outline: 2px solid var(--both); outline-offset: 2px; border-color: transparent; }
.offer-form .btn { flex: 1 1 110px; }
.offer-form .btn:disabled { opacity: .6; cursor: progress; }
.offer-msg { min-height: 1.3em; font-size: 13px; color: var(--warn); }
.offer-done { color: var(--text); font-size: 16px; line-height: 1.4; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--ink2); margin-top: 6px; }
.offer-done:focus-visible { outline: 2px solid var(--both); outline-offset: 2px; }
.offer-note { color: var(--dim); font-size: 12px; line-height: 1.5; max-width: 60ch; }
@media (min-width: 900px) { .offer { max-width: 520px; } }

.phrases { min-width: 0; margin-top: 18px; }
.langs { display: flex; gap: 8px; margin-bottom: 8px; }
.lang { flex: 1; min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 600; }
.lang[aria-pressed="true"] { background: var(--text); color: var(--ink); border-color: var(--text); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; border-top: 1px solid #ffffff12; }
.list li { border-bottom: 1px solid #ffffff12; }
.list button { position: relative; overflow: hidden; width: 100%; min-height: 52px; text-align: left; padding: 8px 12px 8px 16px; border-radius: 0; border: 0; background: transparent; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; transition: background .2s; }
.list button > *:not(.spark) { position: relative; }
.list .spark { position: absolute; left: 150px; right: 52px; top: 52%; bottom: 7px; width: calc(100% - 202px); height: 40%; pointer-events: none; opacity: .32; transition: opacity .25s; }
.list .spark path { fill: none; stroke: var(--them); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.list button::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--them); transform: scaleY(0); transition: transform .25s; }
.list button:hover { background: #ffffff08; } .list button:hover .spark { opacity: .55; }
.list button[aria-current="true"] { background: linear-gradient(90deg, #ff962826, transparent 75%); }
.list button[aria-current="true"]::before { transform: scaleY(1); }
.list button[aria-current="true"] .spark { opacity: .95; }
.list button[aria-current="true"] .spark path { filter: drop-shadow(0 0 4px #ff9628); }
.list .t { font: 400 17px/1.25 var(--serif); }
.list .d { font: 12px/1 var(--mono); color: var(--dim); }
.list .who { grid-column: 1 / -1; font: 12px/1.2 var(--mono); color: var(--dim); }

.foot { margin-top: 22px; color: var(--dim); font-size: 12px; line-height: 1.5; max-width: 60ch; }
.foot p { margin: 0; }

@media (min-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr) 380px; grid-template-areas: "top top" "stage list" "foot foot"; padding: 22px 32px 36px; }
  .top { grid-area: top; padding-bottom: 16px; }
  .stage-col { grid-area: stage; }
  .phrases { grid-area: list; margin-top: 0; }
  .foot { grid-area: foot; }
  .stage { height: min(60vh, 640px); min-height: 300px; }
  .list button { min-height: 66px; } .list .t { font-size: 18px; } .readout b { font-size: 28px; } .readout .tune b { font-size: 46px; height: 50px; }
  .mark { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) { .btn.voice.pulse, .btn.voice[aria-pressed="true"]::before { animation: none; } }
@media (min-width: 900px) { .ph { font-size: 14px; line-height: 16px; } .ph.low { top: 17px; } .phones { height: 36px; } }

@media (max-width: 480px) { .readout { column-gap: 16px; } .readout small { font-size: 10px; letter-spacing: .04em; white-space: nowrap; } }
@media (min-width: 900px) {
  /* the numbers stand beside the ribbon, top to bottom of it: the eye goes across, not down; the buttons right under both */
  .stage-col { display: grid; grid-template-columns: minmax(0, 1fr) 260px; column-gap: 28px; align-content: start; }
  .stage-col > * { grid-column: 1 / -1; }
  .stage { grid-column: 1; grid-row: 1; height: clamp(300px, calc(100vh - 280px), 760px); height: clamp(300px, calc(100dvh - 280px), 760px); }
  .strip { grid-column: 2; grid-row: 1; flex-direction: column; flex-wrap: nowrap; align-items: stretch; justify-content: flex-start; gap: 22px; margin: 0; }
  .legend { flex-wrap: wrap; row-gap: 8px; padding-top: 14px; }
  .strip .readout { flex: 1 1 auto; }
  .readout { grid-template-columns: 1fr auto; grid-template-rows: auto auto 1fr; column-gap: 20px; row-gap: 18px; align-items: start; }
  .readout .tune { grid-column: 1; grid-row: 1; } .readout .when { grid-row: 2; grid-column: 1 / -1; text-align: left; } .readout .when b { justify-content: flex-start; }
  .readout > div:first-of-type { grid-row: 1; grid-column: 2; align-self: end; text-align: right; } .readout > div:first-of-type b { justify-content: flex-end; }
  /* the loop bars take the rest of the column, down to the ribbon's own floor: the rise is as tall as the picture */
  .readout .detail { grid-row: 3; align-self: stretch; display: flex; flex-direction: column; min-height: 0; }
  .readout b { height: 40px; font-size: 26px; } .readout .tune b { font-size: 72px; height: 76px; }
  .invite { height: 170px; font-size: 30px; line-height: 1.12; }
  .readout .tune b[data-v="none"] { font-size: 30px; color: var(--dim); text-shadow: none; }   /* no voice heard: a quiet dash, not a 72 px one */
  .trail:empty::before, .trail[style*="--nat"]:empty::before { font-size: 11px; letter-spacing: 0; }
  .trail { justify-content: flex-start; flex: 1 1 auto; height: auto; min-height: 110px; } .trail i { flex-basis: 18px; }
  .readout small, .legend { font-size: 12px; } .readout small.rise { font-size: 13px; }
  .controls { margin-top: 14px; }
  .hint { font-size: 15px; } .credit { font-size: 13px; } .foot { font-size: 13px; }
}

