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

:root {
  --bg:           #0b0d14;
  --surface:      #13151f;
  --surface2:     #1c1f2e;
  --glass-bg:     rgba(19, 21, 31, 0.82);
  --glass-border: rgba(108, 139, 255, 0.12);
  --accent:       #6c8bff;
  --accent-dim:   #2e3f80;
  --accent2:      #a78bfa;
  --text:         #e4e8f5;
  --text-dim:     #6b7498;
  --danger:       #ff6b6b;
  --radius:       14px;
  --top-h:        72px;
  --bottom-h:     84px;
  --panel-w:      380px;
  --menu-shadow:  0 8px 40px rgba(0,0,0,0.55);
  /* iOS safe areas */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Prevent overscroll bounce hiding content behind bars */
  overscroll-behavior-y: none;
}

/* Reduce default tap flash on iOS */
a, button, [role="button"], input, select, label {
  -webkit-tap-highlight-color: transparent;
}

/* Faster tap response on mobile */
button, [role="button"] {
  touch-action: manipulation;
}

/* ── Header toggle button ──────────────────── */
.header-toggle-btn {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 108px;
  height: 22px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  color: var(--text);
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.2s, color 0.2s;
}
.header-toggle-btn:hover { opacity: 1; color: var(--accent); }
.header-toggle-btn svg { width: 14px; height: 16px; }

/* ── Top bar ───────────────────────────────── */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 4px 32px rgba(0,0,0,0.3);
  padding: 0 1.5rem;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s ease,
              box-shadow 0.3s ease;
  max-height: 400px;
  /* Notch / dynamic island */
  padding-top: var(--safe-top);
}

.top-bar.collapsed {
  max-height: 0;
  opacity: 0;
  box-shadow: none;
  border-bottom-color: transparent;
}

.header-toggle-btn.header-hidden {
  opacity: 0.4;
}
.header-toggle-btn.header-hidden:hover { opacity: 1; }

.top-bar-inner {
  max-width: 1100px;
  margin: 0 auto;
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.brand-icon { width: 30px; height: 30px; flex-shrink: 0; }

.brand-name {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-inputs {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.dropzone-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1.1rem;
  border: 1px dashed rgba(108, 139, 255, 0.35);
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 40px;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  user-select: none;
}

.dropzone-pill svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }

.dropzone-pill:hover,
.dropzone-pill.drag-over {
  border-color: var(--accent);
  background: rgba(108, 139, 255, 0.08);
  color: var(--text);
}

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

.file-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.or-label { color: var(--text-dim); font-size: 0.8rem; flex-shrink: 0; }

.url-row { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }

.url-input {
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 99px;
  padding: 0.45rem 1rem;
  font-size: 0.88rem;
  transition: border-color 0.2s, background 0.2s;
}

.url-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(108, 139, 255, 0.06);
}

.url-input::placeholder { color: var(--text-dim); }

.header-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0.3rem 0 0.4rem;
  gap: 0.5rem 1rem;
}

.supported-types {
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  opacity: 0.6;
}

/* ── Sync ─────────────────────────────────── */
.sync-wrapper {
  position: relative;
  flex-shrink: 0;
}

.sync-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  background: rgba(108, 139, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}
.sync-toggle-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.sync-toggle-btn:hover {
  background: rgba(108, 139, 255, 0.18);
  border-color: var(--accent);
}

.sync-dropdown {
  position: fixed;
  z-index: 500;
  width: 260px;
  padding: 1rem;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}

.sync-dropdown-section { display: flex; flex-direction: column; gap: 0.4rem; }

.sync-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.sync-code-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: rgba(108, 139, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--accent);
  cursor: pointer;
  user-select: all;
}
.sync-code-display svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.5; }
.sync-code-display:hover {
  background: rgba(108, 139, 255, 0.15);
  border-color: var(--accent);
}
.sync-code-display:hover svg { opacity: 1; }

.sync-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  opacity: 0.7;
  line-height: 1.4;
}

.sync-dropdown-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 0.75rem 0;
}

.sync-restore {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.restore-input {
  flex: 1;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}
.restore-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(108, 139, 255, 0.06);
}
.restore-input::placeholder {
  color: var(--text-dim);
  letter-spacing: normal;
  font-weight: 400;
  text-transform: none;
}

.mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.mode-btn {
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  touch-action: manipulation;
}

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

