/*
  Whisper — style.css
  MIT License © 2025 thedigitalauteur
*/

:root {
  --ink: #1a1714;
  --paper: #f5f0e8;
  --paper2: #ede7d9;
  --paper3: #e3dccf;
  --gold: #b8860b;
  --gold-light: #d4a017;
  --rust: #7a2e10;
  --sage: #3a5e3a;
  --mist: #6b7b8d;
  --dim: #9a9080;
  --border: rgba(26, 23, 20, 0.14);
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "DM Mono", monospace;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.022'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 52px 28px 90px;
  position: relative;
  z-index: 1;
}

/* ── Header ── */
header {
  text-align: center;
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
header::after {
  content: "◆";
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper);
  padding: 0 14px;
  color: var(--gold);
  font-size: 10px;
}
.wordmark {
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(56px, 14vw, 92px);
  font-weight: 300;
  font-style: italic;
  letter-spacing: 0.14em;
  color: var(--ink);
  line-height: 1;
}
.sub {
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--dim);
  margin-top: 10px;
}

/* ── Mode strip ── */
.mode-strip {
  display: flex;
  border: 1px solid var(--border);
  margin-bottom: 32px;
}
.mode-btn {
  flex: 1;
  padding: 15px 10px;
  background: var(--paper2);
  border: none;
  cursor: pointer;
  font-family: "DM Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}
.mode-btn + .mode-btn {
  border-left: 1px solid var(--border);
}
.mode-btn.active {
  background: var(--ink);
  color: var(--paper);
}

/* ── Explainer ── */
.explainer {
  background: var(--paper2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  padding: 16px 20px;
  margin-bottom: 30px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.exp-icon {
  font-size: 18px;
  flex-shrink: 0;
  padding-top: 1px;
}
.exp-body {
  font-size: 11px;
  line-height: 1.85;
  color: var(--mist);
}
.exp-body strong {
  color: var(--ink);
  font-weight: 500;
}

/* ── Step ── */
.step-label {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 11px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.step-num {
  width: 17px;
  height: 17px;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.section {
  margin-bottom: 28px;
}

/* ── Sound grid ── */
.sound-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
@media (max-width: 460px) {
  .sound-grid {
    grid-template-columns: 1fr;
  }
}

.sound-card {
  border: 1px solid var(--border);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--paper2);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
  user-select: none;
}
.sound-card:hover {
  background: var(--paper3);
  border-color: rgba(26, 23, 20, 0.25);
}
.sound-card.selected {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.sound-card.selected .sound-desc {
  color: rgba(245, 240, 232, 0.45);
}
.sound-card.playing::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--gold-light);
  animation: shimmer 2.5s linear infinite;
}
@keyframes shimmer {
  from {
    width: 0%;
  }
  to {
    width: 100%;
  }
}

.s-emoji {
  font-size: 20px;
  flex-shrink: 0;
}
.s-info {
  flex: 1;
  min-width: 0;
}
.sound-name {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
}
.sound-desc {
  font-size: 10px;
  color: var(--dim);
  font-weight: 300;
  margin-top: 1px;
}

.preview-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid currentColor;
  background: transparent;
  cursor: pointer;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.15s;
  color: inherit;
  flex-shrink: 0;
}
.preview-btn:hover {
  opacity: 1;
}

.sound-card.upload-card {
  border-style: dashed;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px 12px;
  gap: 6px;
}
.sound-card.upload-card input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* ── Textarea ── */
textarea {
  width: 100%;
  background: var(--paper2);
  border: 1px solid var(--border);
  color: var(--ink);
  font-family: "Cormorant Garamond", serif;
  font-size: 18px;
  padding: 16px 18px;
  resize: none;
  height: 108px;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.65;
}
textarea:focus {
  border-color: var(--ink);
}
textarea::placeholder {
  color: var(--dim);
  font-style: italic;
}
.char-hint {
  text-align: right;
  font-size: 10px;
  color: var(--dim);
  margin-top: 5px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 13px 28px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  width: 100%;
}
.btn-dark {
  background: var(--ink);
  color: var(--paper);
}
.btn-dark:hover {
  background: #2d2a26;
}
.btn-dark:disabled,
.btn-gold:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.btn-gold {
  background: var(--gold);
  color: #fff;
}
.btn-gold:hover {
  background: var(--gold-light);
}

/* ── Progress ── */
.prog-wrap {
  margin-bottom: 14px;
  display: none;
}
.prog-bar {
  height: 2px;
  background: var(--border);
}
.prog-fill {
  height: 100%;
  background: var(--gold);
  width: 0%;
  transition: width 0.2s;
}
.prog-label {
  font-size: 10px;
  color: var(--dim);
  margin-top: 5px;
  letter-spacing: 0.08em;
}

/* ── Upload zone ── */
.upload-zone {
  border: 1px dashed var(--border);
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--paper2);
  position: relative;
}
.upload-zone:hover,
.upload-zone.over {
  border-color: var(--ink);
  background: var(--paper3);
}
.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.up-icon {
  font-size: 26px;
  margin-bottom: 8px;
}
.up-main {
  font-family: "Cormorant Garamond", serif;
  font-size: 16px;
  font-style: italic;
  color: var(--dim);
}
.up-sub {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.1em;
  margin-top: 3px;
}
.up-file {
  font-size: 11px;
  color: var(--ink);
  font-weight: 500;
  margin-top: 8px;
}

/* ── Player ── */
.player {
  background: var(--paper2);
  border: 1px solid var(--border);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.play-btn {
  width: 34px;
  height: 34px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.play-btn:hover {
  background: #2d2a26;
}
.player-meta {
  flex: 1;
  min-width: 0;
}
.player-name {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-time {
  font-size: 10px;
  color: var(--dim);
  margin-top: 2px;
}
.seek-bar {
  width: 100%;
  height: 2px;
  background: var(--border);
  margin-top: 8px;
  cursor: pointer;
}
.seek-fill {
  height: 100%;
  background: var(--gold);
  width: 0%;
}

/* ── Waveform ── */
.wv-wrap {
  position: relative;
  margin-top: 8px;
  overflow: hidden;
}
canvas.wv {
  width: 100%;
  height: 46px;
  display: block;
  background: var(--paper2);
  border: 1px solid var(--border);
}
.wv-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(184, 134, 11, 0.7);
  pointer-events: none;
  display: none;
  left: 0;
}
.wv-playhead.active {
  display: block;
}
.wv-scan-overlay {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: rgba(184, 134, 11, 0.06);
  pointer-events: none;
  width: 0%;
}

/* ── Result box ── */
.result-box {
  background: var(--ink);
  color: var(--paper);
  padding: 22px 26px;
  margin-top: 18px;
  position: relative;
  display: none;
}
.result-badge {
  position: absolute;
  top: -1px;
  left: 18px;
  background: var(--gold);
  color: #fff;
  font-size: 8px;
  letter-spacing: 0.3em;
  padding: 3px 10px;
  text-transform: uppercase;
}
.result-text {
  font-family: "Cormorant Garamond", serif;
  font-size: 20px;
  font-style: italic;
  line-height: 1.65;
  margin-top: 10px;
  word-break: break-word;
}
.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--gold);
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: blink 0.7s step-end infinite;
}
@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

/* ── TTS indicator ── */
.tts-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}
.tts-indicator.active {
  display: flex;
}
.tts-bars {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 14px;
}
.tts-bar {
  width: 3px;
  background: var(--gold);
  border-radius: 1px;
  animation: ttsbar 0.6s ease-in-out infinite alternate;
}
.tts-bar:nth-child(2) {
  animation-delay: 0.1s;
}
.tts-bar:nth-child(3) {
  animation-delay: 0.2s;
}
.tts-bar:nth-child(4) {
  animation-delay: 0.15s;
}
.tts-bar:nth-child(5) {
  animation-delay: 0.05s;
}
@keyframes ttsbar {
  from {
    height: 3px;
  }
  to {
    height: 14px;
  }
}

