/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --red:        #cc3120;
  --red-hover:  #a82818;
  --rail-w:     52px;
  --panel-w:    268px;

  --bg:         #f5f3ef;
  --surface:    #ffffff;
  --border:     #e4dfd6;
  --ink:        #111009;
  --ink2:       #5a534c;
  --ink3:       #9a948e;
  --rail-bg:    #111009;
  --rail-icon:  rgba(255,255,255,0.45);
  --rail-active:#ffffff;
  --rail-hover: rgba(255,255,255,0.12);
  --panel-bg:   #ffffff;
}

[data-theme="dark"] {
  --bg:         #1a1917;
  --surface:    #232220;
  --border:     #2e2c2a;
  --ink:        #f0ece4;
  --ink2:       #a09890;
  --ink3:       #6a6460;
  --panel-bg:   #1e1c1a;
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
}

svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
a { text-decoration: none; color: inherit; }

/* ── Layout ──────────────────────────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Left rail ───────────────────────────────────────────────────────────────── */
.rail {
  width: var(--rail-w);
  background: var(--rail-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 2px;
  flex-shrink: 0;
  z-index: 10;
}

.rail-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  color: var(--rail-icon);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.rail-btn svg { width: 17px; height: 17px; }
.rail-btn:hover:not(:disabled) { background: var(--rail-hover); color: var(--rail-active); }
.rail-btn.active { color: var(--rail-active); }
.rail-btn:disabled { opacity: 0.25; cursor: default; }

.rail-sep { width: 28px; height: 1px; background: rgba(255,255,255,0.08); margin: 6px 0; }

/* ── Center ──────────────────────────────────────────────────────────────────── */
.center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 28px 24px 60px;
  gap: 20px;
  min-width: 0;
}

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.page-sub {
  font-size: 13px;
  color: var(--ink3);
}

/* ── Input card ──────────────────────────────────────────────────────────────── */
.input-card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-card:focus-within {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(204,49,32,0.10);
}

.input-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.char-count {
  font-size: 12px;
  color: var(--ink3);
  font-weight: 500;
  transition: color 0.2s;
}
.char-count.over { color: var(--red); font-weight: 600; }

.tts-textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: none;
  outline: none;
  background: transparent;
  font-family: 'Noto Serif SC', serif;
  font-size: 18px;
  line-height: 1.7;
  color: var(--ink);
}
.tts-textarea::placeholder {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  color: var(--ink3);
}

.input-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-paste {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink2);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: background 0.15s, color 0.15s;
}
.btn-paste svg { width: 12px; height: 12px; }
.btn-paste:hover { background: var(--border); color: var(--ink); }

.btn-clear-text {
  font-size: 12px;
  color: var(--ink3);
  padding: 5px 10px;
  border-radius: 6px;
  transition: background 0.15s;
}
.btn-clear-text:hover { background: var(--border); color: var(--ink2); }

/* ── Error ───────────────────────────────────────────────────────────────────── */
.error-state {
  width: 100%;
  max-width: 560px;
  background: #fdecea;
  color: var(--red);
  border: 1px solid rgba(204,49,32,0.2);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 13px;
}
[data-theme="dark"] .error-state {
  background: rgba(204,49,32,0.12);
  border-color: rgba(204,49,32,0.3);
}

/* ── Player card ─────────────────────────────────────────────────────────────── */
.player-card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Progress */
.progress-wrap { display: flex; flex-direction: column; gap: 6px; }

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--red);
  border-radius: 99px;
  transition: width 0.2s linear;
}
.progress-wave {
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, transparent, rgba(204,49,32,0.3), transparent);
  animation: wave 1.5s ease-in-out infinite;
  display: none;
}
.progress-wave.active { display: block; }

@keyframes wave {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.progress-char {
  font-family: 'Noto Serif SC', serif;
  font-size: 16px;
  color: var(--ink);
  min-height: 22px;
  transition: opacity 0.2s;
}
.progress-pct { font-size: 12px; color: var(--ink3); font-weight: 500; }

/* Player buttons */
.player-btns { display: flex; gap: 10px; align-items: center; }

.btn-play {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  background: var(--red);
  color: #fff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.btn-play:hover:not(:disabled) { background: var(--red-hover); }
.btn-play:disabled { opacity: 0.4; cursor: default; }
.btn-play svg { width: 15px; height: 15px; stroke: #fff; fill: #fff; }

.btn-stop {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--ink2);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn-stop:hover:not(:disabled) { background: var(--border); color: var(--ink); }
.btn-stop:disabled { opacity: 0.35; cursor: default; }
.btn-stop svg { width: 13px; height: 13px; fill: currentColor; stroke: none; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--ink3);
}
.empty-icon { font-size: 48px; line-height: 1; }
.empty-state p { font-size: 13px; }

/* ── Right panel ─────────────────────────────────────────────────────────────── */
.panel {
  width: var(--panel-w);
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: none;
}
.panel::-webkit-scrollbar { display: none; }

.panel-theme { display: flex; justify-content: flex-end; padding: 10px 12px 0; }
.theme-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  color: var(--ink2);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.theme-btn:hover { background: var(--border); }

.panel-body {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  flex: 1;
}

.panel-section { display: flex; flex-direction: column; gap: 8px; }

.panel-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Speed grid */
.speed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.speed-btn {
  padding: 6px 4px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink2);
  border: 1px solid var(--border);
  background: var(--bg);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  text-align: center;
}
.speed-btn:hover:not(.active) { background: var(--border); }
.speed-btn.active {
  background: var(--surface);
  color: var(--red);
  border-color: var(--red);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Voice select */
.voice-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.voice-select:focus { border-color: var(--red); }

/* Download */
.btn-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 10px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.btn-download:hover:not(:disabled) { background: #2a2820; }
.btn-download:disabled { opacity: 0.35; cursor: default; }
.btn-download svg { width: 14px; height: 14px; }
[data-theme="dark"] .btn-download { background: var(--ink); }
[data-theme="dark"] .btn-download:hover:not(:disabled) { background: var(--ink2); }

.download-note {
  font-size: 11px;
  color: var(--ink3);
  text-align: center;
}

/* ── Panel footer ────────────────────────────────────────────────────────────── */
.panel-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.footer-block { display: flex; flex-direction: column; gap: 6px; }

.footer-head {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.footer-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink2);
  transition: color 0.15s;
}
.footer-link:hover { color: var(--red); }
.footer-link svg { width: 13px; height: 13px; flex-shrink: 0; }

.footer-links { display: flex; align-items: center; gap: 5px; }
.footer-tiny { font-size: 11px; color: var(--ink3); transition: color 0.15s; }
a.footer-tiny:hover { color: var(--ink2); }
.footer-dot { font-size: 11px; color: var(--border); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .panel { display: none; }
  .rail { width: 44px; }
  :root { --rail-w: 44px; }
  body { overflow-y: auto; height: auto; }
  .center { overflow: visible; padding: 20px 16px 48px; }
}