/* ── Main content ──────────────────────────── */
.main-content {
  flex: 1;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: calc(2rem + 22px) 1.5rem calc(var(--bottom-h) + var(--safe-bottom) + 2rem);
}

/* ── History ────────────────────────────────── */
.history-section {
  margin-bottom: 1.5rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.history-heading {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.history-item:hover { border-color: rgba(108,139,255,0.3); }

.history-item-body {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.history-item-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0.7;
}

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

.history-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.history-item-meta {
  font-size: 0.76rem;
  color: var(--text-dim);
  margin: 0.15rem 0 0;
}

.history-item-bar {
  height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  margin-top: 0.4rem;
  overflow: hidden;
  max-width: 160px;
}

.history-item-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

.history-item-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.history-remove-btn {
  font-size: 0.72rem !important;
  padding: 0.2rem 0.5rem !important;
  opacity: 0.5;
}
.history-remove-btn:hover { opacity: 1; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  margin-top: 6rem;
  color: var(--text-dim);
  font-size: 0.95rem;
  text-align: center;
  padding: 0 1rem;
}

.empty-state svg { width: 80px; height: 80px; opacity: 0.7; }

.status {
  padding: 0.9rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.status-spinner {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  animation: spin 0.8s linear infinite;
  color: var(--accent);
}

.status.error {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.3);
  background: rgba(255, 107, 107, 0.06);
}

.player { display: flex; flex-direction: column; gap: 1rem; }

.file-info { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }

.filename {
  font-weight: 700;
  font-size: 1.05rem;
  word-break: break-all;
  background: linear-gradient(135deg, var(--text), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.char-count { color: var(--text-dim); font-size: 0.78rem; }

.warning {
  background: rgba(255, 107, 107, 0.07);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.88rem;
  color: var(--danger);
}

/* ── Text display ──────────────────────────── */
.text-display {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1.8rem 2rem;
  font-size: 1rem;
  line-height: 1.85;
  color: var(--text-dim);
  display: none;
}

.text-display.visible { display: block; }

.text-display p {
  margin-bottom: 1.4em;
}
.text-display p:last-child { margin-bottom: 0; }

.text-display h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 2rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--glass-border);
}
.text-display h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin: 1.5rem 0 0.4rem;
}
.text-display h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dim);
  margin: 1.2rem 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.text-display ul {
  margin: 0.2rem 0 1.2rem 0;
  padding-left: 1.4rem;
}
.text-display li {
  margin-bottom: 0.5em;
  line-height: 1.6;
}
.text-display h2:first-child,
.text-display h3:first-child { margin-top: 0; }

.text-sentence {
  display: inline;
  border-radius: 4px;
  padding: 2px 3px;
  cursor: pointer;
  transition: background 0.25s, color 0.25s;
}

/* Desktop hover only — mobile has no hover */
@media (hover: hover) {
  .text-sentence:hover {
    background: rgba(108, 139, 255, 0.1);
    color: var(--text);
  }
}

/* TTS playback highlight */
.text-sentence.active {
  background: rgba(108, 139, 255, 0.18);
  border-radius: 4px;
  transition: background 0.15s;
}

.text-word.speaking {
  font-weight: 700;
  color: #fff;
}

/* User-selected sentence */
.text-sentence.selected {
  outline: 2px solid var(--accent2);
  outline-offset: 1px;
  background: rgba(167, 139, 250, 0.12);
  color: var(--text);
}

.text-sentence.active.selected {
  background: rgba(108, 139, 255, 0.22);
  outline: 2px solid var(--accent2);
}

/* ── Bottom bar ────────────────────────────── */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -4px 32px rgba(0,0,0,0.3);
  /* Notch / home indicator */
  padding-bottom: var(--safe-bottom);
}

.bottom-bar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

.controls { display: flex; gap: 0.5rem; flex-shrink: 0; }

.settings { display: flex; align-items: center; gap: 1.2rem; flex: 1; flex-wrap: wrap; }

.setting-group { display: flex; align-items: center; gap: 0.6rem; }

.setting-group label { color: var(--text-dim); font-size: 0.8rem; white-space: nowrap; }

input[type="range"] { width: 90px; accent-color: var(--accent); cursor: pointer; }

select {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
  max-width: 160px;
}

.progress-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  min-width: 140px;
}

.progress-bar-wrap {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border-radius: 99px;
  height: 5px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  width: 0%;
  transition: width 0.4s;
}

