:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --primary: #005eb8;
  --primary-hover: #004b93;
  --primary-soft: #ebf4ff;
  --danger: #c62828;
  --danger-hover: #a61d1d;
  --danger-soft: #fde8e8;
  --success: #1e6b34;
  --success-soft: #e6f4ea;
  --warning: #9c4221;
  --warning-soft: #feebc8;
  --text: #1a202c;
  --muted: #4a5568;
  --border: #cbd5e0;
  --canvas-bg: #0f172a;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.1);
  --radius: 12px;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  padding: 16px;
}

.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 {
  max-width: 1200px;
  margin: 0 auto;
}

/* --- Header & Status Badges --- */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

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

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.brand-titles h1 {
  font-size: 1.35rem;
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success-soft);
  color: var(--success);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid rgba(30, 107, 52, 0.2);
}

.badge-offline {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(0, 94, 184, 0.22);
}

.badge-offline.is-offline {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: rgba(156, 66, 33, 0.28);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* --- Install & iOS/iPadOS Add to Home Screen Banner --- */
.install-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--primary-soft);
  border: 1px solid #90cdf4;
  color: #1a365d;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.install-banner[hidden] {
  display: none !important;
}

.install-banner-text {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
}

.install-banner-text svg {
  flex-shrink: 0;
  color: var(--primary);
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* --- Interactive Controls (48x48px Universal Touch Minimum) --- */
button,
select,
input[type="text"] {
  min-height: 48px;
  min-width: 48px;
  padding: 10px 16px;
  font-size: 1rem;
  font-family: inherit;
  border-radius: 10px;
  touch-action: manipulation;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.06s ease;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.btn-record {
  background: var(--danger);
  color: #ffffff;
  width: 100%;
  font-size: 1.08rem;
  box-shadow: 0 2px 8px rgba(198, 40, 40, 0.25);
}

.btn-record:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-stop {
  background: #1a202c;
  color: #ffffff;
  width: 100%;
  font-size: 1.08rem;
}

.btn-stop:hover:not(:disabled) {
  background: #2d3748;
}

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

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

.btn-outline {
  background: #edf2f7;
  color: var(--text);
  border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #feb2b2;
}

.btn-danger:hover:not(:disabled) {
  background: #fbd5d5;
}

.btn-icon-only {
  padding: 10px;
  width: 48px;
  height: 48px;
}

/* --- Keyboard Shortcut Hints --- */
kbd {
  display: inline-block;
  padding: 2px 7px;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  line-height: 1.3;
  color: currentColor;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 6px;
}

.kbd-dark {
  background: #edf2f7;
  color: var(--text);
  border-color: var(--border);
}

/* --- Responsive Grid Layout --- */
.layout {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  margin: 0 0 14px;
  font-size: 1.18rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-label {
  font-weight: 600;
  font-size: 0.9rem;
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

select,
.rename-input {
  width: 100%;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  margin-bottom: 12px;
}

.single-mic-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

/* --- Recorder Status, Timer & Live Level Meter --- */
.recorder-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  text-align: center;
}

.rec-state-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 3px 10px;
  border-radius: 999px;
  background: #e2e8f0;
}

.rec-state-pill.is-recording {
  background: var(--danger-soft);
  color: var(--danger);
}

.rec-pulse {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.rec-state-pill.is-recording .rec-pulse {
  animation: pulseDot 1s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

.timer {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 6px 0 10px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.level-meter-track {
  width: 100%;
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.level-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2e7d32 0%, #38a169 65%, #dd6b20 88%, #c62828 100%);
  border-radius: 999px;
  transition: width 0.06s linear;
}

.shortcut-hint {
  font-size: 0.83rem;
  color: var(--muted);
  margin-top: 10px;
  text-align: center;
}

/* --- Saved Recordings List & Storage Quota --- */
.rec-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  margin-bottom: 10px;
}

.rec-header h3 {
  margin: 0;
  font-size: 1.02rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-pill {
  background: #e2e8f0;
  color: var(--text);
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 999px;
}

.rec-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.rec-list-empty {
  font-size: 0.9rem;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}

.rec-item button {
  width: 100%;
  justify-content: space-between;
  text-align: left;
  background: #fafbfc;
  border: 2px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
}

.rec-item button:hover {
  background: #f1f5f9;
}

.rec-item.active button {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.rec-item-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rec-item-title {
  font-weight: 600;
  font-size: 0.96rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-item-meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
  margin-top: 2px;
}

.rec-item-wav {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  background: #ffffff;
  border: 1px solid #bee3f8;
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.storage-panel {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.83rem;
  color: var(--muted);
}

.storage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--text);
}

#storagePersistBadge {
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 0.76rem;
  background: #edf2f7;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.storage-bar {
  width: 100%;
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.storage-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 999px;
}

.shared-trolley-tip {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* --- Right Column: Editor, Playback & Waveform --- */
.empty-state {
  color: var(--muted);
  padding: 32px 16px;
  text-align: center;
  background: var(--surface-subtle);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.empty-state svg {
  color: var(--primary);
  opacity: 0.75;
  margin-bottom: 10px;
}

.empty-state p {
  max-width: 460px;
  margin: 0 auto;
}

.clip-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.playback-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 12px;
  flex-wrap: wrap;
}

.playback-row audio {
  flex: 1 1 240px;
  height: 48px;
}

.waveform-wrap {
  position: relative;
  margin: 12px 0 8px;
}

canvas#waveformCanvas {
  width: 100%;
  height: 164px;
  background: var(--canvas-bg);
  border-radius: 10px;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: ew-resize;
  border: 1px solid #2d3748;
}

.waveform-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
}

/* --- Accessible Range Sliders + +/-0.1s Nudge Controls --- */
.trim-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 12px 0;
}

.slider-group {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.slider-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 8px;
}

.time-readout {
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  font-weight: 700;
}

.slider-nudge-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-nudge {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  min-width: 58px;
  min-height: 48px;
  flex-shrink: 0;
}

.btn-nudge:hover:not(:disabled) {
  background: #edf2f7;
}

input[type="range"] {
  width: 100%;
  min-height: 48px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
  background: transparent;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

/* --- Toast Feedback --- */
.status-toast {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

/* --- Confirmation Modal Dialog --- */
dialog.confirm-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-md);
  color: var(--text);
}

dialog.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.dialog-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.dialog-msg {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.95rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* --- Mobile Thumb-Friendly Bottom Dock (Hidden on >= 640px) --- */
.mobile-thumb-bar {
  display: none;
}

/* --- Breakpoint 2: iPad / Tablet & 11" Chromebooks (640px – 1024px) --- */
@media (min-width: 640px) and (max-width: 1024px) {
  .layout {
    grid-template-columns: minmax(260px, 37%) minmax(0, 1fr);
    gap: 16px;
  }

  .card {
    padding: 16px;
  }

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

  .desktop-only-kbd {
    display: none;
  }
}

/* --- Breakpoint 3: Laptops / Desktops (> 1024px) --- */
@media (min-width: 1025px) {
  body {
    padding: 24px;
  }

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

/* --- Breakpoint 1: Mobile Phones (< 640px) --- */
@media (max-width: 639px) {
  body {
    padding: 12px 12px calc(92px + env(safe-area-inset-bottom, 0px));
  }

  .site-header {
    gap: 10px;
  }

  .brand-titles h1 {
    font-size: 1.2rem;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .card {
    padding: 16px;
  }

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

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

  .desktop-only-kbd,
  .shortcut-hint {
    display: none;
  }

  .mobile-thumb-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    gap: 10px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 14px rgba(15, 23, 42, 0.08);
  }

  .mobile-thumb-bar button {
    flex: 1 1 50%;
    min-height: 52px;
    font-size: 1rem;
  }
}
