/* Tonalitate & BPM — key and tempo detector (js/tonalitate.js). Theme-aware like the other tool pages: tokens on
   :root, redefined under body.dark-theme. Violet is the page's own colour; teal marks the measured result and amber
   the AI estimate, so the two never look alike. */
:root {
    --tn-bg: #f5f4fb;
    --tn-surface: #ffffff;
    --tn-surface-2: #f0eef9;
    --tn-ink: #1c1633;
    --tn-muted: #5f5a75;
    --tn-line: #e1def0;
    --tn-accent: #6d28d9;
    --tn-accent-ink: #ffffff;
    --tn-accent-soft: rgba(109, 40, 217, .10);
    --tn-measured: #0f766e;
    --tn-measured-soft: rgba(15, 118, 110, .10);
    --tn-ai: #b45309;
    --tn-ai-soft: rgba(180, 83, 9, .10);
    --tn-good: #15803d;
    --tn-warn: #b45309;
    --tn-shadow: 0 10px 30px rgba(28, 22, 51, .08);
}

body.dark-theme {
    --tn-bg: #110d1f;
    --tn-surface: #1b1630;
    --tn-surface-2: #241e3d;
    --tn-ink: #ece9f8;
    --tn-muted: #a7a1c0;
    --tn-line: #322b50;
    --tn-accent: #a78bfa;
    --tn-accent-ink: #1b1630;
    --tn-accent-soft: rgba(167, 139, 250, .14);
    --tn-measured: #2dd4bf;
    --tn-measured-soft: rgba(45, 212, 191, .12);
    --tn-ai: #fbbf24;
    --tn-ai-soft: rgba(251, 191, 36, .12);
    --tn-good: #4ade80;
    --tn-warn: #fbbf24;
    --tn-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll container that never
   scrolls, which silently kills any position: sticky inside. */
.tn-body, body.tn-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--tn-bg);
    color: var(--tn-ink);
    min-height: 100vh;
    overflow-x: clip;
}
.tn-main { padding-top: 100px; padding-bottom: 40px; }
.tn-main a { color: var(--tn-accent); }
.tn-wrap { max-width: 920px; display: grid; gap: 16px; }

