/* Tone Generator
   Lab-instrument feel: single centered column, readout-first hierarchy.
   Uses only design tokens from main.css. */

.tg-container {
    max-width: 700px;
}

.tg-tool {
    margin: 0 auto;
}

.tg-tool:focus {
    outline: none;
}

.tg-tool:focus-visible {
    outline: none;
    box-shadow: none;
}

.tg-card {
    box-sizing: border-box;
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    padding: var(--space-6);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

/* Safety notice */
.tg-safety {
    margin: 0 0 var(--space-5);
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
    color: var(--color-warning-text);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-warning);
    border-left-width: 4px;
    border-radius: var(--radius-md);
}

/* Readout */
.tg-readout {
    position: relative;
    margin-bottom: var(--space-5);
    padding: var(--space-4) var(--space-5);
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.tg-readout-value {
    font-family: var(--font-mono);
    font-size: var(--font-size-4xl);
    line-height: var(--line-height-tight);
    color: var(--color-text);
}

.tg-readout-unit {
    font-size: var(--font-size-lg);
    color: var(--color-text-muted);
}

.tg-readout-glyph {
    display: inline-block;
    margin-inline-start: auto;
    width: 1.75em;
    height: 1.75em;
}

.tg-readout-glyph svg {
    width: 100%;
    height: 100%;
    color: var(--color-primary);
}

/* Frequency + volume sliders */
.tg-field {
    margin-bottom: var(--space-5);
}

.tg-field:last-child {
    margin-bottom: 0;
}

.tg-field-label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
}

.tg-slider {
    box-sizing: border-box;
    width: 100%;
    height: var(--space-12);
    margin: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.tg-slider:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.tg-slider:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Linear tick marks under the frequency slider.
   The slider is LINEAR (min=16, max=20000, step=1), so each mark is placed at
   the true linear frequency fraction: (freq - 16) / (20000 - 16) * 100%.
   1k -> 4.92%, 5k -> 24.94%, 10k -> 49.96%.
   The tick row is inset by the native range-thumb inset (~8px, half the ~16px
   thumb) so a mark at fraction f lines up with the thumb center, which
   travels from inset to width-inset rather than edge to edge. */
.tg-ticks {
    position: relative;
    height: var(--font-size-base);
    margin: var(--space-1) 8px 0;
}

.tg-tick {
    position: absolute;
    top: 0;
    padding-top: var(--space-1);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* 1px indicator line, centered on the tick so it sits exactly under the
   slider thumb position the label represents. */
.tg-tick::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: var(--space-1);
    background: var(--color-border);
}

.tg-tick-1k {
    left: 4.92%;
    transform: translateX(-50%);
}

.tg-tick-5k {
    left: 24.94%;
    transform: translateX(-50%);
}

.tg-tick-10k {
    left: 49.96%;
    transform: translateX(-50%);
}

/* Frequency number field + Play/Reset row */
.tg-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.tg-num {
    flex: 0 1 auto;
    min-width: 6rem;
}

.tg-freq-input {
    box-sizing: border-box;
    width: 100%;
    min-height: var(--space-12);
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.tg-freq-input:hover {
    border-color: var(--color-border-dark);
}

.tg-freq-input:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

.tg-freq-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tg-play {
    flex: 1 1 auto;
    min-height: var(--space-12);
    font-size: var(--font-size-base);
}

.tg-play-glyph {
    font-size: var(--font-size-sm);
    line-height: 1;
}

.tg-play.is-playing {
    box-shadow: inset 0 0 0 2px var(--color-primary-light);
}

.tg-play:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tg-reset {
    flex: 0 0 auto;
}

/* Frequency error message */
.tg-error {
    margin: calc(-1 * var(--space-2)) 0 var(--space-4);
    font-size: var(--font-size-sm);
    color: var(--color-error-text);
}

.tg-error[hidden] {
    display: none;
}

/* Segmented radio pills */
.tg-segments {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.tg-segment {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    flex: 1 1 auto;
    min-height: var(--space-10);
    padding: var(--space-2) var(--space-4);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.tg-segment:hover {
    border-color: var(--color-border-dark);
}

.tg-segment input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tg-segment input:focus-visible + .tg-segment-text {
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-full);
}

.tg-segment-text {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
    border-radius: var(--radius-full);
}

.tg-segment-desc {
    flex-basis: 100%;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.tg-segment:has(input:checked),
.tg-segment.is-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.tg-segment:has(input:checked) .tg-segment-text,
.tg-segment.is-active .tg-segment-text,
.tg-segment:has(input:checked) .tg-segment-desc,
.tg-segment.is-active .tg-segment-desc {
    color: var(--color-text-inverse);
}

.tg-segment:has(input:checked) .tg-segment-desc,
.tg-segment.is-active .tg-segment-desc {
    opacity: 0.85;
}

/* Volume row */
.tg-volume-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.tg-volume-row .tg-slider {
    flex: 1 1 auto;
}

.tg-volume-value {
    flex: 0 0 auto;
    min-width: 4ch;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    text-align: end;
}

/* Preset chips */
.tg-presets {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.tg-preset {
    font-family: var(--font-mono);
}

.tg-preset.is-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-text-inverse);
}

.tg-preset.is-active:hover {
    background: var(--color-primary-dark);
}

/* Sweep control */
.tg-sweep-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.tg-sweep-head .tg-field-label {
    margin-bottom: 0;
}

.tg-sweep-desc {
    margin: var(--space-2) 0 var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.tg-progress {
    width: 100%;
    height: var(--space-2);
    overflow: hidden;
    background: var(--color-bg-alt);
    border-radius: var(--radius-full);
}

.tg-progress-bar {
    display: block;
    width: 0%;
    height: 100%;
    background: var(--color-primary);
}

/* Playing state pulse (reduced-motion safe) */
@keyframes tgPulse {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.55;
    }
}

.tg-tool.is-playing .tg-readout-glyph {
    animation: tgPulse 1s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
    .tg-tool.is-playing .tg-readout-glyph {
        animation: none;
    }

    .btn,
    .tg-segment,
    .tg-freq-input {
        transition: none;
    }
}

/* Mobile */
@media (max-width: 479px) {
    .tg-card {
        padding: var(--space-4);
    }

    .tg-readout-value {
        font-size: var(--font-size-3xl);
    }

    .tg-row {
        flex-direction: column;
        align-items: stretch;
    }

    .tg-play {
        width: 100%;
    }

    .tg-segment-desc {
        display: none;
    }

    .tg-presets {
        flex-wrap: wrap;
    }

    .tg-sweep-head {
        flex-direction: column;
        align-items: stretch;
    }

    .tg-sweep-head .btn {
        width: 100%;
    }
}
