:root {
  --bg: #1a1a2e;
  --bg-card: #232342;
  --bg-input: #2a2a4a;
  --border: #3a3a5c;
  --text: #e4e4f0;
  --text-dim: #9999b8;
  --accent: #6c7cf0;
  --accent-hover: #8a98f5;
  --success: #4ade80;
  --warning: #fbbf24;
  --error: #f87171;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
}

:root[data-theme="light"] {
  --bg: #f5f5fa;
  --bg-card: #ffffff;
  --bg-input: #eaeaef;
  --border: #d4d4de;
  --text: #1a1a2e;
  --text-dim: #6b6b8a;
  --accent: #5b67d4;
  --accent-hover: #4c56bf;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
}

.hidden { display: none !important; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.logo-sub {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 500;
}

.burger-btn {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
}

.burger-btn span {
  width: 24px;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.3s, opacity 0.3s;
}

.burger-btn.open span:nth-child(1) { transform: rotate(45deg) translate(6px, 6px); }
.burger-btn.open span:nth-child(2) { opacity: 0; }
.burger-btn.open span:nth-child(3) { transform: rotate(-45deg) translate(6px, -6px); }

.settings-panel {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.settings-panel h3 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
  color: var(--text-dim);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.setting span { font-weight: 600; }

.val-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
}

.setting input,
.setting select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
}

.setting input:focus,
.setting select:focus {
  outline: none;
  border-color: var(--accent);
}

.setting input[type="range"] {
  padding: 0;
}

.main {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}

.card-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: 0.5rem 1.5rem;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.record-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.record-notice {
  background: var(--bg-input);
  border: 1px solid var(--warning);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text);
}

.record-notice a { color: var(--accent); font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, transform 0.1s;
  text-decoration: none;
  color: #fff;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-record { background: var(--accent); }
.btn-record.recording { background: var(--error); }

.record-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: border-radius 0.2s;
}

.btn-record.recording .record-icon {
  border-radius: 3px;
  height: 14px;
  width: 10px;
}

.record-timer {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2.5rem 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--bg-input);
}

.upload-text { font-weight: 600; }
.upload-hint { font-size: 0.85rem; color: var(--text-dim); }

.ref-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.ref-check { color: var(--success); font-weight: 700; }
.ref-duration { color: var(--text-dim); }

.btn-text {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
}

.text-controls {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.text-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.text-controls select {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
}

#textExample { flex: 1; }

#textInput {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

#textInput:focus { outline: none; border-color: var(--accent); }

.generate-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.btn-generate {
  width: 100%;
  max-width: 320px;
  background: var(--accent);
  font-size: 1.15rem;
  padding: 0.85rem 2rem;
}

.btn-generate:not(:disabled):hover { background: var(--accent-hover); }

.progress-bar {
  width: 100%;
  position: relative;
  height: 36px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent, #6c7cf0), var(--accent-hover, #8a98f5));
  transition: width 0.4s ease;
}

.progress-fill.indeterminate {
  width: 30%;
  animation: indeterminate 1.4s ease-in-out infinite;
}

@keyframes indeterminate {
  0% { margin-left: -30%; }
  100% { margin-left: 100%; }
}

.progress-msg {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  z-index: 1;
}

.waveform {
  width: 100%;
  margin-bottom: 1rem;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.btn-play { background: var(--accent); }

.player-time {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.download-controls {
  display: flex;
  gap: 0.75rem;
}

.btn-download {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  flex: 1;
}

.btn-download:hover { border-color: var(--accent); }

.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.footer a:hover { text-decoration: underline; }

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow);
  animation: toast-in 0.3s ease;
  pointer-events: auto;
  max-width: 360px;
}

.toast.success { background: var(--success); color: #0a1a0a; }
.toast.warning { background: var(--warning); color: #1a1a0a; }
.toast.error   { background: var(--error);   color: #fff; }

.toast.removing { animation: toast-out 0.3s ease forwards; }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

@media (max-width: 600px) {
  .header { padding: 0.75rem 1rem; }
  .main { padding: 1rem 0.75rem; }
  .card { padding: 1.1rem; }
  .settings-grid { grid-template-columns: 1fr; }
  .text-controls { flex-direction: column; }
  .download-controls { flex-direction: column; }
  .toast-container { top: 0.5rem; right: 0.5rem; left: 0.5rem; }
  .toast { max-width: none; }
}