/* ---- hero ---- */
.tn-hero { text-align: center; padding: 4px 0 18px; }
.tn-hero-icon { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; color: #fff; background: linear-gradient(135deg, #8b5cf6, #6d28d9 55%, #0f766e); box-shadow: var(--tn-shadow); }
.tn-kicker { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 8px; padding: 4px 12px; border-radius: 999px; background: var(--tn-measured-soft); color: var(--tn-measured); font-size: .8rem; font-weight: 600; }
.tn-hero h1 { font-weight: 800; font-size: clamp(1.7rem, 6vw, 2.5rem); letter-spacing: -.02em; margin: 0 0 10px; }
.tn-lead { max-width: 720px; margin: 0 auto; color: var(--tn-muted); line-height: 1.6; }
.tn-lead strong { color: var(--tn-ink); }

/* ---- cards ---- */
.tn-card { background: var(--tn-surface); border: 1px solid var(--tn-line); border-radius: 18px; padding: 18px; box-shadow: var(--tn-shadow); min-width: 0; }
.tn-card h2 { font-size: 1.1rem; font-weight: 700; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.tn-small { font-size: .86rem; color: var(--tn-muted); margin: 6px 0 0; line-height: 1.5; }
.tn-label { font-weight: 600; font-size: .9rem; margin-bottom: 6px; display: block; }
.tn-row { display: flex; gap: 8px; align-items: center; }
.tn-row-wrap { flex-wrap: wrap; margin-top: 10px; }
.tn-input, .tn-select { background: var(--tn-surface-2); color: var(--tn-ink); border-color: var(--tn-line); border-radius: 12px; }
.tn-input:focus, .tn-select:focus { background: var(--tn-surface-2); color: var(--tn-ink); border-color: var(--tn-accent); box-shadow: 0 0 0 3px var(--tn-accent-soft); }
.tn-input::placeholder { color: var(--tn-muted); opacity: .8; }
.tn-select { width: auto; min-width: 88px; }

.tn-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 12px; padding: 9px 16px; font-weight: 600; border: 1px solid var(--tn-line); background: var(--tn-surface-2); color: var(--tn-ink); min-height: 44px; }
.tn-btn:hover, .tn-btn:focus-visible { border-color: var(--tn-accent); color: var(--tn-ink); background: var(--tn-surface-2); }
.tn-btn-primary { background: var(--tn-accent); border-color: var(--tn-accent); color: var(--tn-accent-ink); }
.tn-btn-primary:hover, .tn-btn-primary:focus-visible { background: var(--tn-accent); color: var(--tn-accent-ink); filter: brightness(1.08); }
.tn-btn:disabled { opacity: .55; cursor: not-allowed; }
.tn-btn-small { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.tn-link-btn { border: 0; background: none; padding: 0; color: var(--tn-accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* ---- tabs ---- */
.tn-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--tn-surface-2); margin-bottom: 16px; }
.tn-tab { border: 0; background: transparent; color: var(--tn-muted); border-radius: 10px; padding: 9px 6px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; }
.tn-tab.is-active { background: var(--tn-surface); color: var(--tn-ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.tn-tab:focus-visible { outline: 2px solid var(--tn-accent); outline-offset: 1px; }

/* ---- file drop ---- */
.tn-drop { border: 2px dashed var(--tn-line); border-radius: 16px; padding: 22px 14px; text-align: center; transition: border-color .15s, background .15s; }
.tn-drop.is-over { border-color: var(--tn-accent); background: var(--tn-accent-soft); }
.tn-drop-title { font-weight: 600; margin: 0 0 10px; }
.tn-file-native { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: 0 !important; opacity: 0 !important; pointer-events: none !important; }
.tn-private { display: flex; gap: 6px; align-items: baseline; }

/* ---- YouTube methods ---- */
.tn-methods { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.tn-method { border: 1px solid var(--tn-line); border-radius: 14px; padding: 14px; background: var(--tn-surface-2); min-width: 0; }
.tn-method h3 { font-size: 1rem; font-weight: 700; margin: 0 0 6px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tn-method .tn-btn { margin-top: 10px; }
.tn-method .tn-row-wrap .tn-btn { margin-top: 0; }
.tn-method-off { opacity: .95; }
.tn-steps { padding-left: 1.2rem; margin: 6px 0 0; font-size: .9rem; line-height: 1.6; }
.tn-key { margin-top: 12px; font-size: .88rem; }
.tn-key summary { cursor: pointer; color: var(--tn-muted); font-weight: 600; }
.tn-key .tn-row { margin-top: 8px; }
.tn-key .tn-btn { margin-top: 0; }
.tn-pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--tn-accent-soft); color: var(--tn-accent); letter-spacing: .02em; }
.tn-pill-ai { background: var(--tn-ai-soft); color: var(--tn-ai); }
.tn-pill-measured { background: var(--tn-measured-soft); color: var(--tn-measured); }

/* ---- live / working ---- */
.tn-live-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.tn-live-time { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--tn-muted); }
.tn-rec { width: 12px; height: 12px; border-radius: 50%; background: #dc2626; animation: tn-pulse 1.2s ease-in-out infinite; }
@keyframes tn-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .tn-rec { animation: none; } }
.tn-bar { height: 8px; border-radius: 999px; background: var(--tn-surface-2); overflow: hidden; }
.tn-bar span { display: block; height: 100%; width: 0; background: var(--tn-accent); border-radius: inherit; transition: width .2s linear; }
.tn-meter { height: 4px; border-radius: 999px; background: var(--tn-surface-2); overflow: hidden; margin-top: 6px; }
.tn-meter span { display: block; height: 100%; width: 0; background: var(--tn-measured); transition: width .08s linear; }
.tn-live-guess { margin: 12px 0; font-weight: 600; }
.tn-work p { margin: 0 0 10px; font-weight: 600; }
.tn-error { border-radius: 14px; margin: 0; }

/* ---- results ---- */
.tn-results { display: grid; gap: 16px; }
.tn-result { border-top: 4px solid var(--tn-measured); }
.tn-result-ai { border-top-color: var(--tn-ai); }
.tn-res-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tn-res-head .tn-src { color: var(--tn-muted); font-size: .86rem; overflow-wrap: anywhere; min-width: 0; }
.tn-res-head .tn-btn { margin-left: auto; }
.tn-res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tn-big { border-radius: 14px; background: var(--tn-surface-2); padding: 14px; min-width: 0; }
.tn-big-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--tn-muted); font-weight: 700; }
.tn-big-value { font-size: clamp(1.5rem, 5.5vw, 2.1rem); font-weight: 800; line-height: 1.15; margin: 4px 0 2px; overflow-wrap: anywhere; }
.tn-big-sub { color: var(--tn-muted); font-size: .92rem; }
.tn-camelot { display: inline-grid; place-items: center; min-width: 44px; height: 30px; padding: 0 8px; border-radius: 9px; font-weight: 800; color: #fff; font-size: .95rem; vertical-align: middle; margin-left: 4px; }
.tn-bpm-unit { font-size: 1rem; font-weight: 700; color: var(--tn-muted); margin-left: 4px; }
.tn-conf { margin-top: 10px; }
.tn-conf-row { display: flex; justify-content: space-between; font-size: .8rem; color: var(--tn-muted); margin-bottom: 4px; }
.tn-conf .tn-bar span { background: var(--tn-measured); }
.tn-result-ai .tn-conf .tn-bar span { background: var(--tn-ai); }
.tn-alts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tn-chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--tn-line); font-size: .82rem; background: var(--tn-surface); font-variant-numeric: tabular-nums; }
.tn-possible { margin-top: 6px; font-size: .88rem; color: var(--tn-warn); font-weight: 600; }