/* ── TTS provider strip ── */
.tts-strip {
  display: flex;
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 10px;
}
.tts-strip button {
  flex: 1;
  padding: 9px 6px;
  font-family: "DM Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  background: var(--paper2);
  color: var(--dim);
  transition: all 0.15s;
}
.tts-strip button + button {
  border-left: 1px solid var(--border);
}
.tts-strip button.active {
  background: var(--ink);
  color: var(--paper);
}

.api-input {
  width: 100%;
  background: var(--paper2);
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  color: var(--ink);
  outline: none;
  margin-bottom: 6px;
}
.voice-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.voice-row input {
  flex: 1;
  min-width: 0;
}
.voice-row select {
  background: var(--paper2);
  border: 1px solid var(--border);
  padding: 10px 8px;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  color: var(--ink);
  outline: none;
  cursor: pointer;
}

/* ── Share result ── */
.share-result {
  display: none;
  margin-top: 4px;
}
.share-input-row {
  display: flex;
  gap: 8px;
}
.share-input-row input {
  flex: 1;
  background: var(--paper2);
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.share-input-row button {
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 10px 16px;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.15em;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Misc ── */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}
.panel {
  display: none;
}
.panel.active {
  display: block;
  animation: up 0.28s ease;
}
@keyframes up {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--ink);
  color: var(--paper);
  padding: 11px 22px;
  font-size: 11px;
  letter-spacing: 0.12em;
  transition: transform 0.28s ease;
  white-space: nowrap;
  z-index: 999;
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
}
.toast.err {
  background: var(--rust);
}
.toast.ok {
  background: var(--sage);
}
