@import url('theme.css');
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --text: #f4efe8;
    --muted: #b7aec9;
    --line: rgba(226, 179, 64, 0.28);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background: var(--ons-1);
    color: var(--text);
    font-family: Inter, Arial, sans-serif;
    line-height: 1.45;
}

body {
    width: 100%;
    min-height: 100dvh;
    padding: 0 16px calc(env(safe-area-inset-bottom));
}

button, input, select { font: inherit; color: inherit; }

a { color: var(--ons-accent); }

.app-nav {
    position: sticky;
    top: 0;
    z-index: 5;
    margin-left: -16px;
    margin-right: -16px;
    background: rgba(27, 20, 48, 0.94);
    border-bottom: 1px solid var(--line);
    padding-top: env(safe-area-inset-top);
}

.app-nav-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 760px;
    margin: 0 auto;
    padding: 0.7rem 1rem;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: inherit;
    text-decoration: none;
    min-width: 0;
}

.app-brand img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    flex: none;
}

.app-brand-text { display: flex; flex-direction: column; min-width: 0; }
.app-brand-name { font-weight: 700; letter-spacing: 0.01em; }
.app-brand-sub, .app-brand-by { color: var(--muted); font-size: 0.78rem; }

.app-shell {
    width: 100%;
    max-width: 728px;
    margin: 0 auto;
    padding: 1rem 0 2rem;
}

.phase {
    padding-left: 0;
    padding-right: 0;
}

.phase h1 {
    margin: 0.2rem 0 0.35rem;
    font-size: clamp(1.6rem, 6vw, 2.1rem);
}

.lede, .hint, .legal {
    color: var(--muted);
    margin: 0 0 1rem;
}

.legal { font-size: 0.82rem; }

.summary-chip {
    display: inline-block;
    margin: 0 0 1rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: var(--ons-2);
    border: 1px solid var(--line);
    color: var(--ons-accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.setup-group { margin: 0 0 1.5rem; }
.setup-group h2 {
    margin: 0 0 0.75rem;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}
.field { margin: 0 0 0.85rem; }
.field span, .choice-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
}

select, input[type="number"] {
    width: 100%;
    min-height: 48px;
    padding: 0.55rem 0.75rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--ons-2);
}

.choice-row {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.4rem;
}

.hear-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.choice {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    cursor: pointer;
}

.choice[aria-pressed="true"] {
    background: var(--ons-gradient-btn);
    color: #1b1430;
    border-color: transparent;
    font-weight: 700;
}

.choice small { display: block; font-weight: 500; opacity: 0.8; }

.custom-piano { margin-top: 0.4rem; }
.pkey-whites, .pkey-blacks { display: flex; gap: 0.35rem; }
.pkey-blacks { margin-bottom: 0.35rem; }
.pkey {
    flex: 1;
    min-height: 48px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
}
.pkey-white { background: #f4efe2; color: #1b1430; }
.pkey-black { background: #120e20; color: #f4efe2; border-color: rgba(226, 179, 64, 0.45); }
.pkey[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--ons-ok); }

.dock {
    position: sticky;
    bottom: 0;
    padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--ons-1) 28%);
}

.btn {
    width: 100%;
    min-height: 52px;
    border: 0;
    border-radius: 999px;
    background: var(--ons-gradient-btn);
    color: #1b1430;
    font-weight: 700;
    cursor: pointer;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-stop { background: var(--ons-bad); }
.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}

.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin: 1rem 0 1rem;
}

.message {
    padding: 0.75rem 0.85rem;
    border-radius: 12px;
    background: rgba(255, 93, 115, 0.12);
    color: #ffd0d6;
}

.live-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.mic-status {
    margin: 0.2rem 0 0.15rem;
    font-size: 1.15rem;
    font-weight: 700;
}

.mic-status.is-live { color: var(--ons-ok); }
.mic-status.is-wait { color: var(--ons-accent); }
.mic-status.is-dead { color: var(--ons-bad); }

.mic-device {
    margin: 0 0 0.55rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.ring {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(226, 179, 64, 0.25);
    border-top-color: var(--ons-accent);
    animation: ons-spin 0.8s linear infinite;
    flex: none;
}

.ring-lg { width: 54px; height: 54px; border-width: 4px; }

.level {
    height: 22px;
    border-radius: 99px;
    background: #3a2f6e;
    overflow: hidden;
    border: 1px solid var(--line);
}

.level > span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--ons-accent), var(--ons-ok));
}