.tn-sub { margin-top: 16px; }
.tn-sub h3 { font-size: .95rem; font-weight: 700; margin: 0 0 8px; }
.tn-top { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.tn-top li { display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.tn-top .tn-camelot { height: 24px; min-width: 38px; font-size: .8rem; margin: 0; }

/* chroma: 12 bars */
.tn-chroma { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 120px; }
.tn-chroma-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.tn-chroma-bar { width: 100%; border-radius: 6px 6px 2px 2px; background: var(--tn-line); min-height: 3px; }
.tn-chroma-col.in-scale .tn-chroma-bar { background: color-mix(in srgb, var(--tn-measured) 55%, transparent); }
.tn-chroma-col.is-tonic .tn-chroma-bar { background: var(--tn-measured); }
.tn-chroma-lbl { font-size: .68rem; color: var(--tn-muted); margin-top: 4px; white-space: nowrap; }
.tn-chroma-col.is-tonic .tn-chroma-lbl { color: var(--tn-ink); font-weight: 700; }

/* key over time */
.tn-strip { display: flex; height: 30px; border-radius: 9px; overflow: hidden; border: 1px solid var(--tn-line); }
.tn-strip span { display: grid; place-items: center; color: #fff; font-size: .72rem; font-weight: 700; min-width: 0; overflow: hidden; white-space: nowrap; text-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.tn-strip-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--tn-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.tn-spark { width: 100%; height: 70px; display: block; }
.tn-spark .tn-spark-line { fill: none; stroke: var(--tn-measured); stroke-width: 2; vector-effect: non-scaling-stroke; }
.tn-spark .tn-spark-grid { stroke: var(--tn-line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.tn-spark text { fill: var(--tn-muted); font-size: 10px; }

.tn-play { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tn-play-time { font-variant-numeric: tabular-nums; color: var(--tn-muted); font-size: .88rem; }
.tn-meta { font-size: .85rem; color: var(--tn-muted); margin: 14px 0 0; line-height: 1.6; }
.tn-ai-notes { margin: 12px 0 0; font-size: .92rem; }
.tn-ai-disclaimer { margin-top: 10px; font-size: .82rem; color: var(--tn-muted); }

.tn-agree { border-radius: 14px; padding: 12px 14px; font-weight: 600; display: flex; gap: 10px; align-items: flex-start; }
.tn-agree.is-ok { background: var(--tn-measured-soft); color: var(--tn-measured); }
.tn-agree.is-diff { background: var(--tn-ai-soft); color: var(--tn-ai); }

.tn-note p { margin: 0 0 8px; line-height: 1.6; }
.tn-how summary { font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.tn-how ul { margin: 12px 0 0; padding-left: 1.2rem; line-height: 1.6; font-size: .92rem; }
.tn-how li { margin-bottom: 6px; }
.tn-powered { text-align: center; color: var(--tn-muted); font-size: .85rem; margin: 24px 0 0; }

@media (max-width: 720px) {
    .tn-methods, .tn-res-grid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
    .tn-card { padding: 14px; border-radius: 16px; }
    .tn-tab { font-size: .88rem; gap: 5px; }
    .tn-chroma { gap: 2px; height: 100px; }
    .tn-chroma-lbl { font-size: .6rem; }
    .tn-row:not(.tn-row-wrap) { flex-wrap: wrap; }
    .tn-row:not(.tn-row-wrap) .tn-input { flex: 1 1 100%; }
}
