:root {
  --bg-0: #06070a;
  --bg-1: #0a0c12;
  --bg-2: #11141d;
  --bg-3: #1a1f2c;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f4f6;
  --text-dim: #9aa0ad;
  --text-soft: #6b7080;
  --accent: #ff8a3d;
  --accent-warm: #ffb070;
  --accent-glow: rgba(255, 138, 61, 0.35);
  --danger: #ff4d4f;
  --success: #46d18d;
  --radius: 18px;
  --radius-sm: 10px;
  --font-display: "Instrument Serif", "Times New Roman", serif;
  --font-ui: "Outfit", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

/* ✅ CRITICAL FIX: [hidden] must always win over display:flex/grid/etc. */
[hidden] { display: none !important; }

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.grid-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse at top right, rgba(255, 138, 61, 0.08), transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(70, 90, 200, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 100%);
}
.grid-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
}

/* TOPBAR */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  gap: 10px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #d96a20);
  color: #1a0d05;
  box-shadow: 0 4px 14px var(--accent-glow);
  flex-shrink: 0;
}
.brand-mark svg { width: 24px; height: 24px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.5px;
}
.brand-sub {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-soft);
  margin-top: 2px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  white-space: nowrap;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-soft);
}
.status-pill.recording { color: var(--danger); border-color: rgba(255, 77, 79, 0.35); }
.status-pill.recording .status-dot { background: var(--danger); animation: blink 1s infinite; }
.status-pill.ready { color: var(--success); border-color: rgba(70, 209, 141, 0.3); }
.status-pill.ready .status-dot { background: var(--success); }
.status-pill.processing { color: var(--accent); border-color: rgba(255, 138, 61, 0.35); }
.status-pill.processing .status-dot { background: var(--accent); animation: blink 0.8s infinite; }

@keyframes blink { 50% { opacity: 0.3; } }

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px 40px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  gap: 24px;
}

.panel {
  width: 100%;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  animation: panelIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head { margin-bottom: 24px; }
.step-num {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: 8px;
}
.panel-head h1 {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 400;
  margin: 0 0 6px;
  letter-spacing: -0.5px;
  line-height: 1;
}
.panel-head p { margin: 0; color: var(--text-dim); font-size: 14.5px; }

.fields { display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-soft);
  font-weight: 500;
}
.field input,
.field textarea {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  transition: border-color 0.2s, background 0.2s;
  resize: none;
}
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #1f2433;
}

.camera-options { margin-bottom: 24px; }
.option-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-soft);
  margin-bottom: 10px;
  font-weight: 500;
}
.radio-group { display: flex; gap: 8px; }
.radio-pill {
  flex: 1;
  position: relative;
  cursor: pointer;
}
.radio-pill input { position: absolute; opacity: 0; pointer-events: none; }
.radio-pill span {
  display: block;
  padding: 12px;
  text-align: center;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: all 0.2s;
}
.radio-pill input:checked + span {
  background: var(--accent);
  color: #1a0d05;
  border-color: var(--accent);
  font-weight: 600;
}

/* Buttons */
.btn-primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: var(--accent);
  color: #1a0d05;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 10px 30px var(--accent-glow);
  transition: transform 0.15s, box-shadow 0.2s;
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary svg { width: 18px; height: 18px; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 12px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); background: #1f2433; }
.btn-secondary svg { width: 20px; height: 20px; color: var(--accent); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-tertiary {
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 16px;
}
.btn-tertiary:hover { color: var(--text); border-color: var(--line-strong); }

.btn-ghost {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost:hover { border-color: var(--accent); }
.btn-ghost:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-ghost svg { width: 18px; height: 18px; }

.btn-mini {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-mini:hover { color: var(--text); border-color: var(--line-strong); }

/* VIEWFINDER */
.viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 11;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  margin-bottom: 18px;
}
.viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, transparent 25%, transparent 75%, rgba(0,0,0,0.6) 100%);
}
.hud-top, .hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.rec-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.3px;
}
.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-soft);
}
.rec-indicator.live .rec-dot {
  background: var(--danger);
  animation: pulse 1.2s infinite;
}
.rec-indicator.paused .rec-dot { background: var(--accent); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--danger); }
  50% { box-shadow: 0 0 0 8px transparent; }
}

