:root {
  color-scheme: dark;
  --bg: #11110f;
  --panel: #191916;
  --panel-2: #20201c;
  --border: #34332c;
  --border-strong: #4b493e;
  --text: #f4f1e8;
  --muted: #aaa69a;
  --accent: #e6b94b;
  --accent-hover: #f2ca65;
  --accent-ink: #17140b;
  --green: #6fd6a0;
  --danger: #ff8b7d;
  --focus: #77bdfb;
  --radius: 8px;
  font-family: Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button, textarea, select, input { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }

.topbar {
  width: min(1180px, calc(100% - 40px));
  height: 82px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.brand { color: var(--text); text-decoration: none; display: inline-flex; gap: 12px; align-items: center; }
.brand-copy { display: grid; direction: ltr; text-align: left; line-height: 1; }
.brand-copy strong { font-size: 20px; font-family: Arial, sans-serif; }
.brand-copy small { margin-top: 6px; color: var(--muted); font: 10px Arial, sans-serif; text-transform: uppercase; letter-spacing: 1.4px; }
.brand-mark { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; gap: 3px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--panel); }
.brand-mark i { display: block; width: 2px; border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(1), .brand-mark i:nth-child(5) { height: 8px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(4) { height: 16px; }
.brand-mark i:nth-child(3) { height: 23px; }

.locale-toggle {
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  direction: rtl;
}
.locale-toggle:hover { border-color: var(--border-strong); color: var(--text); }
.locale-active { color: var(--accent); font-weight: 700; }

main { width: min(980px, calc(100% - 40px)); margin: 0 auto; }
.intro { padding: 54px 0 30px; max-width: 760px; }
.eyebrow { color: var(--accent) !important; font-size: 13px; font-weight: 700; margin: 0 0 14px !important; }
.intro h1 { margin: 0; max-width: 700px; font-size: clamp(32px, 5vw, 56px); line-height: 1.2; font-weight: 800; }
.intro p { margin: 18px 0 0; max-width: 650px; color: var(--muted); font-size: 17px; line-height: 1.8; }

.studio {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .22);
}

.status-banner { display: flex; gap: 10px; align-items: center; padding: 12px 22px; border-bottom: 1px solid #584a28; background: #282318; color: #efd891; font-size: 13px; }
.status-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(230, 185, 75, .12); }

form { padding: 26px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.section-heading label, legend { color: var(--text); font-weight: 700; font-size: 14px; }
#characterCount, #speedValue { color: var(--muted); font: 12px Arial, sans-serif; direction: ltr; }
#characterCount.near-limit { color: var(--danger); }

.editor-shell { position: relative; border: 1px solid var(--border); border-radius: var(--radius); background: #141412; overflow: hidden; transition: border-color .2s, box-shadow .2s; }
.editor-shell:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(119, 189, 251, .12); }
textarea { width: 100%; min-height: 210px; padding: 20px 20px 64px; display: block; resize: vertical; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 18px; line-height: 1.9; caret-color: var(--accent); }
textarea::placeholder { color: #757267; }
.waveform { position: absolute; inset-inline: 20px; bottom: 18px; height: 27px; display: flex; align-items: center; gap: 4px; direction: ltr; opacity: .58; pointer-events: none; }
.waveform i { flex: 1; max-width: 4px; min-width: 2px; height: 4px; border-radius: 2px; background: var(--accent); transition: height .22s ease; }
.waveform i:nth-child(4n+1) { height: 10px; }
.waveform i:nth-child(5n+2) { height: 18px; }
.waveform i:nth-child(7n+3) { height: 25px; }
.waveform.active i { animation: voiceBar .9s ease-in-out infinite alternate; }
.waveform.active i:nth-child(2n) { animation-delay: -.35s; }
.waveform.active i:nth-child(3n) { animation-delay: -.6s; }
@keyframes voiceBar { from { height: 4px; opacity: .5; } to { height: 26px; opacity: 1; } }

.controls-grid { margin-top: 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 24px 18px; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 10px; padding: 0; }
.wide-control { grid-column: 1 / -1; }

.segmented { display: grid; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 7px; background: #141412; }
.segmented.two { grid-template-columns: 1fr 1fr; }
.segmented label { min-width: 0; }
.segmented input, .voice-options input, .performance-options input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { height: 40px; display: flex; justify-content: center; align-items: center; border-radius: 5px; color: var(--muted); font-size: 14px; }
.segmented input:checked + span { color: var(--text); background: var(--panel-2); box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.segmented input:focus-visible + span, .voice-options input:focus-visible + span, .performance-options input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

select { width: 100%; height: 50px; padding: 0 14px; border: 1px solid var(--border); border-radius: 7px; outline: 0; background: #141412; color: var(--text); }
select:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(119, 189, 251, .12); }

.voice-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.voice-options label span { min-height: 68px; padding: 11px 14px; display: grid; align-content: center; border: 1px solid var(--border); border-radius: 7px; background: #141412; transition: border-color .2s, background .2s; }
.voice-options b { font: 700 15px Arial, sans-serif; }
.voice-options small { margin-top: 5px; color: var(--muted); font-size: 12px; }
.voice-options input:checked + span { border-color: var(--accent); background: #252116; box-shadow: inset 0 0 0 1px rgba(230, 185, 75, .13); }

.performance-options { display: flex; flex-wrap: wrap; gap: 8px; }
.performance-options span { min-height: 40px; padding: 0 14px; display: flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; background: #141412; color: var(--muted); font-size: 13px; }
.performance-options input:checked + span { border-color: var(--accent); background: #252116; color: var(--text); }

.speed-control .section-heading { margin: 0 0 8px; }
.speed-control legend { margin: 0; }
.range-wrap { display: grid; grid-template-columns: 38px 1fr 38px; gap: 12px; align-items: center; direction: ltr; color: var(--muted); font: 11px Arial, sans-serif; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.message { margin-top: 22px; padding: 12px 14px; border: 1px solid rgba(255, 139, 125, .35); border-radius: 6px; background: rgba(255, 139, 125, .08); color: #ffc1b9; font-size: 14px; line-height: 1.6; }
.form-actions { margin-top: 25px; display: flex; gap: 10px; }
.primary-button, .secondary-button, .download-button { min-height: 48px; border-radius: 6px; font-weight: 700; text-decoration: none; transition: background .2s, border-color .2s, transform .1s; }
.primary-button { flex: 1; border: 0; background: var(--accent); color: var(--accent-ink); }
.primary-button:hover { background: var(--accent-hover); }
.primary-button:active, .secondary-button:active, .download-button:active { transform: translateY(1px); }
.primary-button:disabled { cursor: wait; opacity: .68; }
.secondary-button { min-width: 92px; border: 1px solid var(--border); background: transparent; color: var(--muted); }
.secondary-button:hover { border-color: var(--border-strong); color: var(--text); }
.button-loading { display: inline-flex; align-items: center; gap: 9px; }
.spinner { width: 17px; height: 17px; border: 2px solid rgba(23, 20, 11, .28); border-top-color: var(--accent-ink); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.result { padding: 24px 26px 27px; border-top: 1px solid var(--border); background: #151513; }
.result-heading { margin-bottom: 18px; display: flex; justify-content: space-between; align-items: center; }
.result-heading h2 { margin: 3px 0 0; font-size: 18px; }
.result-kicker { color: var(--green); font-size: 12px; font-weight: 700; }
.result-badge { padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); font: 10px Arial, sans-serif; }
audio { width: 100%; display: block; }
.download-button { margin-top: 14px; min-height: 44px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border-strong); color: var(--text); }
.download-button:hover { border-color: var(--accent); color: var(--accent); }

footer { width: min(980px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 38px; display: flex; justify-content: space-between; gap: 20px; color: #77746a; font-size: 12px; }
footer span:first-child { font-family: Arial, sans-serif; font-weight: 700; }
.hidden { display: none !important; }

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

html[dir="ltr"] .intro, html[dir="ltr"] textarea { text-align: left; }
html[dir="ltr"] .waveform { direction: ltr; }

@media (max-width: 680px) {
  .topbar, main, footer { width: min(100% - 28px, 980px); }
  .topbar { height: 70px; }
  .intro { padding: 36px 0 23px; }
  .intro h1 { font-size: 34px; }
  .intro p { font-size: 15px; }
  form, .result { padding: 19px; }
  .status-banner { padding: 11px 16px; }
  textarea { min-height: 190px; padding: 16px 16px 58px; font-size: 16px; }
  .waveform { inset-inline: 16px; }
  .controls-grid { grid-template-columns: 1fr; gap: 20px; }
  .wide-control { grid-column: auto; }
  .voice-options { grid-template-columns: 1fr; }
  .voice-options label span { min-height: 58px; grid-template-columns: 60px 1fr; align-items: center; }
  .voice-options small { margin: 0; }
  .form-actions { flex-direction: column; }
  .secondary-button { min-height: 44px; }
  footer { padding-bottom: 24px; flex-direction: column; gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
