:root {
  --bg: #F4F2ED;
  --surface: #FFFFFF;
  --surface-muted: #EAE7DF;
  --ink: #18181B;
  --ink-muted: #52525B;
  --border: #D8D4CA;
  --accent: #B83612;
  --accent-hover: #9A2B0D;
  --accent-contrast: #FFFFFF;
  --success-bg: #DCFCE7;
  --success-ink: #166534;
  --error-bg: #FEE2E2;
  --error-ink: #991B1B;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

html {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* Interactive cursor & focus rules (R-32, R-39) */
a[href],
button:not(:disabled),
summary,
select:not(:disabled),
label[for],
input[type="range"]:not(:disabled),
[role="button"] {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container {
  width: 100%;
  max-width: 820px;
  margin-inline: auto;
  padding-inline: 16px;
}

/* Hide install button immediately when installed/standalone */
.is-installed #install-btn {
  display: none !important;
}

/* Topbar */
.topbar {
  border-bottom: 1px solid var(--border);
  background-color: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Desktop Web Navigation */
.desktop-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-tab {
  min-height: 38px;
  padding: 6px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-tab:hover {
  color: var(--ink);
  background-color: var(--surface-muted);
}

.nav-tab.is-active {
  color: var(--accent);
  background-color: #FAEAE5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-btn {
  border: 0;
  background: transparent;
  padding: 4px 6px;
  margin-left: -6px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: inherit;
}

.brand-btn:hover {
  background-color: var(--surface-muted);
}

.brand-mark {
  display: block;
  border-radius: 6px;
  flex-shrink: 0;
  pointer-events: none;
}

.brand-name {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  background-color: var(--surface-muted);
  color: var(--ink);
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success-ink);
}

.status-pill.is-offline .status-dot {
  background-color: var(--accent);
}

/* Main Workspace */
.workspace {
  flex: 1;
  padding-block: 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.intro h1 {
  margin: 0 0 6px;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.intro-sub {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.975rem;
  max-width: 60ch;
}

/* Cards */
.card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.mono-meta {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  color: var(--ink-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.84rem;
}

.btn-lg {
  min-height: 48px;
  padding: 12px 24px;
  font-size: 1rem;
}

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

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

.btn-secondary:hover:not(:disabled) {
  background-color: var(--surface-muted);
}

.btn-text {
  background-color: transparent;
  color: var(--ink-muted);
  padding-inline: 8px;
}

.btn-text:hover:not(:disabled) {
  color: var(--ink);
  background-color: var(--surface-muted);
}

/* Dropzone */
.dropzone-card {
  padding: 12px;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 40px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background-color: var(--bg);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background-color: #EFECE4;
}

.dropzone-icon {
  color: var(--accent);
}

.dropzone-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.dropzone-hint {
  margin: 0 0 6px;
  font-size: 0.875rem;
  color: var(--ink-muted);
  max-width: 44ch;
}

.url-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-block: 16px 12px;
  color: var(--ink-muted);
  font-size: 0.8125rem;
}

.url-divider::before,
.url-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: var(--border);
}

.url-loader {
  display: flex;
  gap: 10px;
}

.url-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9375rem;
}

.url-note {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* Error State */
.error-card {
  background-color: var(--error-bg);
  border-color: #FCA5A5;
  color: var(--error-ink);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.error-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 700;
}

.error-message {
  margin: 0;
  font-size: 0.9rem;
}

/* Loading State */
.loading-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.loading-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.loading-hint {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-muted);
}

.progress-track {
  width: 100%;
  height: 10px;
  background-color: var(--surface-muted);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: var(--accent);
  transition: width 0.15s ease;
}

.progress-fill.indeterminate {
  width: 40%;
  animation: indeterminate-slide 1.2s ease-in-out infinite;
}

@keyframes indeterminate-slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(300%);
  }
}

/* Workbench */
.workbench {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.file-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.file-meta-group {
  min-width: 0;
  flex: 1;
}

.file-name {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-list {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
}

.meta-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.meta-item dt {
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

.meta-item dd {
  margin: 0;
  font-weight: 500;
  color: var(--ink);
}

/* Waveform & Trim */
.waveform-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.waveform-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.waveform-well {
  background-color: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.waveform-canvas {
  display: block;
  width: 100%;
  height: 88px;
}

.trim-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.trim-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 600;
}

.range-input {
  width: 100%;
  min-height: 36px;
  accent-color: var(--accent);
}

/* Export Settings */
.export-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.select-input {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
}

.convert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.encode-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.encode-progress-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Output Result */
.output-result {
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.output-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.output-title {
  margin: 0 0 2px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--success-ink);
}

.audio-player {
  width: 100%;
  height: 44px;
}

/* iOS Install Dialog */
.ios-dialog {
  width: min(440px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: var(--surface);
  color: var(--ink);
  padding: 20px;
}

.ios-dialog::backdrop {
  background-color: rgba(24, 24, 27, 0.55);
}

.ios-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.ios-steps {
  margin: 0 0 18px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9375rem;
}

.ios-dialog-ok {
  width: 100%;
}

.history-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* History */
.history-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.history-item-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-item-info {
  min-width: 0;
  flex: 1;
}

.history-item-name {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guide-steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--ink-muted);
  font-size: 0.9375rem;
  line-height: 1.55;
}

.guide-steps strong {
  color: var(--ink);
}

.guide-steps code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background-color: var(--surface-muted);
  padding: 2px 5px;
  border-radius: 4px;
}

.contact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
}

/* App Views */
.app-view {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app-view[hidden] {
  display: none;
}

/* Info & Contact Sections */
.info-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-text {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9375rem;
  line-height: 1.6;
}

.info-text strong {
  color: var(--ink);
}

.feature-list {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

.feature-list strong {
  color: var(--ink);
}

.developer-credit {
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.contact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding-top: 4px;
}

.contact-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--ink);
  min-height: 68px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.contact-tile:hover {
  border-color: var(--accent);
  background-color: #EFECE4;
}

.contact-tile-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
}

.contact-tile-sub {
  font-size: 0.825rem;
  color: var(--ink-muted);
  word-break: break-word;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  font-size: 0.9375rem;
  color: var(--ink-muted);
}

.dialog-body p {
  margin: 0;
}

/* Footer */
.footer {
  padding-block: 16px 28px;
  color: var(--ink-muted);
  font-size: 0.8125rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border);
}

.footer-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.footer p {
  margin: 0;
}

.footer-brand strong {
  color: var(--ink);
  font-weight: 600;
}

.brand-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.brand-link:hover {
  color: var(--accent-hover);
}

/* Mobile App Bottom Navigation (iPhone & Android) */
.bottom-nav {
  display: none;
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .desktop-nav {
    display: none;
  }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 58px;
    padding: 6px 2px;
    border: 0;
    background: transparent;
    color: var(--ink-muted);
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-item:active {
    transform: scale(0.96);
  }

  .bottom-nav-item.is-active {
    color: var(--accent);
  }

  .workspace {
    padding-block: 20px 24px;
  }

  .footer {
    padding-bottom: calc(82px + env(safe-area-inset-bottom, 0px));
  }

  .contact-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .status-pill {
    display: none;
  }

  .url-loader {
    flex-direction: column;
  }

  .url-loader .btn {
    width: 100%;
  }

  .trim-controls,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .contact-actions .btn,
  .convert-actions .btn {
    width: 100%;
  }

  .output-actions,
  .output-info .btn {
    width: 100%;
  }
}

/* Reduced Motion (R-39) */
/* Contact Form & Channels */
.contact-layout {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
  align-items: start;
}

.contact-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.text-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background-color: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9375rem;
}

.text-area {
  min-height: 108px;
  resize: vertical;
}

.form-status {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  background-color: var(--success-bg);
  color: var(--success-ink);
}

.form-status.is-error {
  background-color: var(--error-bg);
  color: var(--error-ink);
}

.contact-channels {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.channel-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.channel-value {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
}

/* Secret Operations Console */
.ops-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.ops-header-actions {
  display: flex;
  gap: 8px;
}

.ops-dashboard {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}

.ops-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.ops-breakdown-list,
.ops-messages-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ops-breakdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background-color: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.ops-message-item {
  padding: 12px 14px;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ops-message-item.is-unread {
  border-color: var(--accent);
}

.ops-message-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.ops-message-body {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
  white-space: pre-wrap;
}

.ops-message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.ops-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
  text-align: left;
}

.ops-table th,
.ops-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.ops-table th {
  font-weight: 600;
  color: var(--ink-muted);
}

@media (max-width: 768px) {
  .contact-layout,
  .ops-two-col {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill.indeterminate {
    animation: none;
    width: 100%;
  }
  .btn,
  .dropzone,
  .progress-fill {
    transition: none;
  }
}