.chunk-label { color: var(--text-dim); font-size: 0.75rem; white-space: nowrap; }

.panel-actions { display: flex; align-items: center; flex-shrink: 0; margin-left: auto; }

/* ── Buttons ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  min-height: 40px;
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn:hover:not(:disabled) {
  background: rgba(108, 139, 255, 0.12);
  border-color: var(--accent);
}

.btn:active:not(:disabled) {
  background: rgba(108, 139, 255, 0.2);
}

.btn:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }

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

.btn-primary:hover:not(:disabled) { background: #7a99ff; border-color: #7a99ff; }

.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.85rem; border-radius: 99px; }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.btn-icon svg { width: 18px; height: 18px; }

/* Notes badge */
.notes-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background: var(--accent2);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  line-height: 1;
}

/* ── Sentence context menu ─────────────────── */
.sentence-menu {
  position: fixed;
  z-index: 300;
  background: var(--surface2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--menu-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 152px;
}

.sentence-menu-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
  text-align: left;
  touch-action: manipulation;
}

.sentence-menu-item svg { width: 16px; height: 16px; color: var(--accent); flex-shrink: 0; }

.sentence-menu-item:hover { background: rgba(108, 139, 255, 0.14); }
.sentence-menu-item:active { background: rgba(108, 139, 255, 0.22); }

/* ── Panel overlay ─────────────────────────── */
.panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* ── Side panels ───────────────────────────── */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  max-width: 100vw;
  z-index: 210;
  background: var(--surface);
  border-left: 1px solid var(--glass-border);
  box-shadow: -8px 0 48px rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  /* Notch safety */
  padding-bottom: var(--safe-bottom);
}

.side-panel.open { transform: translateX(0); }

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  /* Notch safety for full-screen mobile panel */
  padding-top: max(1rem, var(--safe-top));
}

.side-panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.panel-close-btn { border: none !important; background: transparent !important; }

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

#btn-share-all .share-all-label {
  display: inline;
}

@media (max-width: 400px) {
  #btn-share-all .share-all-label { display: none; }
  #btn-share-all { padding: 0; width: 36px; height: 36px; justify-content: center; }
}

/* ── Notes panel ───────────────────────────── */
.notes-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.notes-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}

.notes-empty svg { width: 48px; height: 48px; color: var(--text-dim); opacity: 0.4; }

.notes-empty strong { color: var(--accent2); font-weight: 600; }

.note-card {
  background: var(--surface2);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  position: relative;
}

.note-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.note-filename {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.note-timestamp { font-size: 0.7rem; color: var(--text-dim); flex-shrink: 0; }

.note-quote {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.6;
  border-left: 3px solid var(--accent2);
  padding-left: 0.65rem;
  margin: 0;
  word-break: break-word;
}

.note-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--glass-border);
}

.note-share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  min-height: 36px;
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}

.note-share-btn svg { width: 14px; height: 14px; }

.note-research-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  min-height: 36px;
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-dim);
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}

.note-research-btn svg { width: 14px; height: 14px; }

.note-research-btn:hover,
.note-research-btn:active {
  background: rgba(167, 139, 250, 0.12);
  border-color: var(--accent2);
  color: var(--text);
}

.note-share-btn:hover,
.note-share-btn:active {
  background: rgba(108, 139, 255, 0.12);
  border-color: var(--accent);
  color: var(--text);
}

.note-delete-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  touch-action: manipulation;
}

.note-delete-btn:hover,
.note-delete-btn:active { color: var(--danger); }

.note-delete-btn svg { width: 15px; height: 15px; }

/* ── Research panel ────────────────────────── */
.research-quote-wrap {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.research-quote {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.65;
  border-left: 3px solid var(--accent);
  padding-left: 0.7rem;
  margin: 0;
  font-style: italic;
  word-break: break-word;
}

.research-result {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.2rem;
}

.research-text {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.8;
  white-space: pre-wrap;
}

.research-loading {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text-dim);
  font-size: 0.88rem;
  padding: 0.5rem 0;
}

.research-loading svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  animation: spin 1s linear infinite;
  color: var(--accent);
}

.research-error { font-size: 0.88rem; color: var(--danger); }

.research-refs {
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--glass-border);
}

.research-refs-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 0.6rem;
}

.research-refs-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.research-ref-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.research-ref-link:hover {
  background: rgba(108, 139, 255, 0.1);
  border-color: var(--glass-border);
}

