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

:root {
  --bg: #1a1a1a;
  --surface: #2a2a2a;
  --text: #f5f5f0;
  --muted: #999;
  --accent: #CD3301;
  --accent-light: #e84d1a;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.5;
}

header {
  text-align: center;
  margin-bottom: 24px;
}

.build-footer {
  text-align: center;
  margin-top: 24px;
  padding-bottom: 4px;
}

.build-footer #build-info {
  font-size: 0.7rem;
  font-family: -apple-system, monospace;
  letter-spacing: 0.02em;
  color: #fff;
  opacity: 0.85;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.step-indicator {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.step-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--surface);
  transition: background 0.2s, transform 0.2s;
}

.step-indicator .dot.current {
  background: var(--accent);
  transform: scale(1.3);
}

.step-indicator .dot.done {
  background: var(--accent-light);
}

.step {
  display: none;
}

.step.active {
  display: block;
}

.step h2 {
  font-size: 1.15rem;
  margin-bottom: 6px;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.hint.small {
  font-size: 0.75rem;
  margin-top: 8px;
  margin-bottom: 0;
  opacity: 0.8;
}

.status {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 8px;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  width: 100%;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
}

.btn-large {
  padding: 18px 24px;
  font-size: 1.05rem;
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.85rem;
  width: auto;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-row .btn {
  flex: 1;
}

/* Audio controls */
.audio-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

#record-btn.recording {
  background: #c0392b;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.divider {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  position: relative;
  margin: 4px 0;
}

.divider::before,
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--surface);
}

.divider::before { left: 0; }
.divider::after { right: 0; }

.file-label {
  cursor: pointer;
}

#audio-player {
  width: 100%;
  margin-top: 12px;
  border-radius: var(--radius);
}

/* Textarea */
textarea {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--surface);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 160px;
  -webkit-appearance: none;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* Preview */
.preview-container {
  position: relative;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin-bottom: 16px;
}

.preview-container canvas {
  width: 100%;
  height: auto;
  display: block;
}

.preview-container.small canvas {
  max-height: 200px;
  object-fit: contain;
}

.preview-play {
  position: absolute;
  bottom: 10px;
  right: 10px;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  padding: 0;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 1.1rem;
}

/* Style controls */
.style-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.control span {
  flex-shrink: 0;
  min-width: 120px;
}

.control input[type="color"] {
  width: 48px;
  height: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: none;
  -webkit-appearance: none;
}

.control input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  min-height: 36px;
}

.control select {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--surface);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.control output {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 36px;
  text-align: right;
}

/* Progress */
.progress-wrap {
  margin-top: 16px;
}

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

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

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + var(--safe-top));
  padding-bottom: calc(16px + var(--safe-bottom));
}

.loading-overlay.hidden {
  display: none !important;
}

.loading-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px;
  text-align: center;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 16px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-overlay.error .loading-spinner {
  display: none;
}

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

.loading-title {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.loading-overlay.error .loading-title {
  color: #ff6b6b;
}

.loading-message {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
  min-height: 1.4em;
}

.loading-steps {
  list-style: none;
  text-align: left;
  margin-bottom: 16px;
}

.loading-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.loading-step.active {
  color: var(--text);
  font-weight: 600;
}

.loading-step.active .step-icon {
  color: var(--accent);
}

.loading-step.done {
  color: var(--accent-light);
}

.loading-step.done .step-icon {
  color: #6bcb77;
}

.loading-step.error {
  color: #ff6b6b;
}

.loading-step.error .step-icon {
  color: #ff6b6b;
}

.step-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.loading-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.loading-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s;
  border-radius: 3px;
}

.loading-pct {
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 32px;
}

.loading-log {
  max-height: 100px;
  overflow-y: auto;
  text-align: left;
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, monospace;
}

.loading-cancel {
  margin-top: 4px;
}

/* iOS standalone */
@media (display-mode: standalone) {
  body {
    padding-top: calc(24px + var(--safe-top));
  }
}