.timer {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 8px;
  letter-spacing: 1px;
}

.meta-chip {
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-meter {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  max-width: 110px;
  overflow: hidden;
}
.meter-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--accent), var(--danger));
  width: 0%;
  transition: width 0.1s;
}

.record-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: 12px 0;
}

.rec-button {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 4px solid var(--text);
  background: transparent;
  padding: 6px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.2s;
}
.rec-button:active { transform: scale(0.92); }
.rec-button-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--danger);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.rec-button.recording .rec-button-inner {
  border-radius: 8px;
  width: 38%;
  height: 38%;
}

.hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-soft);
  margin: 14px 0 0;
}

.result-video {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin-bottom: 20px;
  border: 1px solid var(--line);
}
.result-video video {
  width: 100%;
  display: block;
  max-height: 50vh;
}

.transcription-card {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.card-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 600;
}
.card-title svg { width: 16px; height: 16px; color: var(--accent); }
.card-status {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-soft);
  padding: 4px 9px;
  background: var(--bg-1);
  border-radius: 999px;
}
.card-status.done { color: var(--success); }
.card-status.error { color: var(--danger); }
.card-status.loading { color: var(--accent); }

.card-body { position: relative; padding: 18px; min-height: 120px; }
.transcription-text {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 80px;
}
.transcription-text:empty::before {
  content: attr(data-placeholder);
  color: var(--text-soft);
  font-style: italic;
}

.trans-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  background: var(--bg-3);
  color: var(--text-dim);
  font-size: 13px;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.trans-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  background: var(--bg-3);
  padding: 18px;
  text-align: center;
}
.trans-error svg { width: 32px; height: 32px; color: var(--danger); margin-bottom: 4px; }
.trans-error strong { font-size: 14px; color: var(--text); }
.trans-error small { font-size: 12.5px; color: var(--text-soft); max-width: 80%; }

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 22px;
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text);
  font-size: 13.5px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-color: rgba(70, 209, 141, 0.5); }
.toast.error { border-color: rgba(255, 77, 79, 0.5); }

/* MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 200;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  position: relative;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 28px 26px 24px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal h2 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  margin: 0 0 14px;
  letter-spacing: -0.5px;
}
.modal-intro { color: var(--text-dim); font-size: 14.5px; margin: 0 0 18px; }
.modal-note {
  color: var(--text-soft);
  font-size: 12.5px;
  margin: 14px 0 0;
  padding: 10px 12px;
  background: var(--bg-3);
  border-radius: 8px;
  border-left: 2px solid var(--accent);
  line-height: 1.5;
}

.ios-steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.ios-steps li { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; color: var(--text); line-height: 1.5; }
.step-circle {
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #1a0d05;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.inline-icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: #1a0d05;
  border-radius: 6px;
  vertical-align: middle;
  margin: 0 2px;
}
.inline-icon svg { width: 14px; height: 14px; }

/* FOOTER */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-soft);
}
.footer-brand { color: var(--accent); font-weight: 500; }
.footer-sep { opacity: 0.4; }
.version-badge {
  padding: 3px 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  letter-spacing: 0.8px;
  transition: border-color 0.2s;
}
.version-badge:hover { border-color: var(--accent); color: var(--accent); cursor: default; }

/* MOBILE */
@media (max-width: 540px) {
  .topbar { padding: 14px 16px; }
  .brand-name { font-size: 19px; }
  .stage { padding: 18px 14px 32px; gap: 18px; }
  .panel { padding: 22px 20px; }
  .panel-head h1 { font-size: 32px; }
  .row { grid-template-columns: 1fr; }
  .rec-button { width: 76px; height: 76px; }
  .record-controls { gap: 22px; }
  .timer { font-size: 18px; }
  .action-grid { grid-template-columns: 1fr 1fr; }
  .action-grid .btn-secondary:nth-child(3) { grid-column: 1 / -1; }
  .modal { padding: 24px 20px 20px; }
  .modal h2 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
