@font-face {
  font-family: "Hedvig Letters Serif";
  src: url("fonts/hedvig-letters-serif-latin.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Hedvig Letters Serif";
  src: url("fonts/hedvig-letters-serif-latin-ext.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #ffffff;
  --fg: #000000;
  --gray: #8e8e93;
  --hairline: rgba(0, 0, 0, 0.12);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

main { min-height: 100%; }

/* ---------- Screens ---------- */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 16px) 20px calc(var(--safe-bottom) + 20px);
  max-width: 560px;
  margin: 0 auto;
}
.screen.active { display: flex; }

.screen-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.screen-header h2 {
  flex: 1;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
}
.btn-back {
  width: 36px; height: 36px;
  border: none;
  background: transparent;
  font-size: 30px;
  line-height: 1;
  color: var(--fg);
  cursor: pointer;
  padding-bottom: 6px;
}
.header-spacer { width: 36px; }

/* ---------- Home ---------- */
.home-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 14px;
}
.brand-mark {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 84px;
  margin-bottom: 10px;
}
.brand-mark span {
  height: 12px;
  background: var(--fg);
  transform: scaleY(1.35);
}
.brand-mark span:nth-child(1) { width: 100%; }
.brand-mark span:nth-child(2) { width: 62%; align-self: flex-start; }
.brand-mark span:nth-child(3) { width: 100%; }

h1 {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--gray);
  font-size: 16px;
  line-height: 1.45;
  max-width: 320px;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 18px;
}
.fine-print {
  text-align: center;
  color: var(--gray);
  font-size: 12px;
  padding-top: 4px;
}

/* ---------- Buttons ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.985); opacity: 0.85; }
.btn-primary { background: var(--fg); color: #fff; }
.btn-secondary {
  background: transparent;
  color: var(--fg);
  border: 1.5px solid var(--fg);
}
.btn-text {
  background: transparent;
  color: var(--gray);
  font-weight: 500;
}
.btn[disabled] { opacity: 0.35; pointer-events: none; }

/* ---------- Record ---------- */
.record-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  text-align: center;
}
.rec-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #ff3b30;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}
.rec-timer {
  font-size: 56px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.hint { color: var(--gray); font-size: 14px; line-height: 1.45; }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--hairline);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Edit ---------- */
.edit-hint { margin-bottom: 12px; }
#transcript {
  flex: 1;
  width: 100%;
  min-height: 200px;
  resize: none;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 18px;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.75;
  color: var(--fg);
  background: var(--bg);
  outline: none;
}
#transcript:focus { border-color: var(--fg); }

/* ---------- Trim ---------- */
.trim-box {
  position: relative;
  height: 120px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline);
  overflow: hidden;
  touch-action: none;
  background: #fafafa;
}
#waveform {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.trim-shade {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.82);
  pointer-events: none;
}
#trim-shade-l { left: 0; }
#trim-shade-r { right: 0; }
.trim-handle {
  position: absolute;
  top: 0; bottom: 0;
  width: 34px;
  margin-left: -17px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ew-resize;
}
.trim-handle span {
  width: 5px;
  height: 70%;
  border-radius: 3px;
  background: var(--fg);
}
.trim-playhead {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: #ff3b30;
  pointer-events: none;
}
.trim-times {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 2px;
}
.trim-dur { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.trim-preview { display: flex; justify-content: center; padding: 6px 0; }
.lang-row { border-bottom: none; min-height: 44px; }
.lang-row label { color: var(--gray); font-size: 14px; }

/* ---------- Color picker ---------- */
.color-chip {
  width: 40px;
  height: 30px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
}
.color-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 2px 16px;
  border-bottom: 1px solid var(--hairline);
}
.color-panel[hidden] { display: none; }
.cp-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.cp-swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  cursor: pointer;
  padding: 0;
}
.cp-swatch:active { transform: scale(0.92); }
.cp-slider { display: flex; }
.cp-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  border-radius: 11px;
  border: 1px solid var(--hairline);
  outline: none;
}
.cp-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--fg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  cursor: pointer;
}
.cp-hex {
  font-size: 12px;
  color: var(--gray);
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

/* ---------- Studio ---------- */
.preview-wrap {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  line-height: 0;
}
#preview { width: 100%; height: auto; display: block; }

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 2px 6px;
}
.play-btn {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--fg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.play-btn:active { opacity: 0.85; }
.play-btn svg[hidden] { display: none; } /* hidden no aplica a SVG per si sol */
.time {
  font-size: 12px;
  color: var(--gray);
  font-variant-numeric: tabular-nums;
  min-width: 34px;
  text-align: center;
}
#scrub { flex: 1; }

/* ---------- Controls ---------- */
.controls {
  border-top: 1px solid var(--hairline);
  margin-top: 8px;
}
.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  border-bottom: 1px solid var(--hairline);
}
.ctrl-row label {
  font-size: 15px;
  flex: none;
  white-space: nowrap;
}
.ctrl-row input[type="range"] {
  flex: 1;
  max-width: 55%;
}
input[type="range"] {
  accent-color: var(--fg);
  height: 30px;
}
input[type="color"] {
  width: 40px;
  height: 30px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: none;
  padding: 0;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }

.segmented {
  display: flex;
  border: 1.5px solid var(--fg);
  border-radius: 10px;
  overflow: hidden;
}
.segmented button {
  border: none;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 16px;
  cursor: pointer;
}
.segmented button.on { background: var(--fg); color: #fff; }

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1.5px solid var(--fg);
  border-radius: 10px;
  overflow: hidden;
}
.stepper button {
  border: none;
  background: transparent;
  color: var(--fg);
  font-size: 20px;
  width: 40px;
  height: 34px;
  cursor: pointer;
}
.stepper button:active { background: rgba(0,0,0,0.06); }
.stepper span {
  min-width: 26px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
}

.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: rgba(120, 120, 128, 0.32);
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 27px; height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

.font-serif { font-family: "Hedvig Letters Serif", Georgia, serif; }

/* ---------- Overlay / Export ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.overlay-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.overlay-card h3 { font-size: 22px; font-weight: 700; }
#export-progress-view, #export-done-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.progress {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--hairline);
  overflow: hidden;
}
#export-bar {
  height: 100%;
  width: 0%;
  background: var(--fg);
  border-radius: 3px;
  transition: width 0.2s linear;
}
#result-video {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  max-height: 45dvh;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  background: var(--fg);
  color: #fff;
  font-size: 14px;
  padding: 12px 18px;
  border-radius: 12px;
  max-width: 85vw;
  text-align: center;
  z-index: 100;
}
#toast[hidden] { display: none; }