.clock { font-variant-numeric: tabular-nums; color: var(--muted); }

.live-note {
    margin: 0.85rem 0 0.2rem;
    font-size: clamp(2.6rem, 12vw, 4.4rem);
    line-height: 1;
    font-weight: 700;
}

.live-note.is-held { opacity: 0.55; }

.cents { margin: 0.2rem 0 0.5rem; color: var(--muted); }

.judge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 32px;
    padding: 0.15rem 0.7rem;
    border-radius: 999px;
    background: var(--ons-2);
    font-weight: 700;
}

.judge-on { background: var(--ons-ok); color: #083224; }
.judge-off { background: var(--ons-bad); color: #3a1020; }
.judge-on::before { content: "✓ "; }
.judge-off::before { content: "× "; }

.live-roll {
    display: block;
    width: 100%;
    height: 280px;
    margin: 1rem 0 0.5rem;
    border-radius: 16px;
    background: #241c3d;
}

.play-time {
    margin: 0.35rem 0 0.45rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.scoring-card, .score-card, .sheet-card, .share-card {
    background: var(--ons-2);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1.1rem;
}

.scoring-card {
    min-height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.8rem;
}

.score-card { text-align: center; margin-bottom: 0.9rem; }
.score-label { margin: 0; color: var(--muted); font-size: 0.82rem; letter-spacing: 0.04em; text-transform: uppercase; }
.scale-score {
    margin: 0.15rem 0;
    font-size: clamp(3rem, 14vw, 4.5rem);
    line-height: 0.95;
    font-weight: 700;
    color: var(--ons-accent);
}
.tune-line { margin: 0.2rem 0 0; color: var(--muted); }

audio { width: 100%; margin: 0.4rem 0 0.8rem; }

.scroller {
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #241c3d;
    touch-action: pan-x pan-y;
}

.spacer { position: relative; min-width: 100%; }
.spacer canvas { display: block; }
.playhead {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    background: var(--ons-accent);
    pointer-events: none;
}

.list-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 1.5rem 0 0.5rem;
}
.list-tools h2 { margin: 0; font-size: 1rem; }
.check { color: var(--muted); font-size: 0.85rem; }

.note-list { list-style: none; margin: 0; padding: 0; }
.note-row {
    width: 100%;
    display: grid;
    grid-template-columns: 4.2rem 3.4rem 3.4rem 1fr;
    gap: 0.4rem;
    align-items: center;
    min-height: 48px;
    margin-bottom: 0.35rem;
    padding: 0.35rem 0.7rem;
    border-radius: 12px;
    border: 0;
    text-align: left;
    cursor: pointer;
}
.note-on { background: rgba(61, 220, 151, 0.16); }
.note-off { background: rgba(255, 93, 115, 0.18); }
.note-flag { font-weight: 700; }

.sheet {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: end center;
    padding: 1rem;
    background: rgba(8, 5, 16, 0.72);
}
.sheet[hidden] { display: none; }
.sheet-card { width: min(520px, 100%); margin-bottom: env(safe-area-inset-bottom); }
.sheet-card h2 { margin: 0 0 0.4rem; }
.sheet-actions { display: grid; gap: 0.45rem; }
.share-link {
    width: 100%;
    min-height: 44px;
    margin: 0.4rem 0;
    padding: 0.4rem 0.6rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--ons-1);
}

.app-footer {
    max-width: 760px;
    margin: 0 auto;
    padding: 0.5rem 1rem 1.4rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.share-body { padding: 1.2rem; }
.share-card { width: min(640px, 100%); margin: 0 auto; }
.share-kicker { color: var(--ons-accent); font-weight: 700; margin: 0; }
.share-scores span { color: var(--ons-accent); font-weight: 700; }
.share-misses { padding-left: 1.1rem; color: var(--muted); }

@keyframes ons-spin { to { transform: rotate(360deg); } }

@media (min-width: 800px) {
    .live-roll { height: 380px; }
    .app-shell { padding-top: 1.4rem; }
    .choice-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .hear-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    .ring { animation: none; }
}
