/* Free the Noise: mobile-first. Light theme by default; `.dark` on <html> switches the
   tokens. --color-primary / --color-on-primary are the accent, set by ThemeManager. */

/* ---------- Tokens ---------- */

:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f3f4f6;
    --text: #111827;
    --muted: #4b5563;          /* 7:1 on --bg and --surface */
    --border: #e5e7eb;
    --track: #d1d5db;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(17, 24, 39, 0.06);

    --color-primary: #778899;
    --color-primary-darker: #708090;
    --color-primary-ring: #B0C4DE;
    --color-on-primary: #111827;

    --radius: 1rem;
    --radius-sm: 0.625rem;
    --gap: 1rem;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.dark {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #273449;
    --text: #f1f5f9;
    --muted: #a9b4c4;          /* 7:1 on --surface */
    --border: #334155;
    --track: #475569;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    line-height: 1.5;
    color: var(--text);
    /* A soft glow of the accent colour at the top; it follows the sound when "Match" is on */
    background:
        radial-gradient(120% 22rem at 50% -6rem, color-mix(in srgb, var(--color-primary) 28%, transparent), transparent),
        var(--bg);
    transition: color 0.2s;
}

h1, h2, p, fieldset, legend { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* One visible focus style for every control */
:focus-visible,
input:focus-visible + label,
.switch input:focus-visible ~ .switch-track {
    outline: 3px solid var(--color-primary-ring);
    outline-offset: 2px;
}

.page {
    max-width: 36rem;
    margin: 0 auto;
    padding: max(1rem, env(safe-area-inset-top)) 1rem max(1.5rem, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.section-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

/* ---------- Header ---------- */

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.875rem;
    padding: 0.75rem 0 0.25rem;
}
.brand-mark { width: 3.25rem; height: 2.6rem; flex-shrink: 0; overflow: visible; }
.brand h1 {
    font-size: 1.625rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
}
.tagline { font-size: 0.875rem; color: var(--muted); margin-top: 0.15rem; }

/* The six sound colours; White is a light grey and needs a darker shade on light backgrounds */
.bar { transform-box: fill-box; transform-origin: center; }
.bar--brown  { fill: #A0522D; }
.bar--pink   { fill: #FF69B4; }
.bar--green  { fill: #3CB371; }
.bar--white  { fill: #9CA3AF; }
.bar--blue   { fill: #4F8FC6; }
.bar--violet { fill: #9370DB; }
.dark .bar--white { fill: #E5E7EB; }

/* While playing, the bars move like a live spectrum */
.is-playing .bar { animation: bar-pulse 1.6s ease-in-out infinite alternate; }
.is-playing .bar--pink   { animation-delay: -0.3s; animation-duration: 1.3s; }
.is-playing .bar--green  { animation-delay: -0.9s; animation-duration: 1.9s; }
.is-playing .bar--white  { animation-delay: -0.5s; animation-duration: 1.4s; }
.is-playing .bar--blue   { animation-delay: -1.2s; animation-duration: 1.7s; }
.is-playing .bar--violet { animation-delay: -0.7s; animation-duration: 1.5s; }
@keyframes bar-pulse { from { transform: scaleY(1); } to { transform: scaleY(0.55); } }

/* ---------- Main: player card and panels ---------- */

.content { display: flex; flex-direction: column; gap: var(--gap); }

/* ---------- Player card ---------- */

.player {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 0.25rem);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Now playing */
.now { display: flex; align-items: center; gap: 1rem; }

.play-toggle {
    flex-shrink: 0;
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    display: grid;
    place-items: center;
    background: var(--color-primary);
    color: var(--color-on-primary);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s, background-color 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.play-toggle:hover { transform: scale(1.04); }
.play-toggle:active { transform: scale(0.96); }
.play-toggle svg { width: 2rem; height: 2rem; fill: currentColor; }
.play-toggle .icon-pause, .play-toggle[aria-pressed="true"] .icon-play { display: none; }
.play-toggle[aria-pressed="true"] .icon-pause { display: block; }

.now-text { min-width: 0; }
.now-title { font-size: 1.25rem; font-weight: 700; }
.now-status { font-size: 0.875rem; color: var(--muted); }

/* Spectrum: only takes space while shown */
.spectrum { display: none; width: 100%; height: 7rem; border-radius: var(--radius-sm); background: var(--surface-2); }
.spectrum.visible { display: block; }

/* Colour tiles */
.colour-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.625rem; }

.tile {
    --tile: #778899;
    --tile-on: #111827;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 4.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius);
    border: 2px solid transparent;
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--tile) 30%, transparent), color-mix(in srgb, var(--tile) 12%, transparent)),
        var(--surface-2);
    cursor: pointer;
    user-select: none;
    transition: transform 0.12s, background 0.2s, border-color 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.tile::before {
    content: "";
    position: absolute;
    top: 0.625rem;
    left: 0.75rem;
    width: 0.875rem;
    height: 0.875rem;
    border-radius: 50%;
    background: var(--tile);
    box-shadow: 0 0 0 2px var(--surface);
}
.tile:hover { border-color: color-mix(in srgb, var(--tile) 60%, transparent); }
.tile:active { transform: scale(0.97); }
.tile-name { font-weight: 700; }
.tile-hint { font-size: 0.75rem; color: var(--muted); }

input:checked + .tile { background: var(--tile); border-color: var(--tile); color: var(--tile-on); }
input:checked + .tile .tile-hint { color: inherit; }
input:checked + .tile::before { background: var(--tile-on); box-shadow: none; }

/* Text colour per tile: whichever of white / near-black has more contrast (WCAG AA) */
.tile--brown  { --tile: #A0522D; --tile-on: #ffffff; }
.tile--pink   { --tile: #FF69B4; --tile-on: #111827; }
.tile--green  { --tile: #3CB371; --tile-on: #111827; }
.tile--white  { --tile: #A9A9A9; --tile-on: #111827; }
.tile--blue   { --tile: #427AA9; --tile-on: #ffffff; }
.tile--violet { --tile: #9370DB; --tile-on: #111827; }

/* Volume */
.volume-row { display: flex; align-items: center; gap: 0.75rem; }
.volume-icon { width: 1.5rem; height: 1.5rem; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.volume-value { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.875rem; }

.volume-track { position: relative; flex: 1; height: 2.75rem; display: flex; align-items: center; }
.volume-track::before {
    content: "";
    position: absolute;
    left: 0; right: 0;
    height: 0.5rem;
    border-radius: 999px;
    background: var(--track);
}
/* Shows the level actually playing, including the breathing swell */
.volume-meter {
    position: absolute;
    left: 0;
    width: 0;
    max-width: 100%;
    height: 0.5rem;
    border-radius: 999px;
    background: var(--color-primary);
    pointer-events: none;
}
.volume-meter.idle { opacity: 0.35; }

input[type="range"] {
    position: relative;
    width: 100%;
    height: 2.75rem;
    margin: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 0.5rem; background: transparent; }
input[type="range"]::-moz-range-track { height: 0.5rem; background: transparent; }
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 1.5rem; height: 1.5rem; margin-top: -0.5rem;
    border-radius: 50%;
    background: var(--surface);
    border: 3px solid var(--color-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
    width: 1.125rem; height: 1.125rem;
    border-radius: 50%;
    background: var(--surface);
    border: 3px solid var(--color-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* Switches */
.switches { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.switch {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 0 0;
    cursor: pointer;
}
.switch + .switch { padding-top: 0.875rem; }
.switch-text { flex: 1; display: flex; flex-direction: column; }
.switch-name { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 600; }
.switch-hint { font-size: 0.8125rem; color: var(--muted); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
    position: relative;
    width: 3rem; height: 1.75rem;
    flex-shrink: 0;
    border-radius: 999px;
    background: var(--track);
    transition: background-color 0.2s;
}
.switch-track::after {
    content: "";
    position: absolute;
    top: 0.1875rem; left: 0.1875rem;
    width: 1.375rem; height: 1.375rem;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}
.switch input:checked ~ .switch-track { background: var(--color-primary); }
.switch input:checked ~ .switch-track::after { transform: translateX(1.25rem); }

.icon-wave { width: 1.125rem; height: 1.125rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-wave.animate { animation: wave 8s ease-in-out infinite; }
@keyframes wave { 0%, 100% { transform: scaleY(0.6); } 50% { transform: scaleY(1.3); } }

/* ---------- Panels (Appearance, Help) ---------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.panel summary {
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 3.25rem;
    padding: 0 1.25rem;
    font-weight: 600;
    cursor: pointer;
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: ""; width: 0.6rem; height: 0.6rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform 0.2s; margin-top: -0.25rem; }
.panel[open] summary::after { transform: rotate(-135deg); margin-top: 0.25rem; }
.panel-body { padding: 0 1.25rem 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }

/* Segmented control (theme) */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: var(--radius-sm); padding: 0.25rem; }
.segmented label { text-align: center; padding: 0.5rem; border-radius: calc(var(--radius-sm) - 0.25rem); cursor: pointer; font-size: 0.875rem; font-weight: 600; color: var(--muted); }
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* Accent chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips label {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 0.875rem;
    cursor: pointer;
}
.chips input:checked + label { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); font-weight: 600; }
.chip-dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; }
.chip-dot--match  { background: conic-gradient(#A0522D, #FF69B4, #3CB371, #A9A9A9, #427AA9, #9370DB, #A0522D); }
.chip-dot--brown  { background: #A0522D; }
.chip-dot--pink   { background: #FF69B4; }
.chip-dot--green  { background: #3CB371; }
.chip-dot--white  { background: #A9A9A9; }
.chip-dot--blue   { background: #427AA9; }
.chip-dot--violet { background: #9370DB; }

/* Help text */
.prose { gap: 0.75rem; }
.prose h2 { font-size: 1rem; margin-top: 0.5rem; }
.prose p, .prose ul { margin: 0; color: var(--muted); }
.prose ul { padding-left: 1.25rem; }
.prose strong { color: var(--text); }
.shortcuts { list-style: none; padding: 0 !important; display: grid; gap: 0.25rem; }
kbd {
    display: inline-block; min-width: 1.6em; padding: 0.05rem 0.4rem;
    border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 0.35rem;
    background: var(--surface-2); color: var(--text);
    font: 600 0.8125rem var(--font); text-align: center;
}

/* Contact form */
.contact-form { display: flex; flex-direction: column; gap: 0.35rem; }
.contact-form label { font-size: 0.875rem; font-weight: 600; margin-top: 0.5rem; }
.contact-form input, .contact-form textarea {
    width: 100%; padding: 0.625rem 0.75rem;
    font: inherit; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.contact-form textarea { resize: vertical; }
.form-status { font-size: 0.875rem; min-height: 1.25rem; }
.form-status.success { color: #15803d; }
.form-status.error { color: #b91c1c; }
.dark .form-status.success { color: #4ade80; }
.dark .form-status.error { color: #f87171; }

/* Buttons */
.button {
    margin-top: 0.75rem;
    align-self: flex-start;
    padding: 0.625rem 1.25rem;
    border: 0; border-radius: var(--radius-sm);
    background: var(--color-primary); color: var(--color-on-primary);
    font: 600 0.9375rem var(--font);
    cursor: pointer;
}
.button:disabled { opacity: 0.6; cursor: progress; }
.button--quiet { background: transparent; color: var(--text); border: 1px solid var(--border); margin: 0 0 0.75rem; align-self: center; }

/* ---------- Footer ---------- */

.footer { text-align: center; font-size: 0.875rem; color: var(--muted); padding: 0.5rem 0 1rem; display: flex; flex-direction: column; align-items: center; }
.footer .app-version { font-size: 0.75rem; margin-top: 0.25rem; }

/* ---------- Larger screens ---------- */

@media (min-width: 40rem) {
    .page, .content { gap: 1.25rem; }
    .page { padding-top: 2.5rem; }
    .brand { gap: 1.125rem; padding-bottom: 0.75rem; }
    .brand-mark { width: 4rem; height: 3.2rem; }
    .brand h1 { font-size: 2.125rem; }
    .tagline { font-size: 1rem; }
    .player { padding: 1.75rem; }
    .play-toggle { width: 5rem; height: 5rem; }
    .now-title { font-size: 1.5rem; }
    .tile { min-height: 5.5rem; }
}

/* Very narrow phones: two tiles per row */
@media (max-width: 22rem) {
    .colour-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
