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

:root {
  color-scheme: dark;
  --bg-primary: #050b18;
  --bg-panel: rgba(10, 18, 40, 0.82);
  --bg-panel-blur: rgba(10, 18, 40, 0.65);
  --border-soft: rgba(255, 255, 255, 0.08);
  --text-primary: #f7f9ff;
  --text-muted: rgba(247, 249, 255, 0.72);
  --accent: #59e8ff;
  --accent-strong: #2cb7ff;
  --danger: #ff6584;
  --control-bg: rgba(5, 11, 24, 0.7);
  --control-border: rgba(255, 255, 255, 0.18);
  --gradient: radial-gradient(circle at 12% 20%, rgba(89, 232, 255, 0.35), transparent 40%),
    radial-gradient(circle at 88% 0%, rgba(81, 77, 255, 0.35), transparent 45%),
    linear-gradient(135deg, #030814, #050b18);
  --font-heading: 'Space Grotesk', 'DM Sans', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

body[data-theme='light'] {
  --bg-primary: #f3f5fc;
  --bg-panel: rgba(255, 255, 255, 0.92);
  --bg-panel-blur: rgba(255, 255, 255, 0.85);
  --border-soft: rgba(15, 23, 42, 0.08);
  --text-primary: #0f172a;
  --text-muted: rgba(15, 23, 42, 0.6);
  --control-bg: rgba(255, 255, 255, 0.94);
  --control-border: rgba(15, 23, 42, 0.15);
  --gradient: linear-gradient(135deg, #f7f8ff, #edf0ff);
}

body {
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--gradient);
  color: var(--text-primary);
  padding: clamp(16px, 3vw, 32px);
  line-height: 1.6;
}

.app-shell {
  width: min(1040px, 100%);
  margin: 0 auto 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.hero {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  padding: clamp(18px, 3vw, 32px);
  background: var(--bg-panel);
  box-shadow: 0 16px 60px rgba(5, 11, 24, 0.42);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  gap: 16px;
  flex: 1 1 280px;
  align-items: center;
}

.brand img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.68rem;
  color: var(--text-muted);
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(1.6rem, 2.5vw, 2.4rem);
  margin-bottom: 6px;
}

.lede {
  color: var(--text-muted);
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ghost-btn,
.icon-btn,
.accent-btn,
.primary-btn {
  border-radius: 999px;
  padding: 9px 14px;
  border: 1px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.ghost-btn {
  border-color: var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
}

.primary-btn,
.accent-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #041024;
  font-weight: 600;
  box-shadow: 0 12px 26px rgba(89, 232, 255, 0.3);
}

.workspace {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.panel {
  background: var(--bg-panel-blur);
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  padding: clamp(18px, 2vw, 26px);
  box-shadow: 0 12px 45px rgba(5, 11, 24, 0.35);
  backdrop-filter: blur(14px);
}

.phrasebook-panel {
  min-height: 200px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.preview-actions {
  display: inline-flex;
  gap: 8px;
}

.selector-group {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

select {
  background: var(--control-bg);
  color: var(--text-primary);
  border-radius: 14px;
  border: 1px solid var(--control-border);
  padding: 6px 10px;
  min-width: 110px;
}

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

textarea {
  width: 100%;
  min-height: 160px;
  border-radius: 16px;
  border: 1px solid var(--border-soft);
  background: rgba(5, 11, 24, 0.5);
  color: var(--text-primary);
  padding: 16px;
  font-size: 0.98rem;
  line-height: 1.5;
  resize: vertical;
}

.action-tray {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
}

.icon-btn.recording {
  background: rgba(255, 101, 132, 0.12);
  border-color: var(--danger);
  color: var(--danger);
}

.spacer {
  flex: 1;
}

.output-card {
  min-height: 160px;
  border-radius: 16px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  padding: 16px;
  background: rgba(5, 11, 24, 0.35);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#translatedText {
  font-size: 1.1rem;
  font-family: var(--font-heading);
  line-height: 1.6;
}

#statusLine {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.meta-line {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.phrase-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.phrase-item {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.phrase-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.phrase-source {
  font-weight: 600;
}

.phrase-translation {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.phrase-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.phrase-actions {
  display: flex;
  gap: 8px;
}

.phrase-actions .ghost-btn,
.phrase-actions .accent-btn {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.settings-panel {
  min-height: 200px;
}

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}

.setting-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.setting-label {
  font-weight: 600;
}

.setting-help {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.setting-control select {
  min-width: 200px;
}

.setting-control.range-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-control.range-control input[type='range'] {
  width: 160px;
}

.setting-value {
  font-weight: 600;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  transition: background 0.2s ease;
}

.switch .slider::before {
  position: absolute;
  content: '';
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.settings-panel input[type='range'] {
  accent-color: var(--accent);
}

.install-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.04);
}

.install-banner.hidden {
  display: none;
}

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 999;
}

.toast {
  min-width: 220px;
  padding: 10px 14px;
  border-radius: 11px;
  color: #041024;
  font-weight: 600;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.3s ease forwards;
}

.toast.error {
  background: var(--danger);
}

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

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .hero,
  .panel {
    padding: 16px;
  }

  .hero-actions button {
    flex: 1 1 140px;
    justify-content: center;
  }

  .toast-stack {
    top: auto;
    bottom: 14px;
    right: 14px;
  }
}