.ref-icon {
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(108, 139, 255, 0.15);
  border-radius: 4px;
  color: var(--accent);
}

/* ── Toast ─────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface2);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.55rem 1.1rem;
  border-radius: 99px;
  box-shadow: var(--menu-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 400;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Footer ───────────────────────────────── */
.site-footer {
  width: 100%;
  padding: 0.55rem 1rem calc(0.55rem + var(--safe-bottom));
  text-align: center;
  background: var(--glass-bg);
  border-top: 1px solid var(--glass-border);
}

.site-footer-link {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-decoration: none;
  opacity: 0.5;
  transition: opacity 0.2s, color 0.2s;
}
.site-footer-link:hover { opacity: 1; color: var(--accent); }

/* ── Utility ───────────────────────────────── */
.hidden { display: none !important; }

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

/* ─────────────────────────────────────────────
   MOBILE — ≤ 680px
   ───────────────────────────────────────────── */
@media (max-width: 680px) {
  :root {
    --panel-w:    100vw;
    --bottom-h:   138px;  /* taller to fit 2 rows */
  }

  /* ── Top bar ── */
  .top-bar { padding: 0 1rem; }

  .top-bar-inner {
    height: auto;
    flex-wrap: wrap;
    padding: 0.8rem 0 0.5rem;
    gap: 0.6rem;
  }

  .brand { width: 100%; }

  .header-inputs {
    flex-wrap: wrap;
    gap: 0.6rem;
    width: 100%;
  }

  .dropzone-pill {
    width: 100%;
    justify-content: center;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-size: 0.92rem;
    min-height: 44px;
  }

  .or-label { display: none; }   /* just stack; "or" is implied */

  .url-row { width: 100%; }

  /* Prevent iOS zoom on input focus — must be ≥ 16px */
  .url-input {
    font-size: 16px;
    padding: 0.6rem 1rem;
    min-height: 44px;
    border-radius: var(--radius);
  }

  .btn-sm {
    min-height: 44px;
    padding: 0 1.1rem;
    border-radius: var(--radius);
    font-size: 0.92rem;
  }

  .sync-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: 18px 18px 0 0;
    padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
    z-index: 300;
  }
  .restore-input { font-size: 16px; min-height: 44px; border-radius: 10px; }

  /* ── Main content ── */
  .main-content {
    padding: 1.25rem 1rem calc(var(--bottom-h) + var(--safe-bottom) + 1.5rem);
  }

  .text-display {
    padding: 1.2rem 1.1rem;
    font-size: 1rem;
    line-height: 1.9;
    border-radius: 10px;
  }

  .text-sentence {
    padding: 3px 4px;  /* slightly larger tap target area */
  }

  /* ── Bottom bar — 2-row layout ── */
  .bottom-bar-inner {
    flex-wrap: wrap;
    padding: 0.65rem 1rem;
    gap: 0.5rem;
    row-gap: 0.55rem;
  }

  /* Row 1: play controls on left, notes on right */
  .controls     { order: 1; flex: 1; gap: 0.4rem; }
  .panel-actions{ order: 2; margin-left: 0; }

  /* Row 2: progress bar, full width */
  .progress-section {
    order: 3;
    width: 100%;
    min-width: unset;
    gap: 0.6rem;
  }

  /* Row 3: speed + voice, full width */
  .settings {
    order: 4;
    width: 100%;
    gap: 0.75rem;
    justify-content: space-between;
  }

  .setting-group { flex: 1; }

  input[type="range"] {
    flex: 1;
    width: auto;
    min-width: 60px;
  }

  select {
    flex: 1;
    max-width: 100%;
    font-size: 14px;
    min-height: 36px;
  }

  /* Play/Pause/Stop slightly larger on mobile */
  .controls .btn {
    padding: 0.55rem 0.85rem;
    font-size: 0.88rem;
  }

  /* ── Sentence context menu — centered above bottom bar ── */
  .sentence-menu {
    min-width: 160px;
    border-radius: var(--radius);
  }

  .sentence-menu-item {
    min-height: 48px;
    font-size: 0.95rem;
    padding: 0.7rem 1rem;
  }

  /* ── Side panels ── */
  .side-panel { border-left: none; border-top: 1px solid var(--glass-border); }
}

/* Very small screens */
@media (max-width: 360px) {
  .controls .btn span { display: none; }   /* hide button text, keep icons */
  .controls .btn { padding: 0.55rem 0.65rem; }
}
