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

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --fg: #1b1b19;
  --muted: #76766f;
  --border: #e7e7e2;
  --track: #cfcfc9;
  --tie: #bdbdb6;
  --input: #fbfbfa;
  --accent: #d6452b;
  --accentDark: #953018;
  --smoke: rgba(140,140,140,.42);
  --wheel: #3a3a38;
  --cabWin: #bfe3ef;
  --head: #ffb43e;
  --play: paused;
}

input:focus { outline: none; }
button { font-family: inherit; cursor: pointer; }
::placeholder { color: var(--muted); }

@keyframes smoke {
  0%   { transform: translateY(0) scale(1); opacity: 0; }
  15%  { opacity: .5; }
  100% { transform: translateY(-26px) scale(1.2); opacity: 0; }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes chug {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-1.5px); }
}

/* Layout */
.page {
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Space Grotesk', sans-serif;
  transition: background .25s ease, color .25s ease;
  padding: 40px 24px 72px;
}

.container {
  max-width: 580px;
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 48px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 11px;
}

.logo-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}


.logo-text {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.4px;
}

.accent-text { color: var(--accent); }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.toggle-track {
  display: inline-flex;
  align-items: center;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: var(--track);
  padding: 3px;
  transition: background .25s ease;
}

.toggle-knob {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform .25s ease;
}

/* Title */
.title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.9px;
  line-height: 1.15;
  margin: 0 0 10px;
}

.subtitle {
  font-size: 15px;
  color: var(--muted);
  margin: 0 0 30px;
  line-height: 1.5;
}

/* Track area */
.track-area {
  position: relative;
  height: 104px;
  margin: 8px 0 34px;
  overflow: hidden;
}

.track-rail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  height: 5px;
  background: var(--track);
  border-radius: 3px;
}

.track-fill {
  position: absolute;
  left: 0;
  bottom: 18px;
  height: 5px;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  opacity: 0;
  transition: width .1s linear, opacity .25s ease;
}

.track-ties {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  height: 9px;
  background: repeating-linear-gradient(90deg, var(--tie) 0 4px, transparent 4px 19px);
}

/* Locomotive */
.loco {
  position: absolute;
  bottom: 15px;
  left: 0;
}

.loco-inner {
  position: relative;
  width: 104px;
  height: 60px;
  animation: chug .5s ease-in-out infinite;
  animation-play-state: var(--play);
}

.smoke-stack {
  position: absolute;
  left: 62px;
  top: -16px;
  width: 14px;
  height: 14px;
}

.smoke {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--smoke);
  animation: smoke 1.4s ease-out infinite;
}

.smoke-d2 { animation-delay: .42s; }
.smoke-d3 { animation-delay: .85s; }

.loco-chimney {
  position: absolute;
  left: 62px;
  top: 0;
  width: 11px;
  height: 18px;
  background: var(--accentDark);
  border-radius: 2px 2px 0 0;
}

.loco-dome {
  position: absolute;
  left: 44px;
  top: 6px;
  width: 11px;
  height: 11px;
  border-radius: 50% 50% 0 0;
  background: var(--accentDark);
}

.loco-cab {
  position: absolute;
  left: 6px;
  bottom: 14px;
  width: 30px;
  height: 32px;
  background: var(--accent);
  border-radius: 5px 7px 0 0;
}

.loco-window {
  position: absolute;
  left: 6px;
  top: 7px;
  width: 18px;
  height: 15px;
  background: var(--cabWin);
  border-radius: 2px;
}

.loco-boiler {
  position: absolute;
  left: 30px;
  bottom: 14px;
  width: 60px;
  height: 24px;
  background: var(--accent);
  border-radius: 6px 13px 0 0;
}

.loco-headlight {
  position: absolute;
  left: 84px;
  bottom: 25px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--head);
  box-shadow: 0 0 6px var(--head);
}

.loco-frame {
  position: absolute;
  left: 4px;
  bottom: 9px;
  width: 88px;
  height: 8px;
  background: var(--accentDark);
  border-radius: 3px;
}

.loco-cowcatcher {
  position: absolute;
  left: 90px;
  bottom: 5px;
  width: 0;
  height: 0;
  border-top: 13px solid transparent;
  border-left: 11px solid var(--accentDark);
}

.loco-wheel {
  position: absolute;
  bottom: 0;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--wheel);
  border: 3px solid var(--accentDark);
  animation: spin .7s linear infinite;
  animation-play-state: var(--play);
}

.loco-wheel-1 { left: 13px; }
.loco-wheel-2 { left: 40px; }
.loco-wheel-3 { left: 67px; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 9px;
}

.url-input {
  width: 100%;
  padding: 13px 15px;
  font-size: 14px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--fg);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 24px;
  transition: border-color .15s ease;
}

.url-input:focus {
  border-color: var(--accent);
}

/* Format chips */
.format-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}

.chip {
  padding: 11px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--fg);
  text-align: center;
  transition: all .15s ease;
  line-height: 1.1;
}

.chip-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chip-label {
  display: block;
  font-weight: 600;
  font-size: 14px;
}

.chip-kind {
  display: block;
  font-size: 10px;
  margin-top: 2px;
  opacity: .7;
}

/* Quality pills */
.quality-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 26px;
}

.pill {
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  font-family: 'IBM Plex Mono', monospace;
  transition: all .15s ease;
}

.pill-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Convert button */
.convert-btn {
  width: 100%;
  padding: 15px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 11px;
  border: none;
  background: var(--track);
  color: var(--muted);
  cursor: not-allowed;
  transition: all .2s ease;
}

.convert-btn-active {
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

/* Loading state */
.loading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
}

.progress-pct {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
}

.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width .1s linear;
}

/* Error */
.error-msg {
  padding: 12px 15px;
  background: rgba(214, 69, 43, .08);
  border: 1px solid rgba(214, 69, 43, .25);
  border-radius: 10px;
  color: var(--accent);
  font-size: 14px;
  margin-bottom: 14px;
  line-height: 1.4;
}

/* Done state */
.file-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 11px;
  margin-bottom: 14px;
}

.file-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.file-info { min-width: 0; }

.file-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.done-actions {
  display: flex;
  gap: 10px;
}

.download-btn {
  flex: 1;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 11px;
  cursor: pointer;
  transition: opacity .15s ease;
}

.download-btn:hover { opacity: .9; }

.reset-btn {
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: background .15s ease;
}

.reset-btn:hover { background: var(--border); }

/* API Settings */
.api-settings {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.api-settings-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.api-settings-toggle::-webkit-details-marker { display: none; }

.api-settings-toggle:hover { color: var(--fg); }

.api-settings-body {
  padding-top: 16px;
}

.api-input {
  margin-bottom: 16px !important;
}

.api-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin: 4px 0 0;
}

.api-hint a {
  color: var(--accent);
  text-decoration: none;
}

.api-hint a:hover { text-decoration: underline; }

/* Disclaimer */
.disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 22px 0 0;
}
