:root {
  color-scheme: light;
  --bg: #C6CCBE;
  --grout: #B3BAAB;
  --panel: #DDE1D6;
  --ink: #1F231E;
  --muted: #4B5348;
  --line: #9DA596;
  --rust: #8B3A1C;
  --red: #9E1219;
  --red-ink: #FFF4EE;
  --label: #E6DCC4;
  --label-ink: #2A241D;
  --bakelite: #2D2824;
  --bakelite-hi: #4A433D;
  --metal: #B7B2A8;
  --tape: #4B3122;
  --well: #15110E;
  --focus: #1F5FA8;
  --type: "Special Elite", "Courier New", Courier, monospace;
  --sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161B17;
    --grout: #1E2420;
    --panel: #212823;
    --ink: #DCE0D5;
    --muted: #9AA394;
    --line: #3B443C;
    --rust: #C46634;
    --red: #B8222A;
    --label: #D6CCB3;
    --bakelite: #0E0C0B;
    --bakelite-hi: #2E2925;
    --metal: #8E897F;
    --focus: #7FB2F0;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161B17; --grout: #1E2420; --panel: #212823; --ink: #DCE0D5; --muted: #9AA394;
  --line: #3B443C; --rust: #C46634; --red: #B8222A; --label: #D6CCB3; --bakelite: #0E0C0B;
  --bakelite-hi: #2E2925; --metal: #8E897F; --focus: #7FB2F0;
}
*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grout) 2px, transparent 2px),
    linear-gradient(90deg, var(--grout) 2px, transparent 2px);
  background-size: 56px 56px;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 560px; margin: 0 auto; padding: 20px 16px 48px; }
h1 {
  font-family: var(--type);
  font-weight: 400;
  font-size: clamp(2.1rem, 9vw, 2.9rem);
  line-height: 1.05;
  margin: 6px 0 6px;
}
.lead { margin: 0 0 20px; color: var(--muted); max-width: 52ch; }
h2 { font-family: var(--sans); font-size: 1.15rem; font-weight: 700; margin: 0 0 10px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Nauhuri */
.recorder {
  background: var(--bakelite);
  border-radius: 22px 22px 30px 30px;
  padding: 14px 14px 16px;
  box-shadow: inset 0 1px 0 var(--bakelite-hi), 0 12px 26px rgba(0, 0, 0, .28);
  color: var(--label);
}
.grille {
  height: 12px;
  margin: 2px 22% 12px;
  background-image: radial-gradient(circle, var(--bakelite-hi) 1.7px, transparent 2.2px);
  background-size: 8px 8px;
}
.window {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: var(--well);
  border: 2px solid var(--bakelite-hi);
}
.reel {
  flex: 0 0 62px;
  height: 62px;
  border-radius: 50%;
  background-color: #120F0C;
  background-image:
    radial-gradient(circle, var(--metal) 0 8px, transparent 9px),
    conic-gradient(var(--metal) 0 16deg, transparent 16deg 120deg, var(--metal) 120deg 136deg, transparent 136deg 240deg, var(--metal) 240deg 256deg, transparent 256deg);
  border: 9px solid var(--tape);
  box-shadow: 0 0 0 2px var(--bakelite-hi);
}
.recorder.playing .reel { animation: spin 1.7s linear infinite; }
.recorder.playing .reel + .scope + .reel { animation-duration: 2.3s; }
@keyframes spin { to { transform: rotate(360deg); } }
.scope { flex: 1 1 auto; min-width: 0; width: 100%; height: 56px; display: block; }
.sticker {
  margin: 14px 2px 0;
  padding: 10px 12px 11px;
  min-height: 3.4em;
  background: var(--label);
  color: var(--label-ink);
  font-family: var(--type);
  font-size: 1.08rem;
  line-height: 1.35;
  border-radius: 3px;
  transform: rotate(-0.7deg);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .25);
  overflow-wrap: anywhere;
}
.status { margin: 10px 4px 0; font-size: .9rem; color: var(--metal); min-height: 1.5em; }

/* Oma lause */
.compose { margin-top: 26px; }
.compose label { display: block; font-weight: 700; margin-bottom: 6px; }
textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  padding: 12px 13px;
  font: inherit;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 10px;
}
textarea::placeholder { color: var(--muted); opacity: .85; }
.lang { margin: 14px 0 0; padding: 0; border: 0; min-width: 0; }
.lang legend { font-size: .9rem; color: var(--muted); margin: 0 0 6px; padding: 0; }
.seg { display: flex; }
.lang label {
  flex: 1;
  position: relative;
  text-align: center;
  padding: 10px 8px;
  border: 2px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-weight: 600;
}
.lang label:first-of-type { border-radius: 10px 0 0 10px; border-right-width: 1px; }
.lang label:last-of-type { border-radius: 0 10px 10px 0; border-left-width: 1px; }
.lang input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.lang label:has(input:checked) { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.lang label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 1; }

.actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-top: 14px; }
.btn {
  min-height: 52px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  border-radius: 12px;
  cursor: pointer;
  border: 2px solid transparent;
  touch-action: manipulation;
}
.btn-primary { background: var(--red); color: var(--red-ink); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }

/* Repliikit */
.lines-wrap { margin-top: 34px; }
.lines-wrap p { margin: 0 0 12px; color: var(--muted); font-size: .92rem; }
.lines { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--line); }
.lines li { border-bottom: 2px solid var(--line); }
.line {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 4px;
  min-height: 64px;
  background: none;
  border: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.line .icon {
  flex: 0 0 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
}
.line .icon::before {
  content: "";
  width: 0; height: 0;
  border-left: 12px solid var(--ink);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  margin-left: 3px;
}
.line[aria-pressed="true"] .icon { background: var(--red); border-color: var(--red); }
.line[aria-pressed="true"] .icon::before { border: 0; width: 12px; height: 12px; margin: 0; background: var(--red-ink); }
.line.busy .icon { opacity: .5; }
.line-text { display: block; font-family: var(--type); font-size: 1.12rem; line-height: 1.3; }
.line-sub { display: block; font-size: .85rem; color: var(--muted); margin-top: 2px; }

/* Säädöt */
details.tune { margin-top: 34px; background: var(--panel); border: 2px solid var(--line); border-radius: 12px; }
details.tune summary { padding: 14px 16px; font-weight: 700; cursor: pointer; list-style-position: inside; }
.tune-body { padding: 0 16px 16px; }
.ctl { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 10px; margin: 14px 0 0; }
.ctl label { font-weight: 600; }
.ctl output { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctl input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--red); height: 32px; margin: 0; }
.ctl small { grid-column: 1 / -1; color: var(--muted); font-size: .82rem; margin-top: -4px; }
.reset { margin-top: 16px; width: 100%; }

.notes { margin-top: 30px; font-size: .88rem; color: var(--muted); }
.notes p { margin: 0 0 8px; max-width: 60ch; }

@media (prefers-reduced-motion: reduce) {
  .recorder.playing .reel { animation: none; }
  .btn-primary:active { transform: none; }
}

main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.line > span:last-child { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 360px) { .reel { flex-basis: 46px; height: 46px; } .window { gap: 8px; padding: 10px; } .actions { grid-template-columns: 1fr; } }
