/* ===== TRENDING TAB ===== */
.trending-section { margin-bottom: 24px; }

.section-title {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.trending-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.filter-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.trending-list { display: flex; flex-direction: column; gap: 8px; }

.trending-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.trending-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
  flex-shrink: 0;
}

.trending-info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.trending-label { font-weight: 700; font-size: 0.9rem; overflow-wrap: anywhere; }
.trending-meta { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; overflow-wrap: anywhere; }

.trending-bar-wrap { width: 80px; }
.trending-bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.trending-bar-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.trending-count {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--brand-ink);
  min-width: 32px;
  text-align: right;
}

/* ===== SUPPORT HANDOFF ===== */
.support-wrap { max-width: 760px; margin: 0 auto; }
.support-intro, .support-card, .support-note { margin-bottom: 14px; }
.support-intro h1 { font-size: 1.35rem; margin-bottom: 7px; }
.support-intro p, .support-note { color: var(--text-secondary); line-height: 1.5; }
.support-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.support-field { display: block; margin: 14px 0; font-weight: 700; }
.support-field select, .support-field textarea { display: block; width: 100%; margin-top: 7px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface2); color: var(--text-primary); font: inherit; }
.support-field select { min-height: 48px; }
.support-field textarea { min-height: 126px; resize: vertical; line-height: 1.45; }
.support-actions, .support-phrases { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.support-phrase { min-height: 42px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface2); color: var(--text-primary); cursor: pointer; font: inherit; }
.support-consent { display: flex; align-items: flex-start; gap: 10px; margin: 14px 0; line-height: 1.45; }
.support-consent input { width: 22px; height: 22px; flex: 0 0 22px; }
.support-launch { min-height: 50px; width: 100%; border: 0; border-radius: var(--radius-sm); background: var(--brand); color: #fff; cursor: pointer; font: inherit; font-weight: 800; }
.support-launch:disabled { opacity: .48; cursor: not-allowed; }
.support-status { min-height: 1.5em; margin-top: 10px; color: var(--text-secondary); }
.support-contact-info { padding: 12px; border-radius: var(--radius-sm); background: var(--surface2); line-height: 1.5; }
.support-contact-info a { color: var(--brand-ink); overflow-wrap: anywhere; }
html[data-theme="dark"] .support-phrase { color: var(--text-primary); }
@media (max-width: 600px) { .support-card { padding: 12px; } }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* ===== SETTINGS PANEL ===== */
#settings-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  background: rgba(0,0,0,0.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  /* hidden = not focusable and not read out while closed */
  visibility: hidden;
  transition: opacity 0.25s, visibility 0s linear 0.25s;
}

#settings-panel.open {
  opacity: 1;
  pointer-events: all;
  visibility: visible;
  transition: opacity 0.25s, visibility 0s;
}

#settings-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  box-shadow: var(--shadow-lg);
}

#settings-panel.open #settings-sheet { transform: translateY(0); }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.sheet-title { font-size: 1.1rem; font-weight: 800; }

.sheet-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-body { padding: 16px 20px 40px; }

.settings-section {
  margin-bottom: 24px;
}

.settings-section-title {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-ink);
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.settings-row > div:first-child { flex: 1 1 12rem; min-width: 0; }

.settings-row:last-child { border-bottom: none; }

.settings-row-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.settings-row-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(22px); }
.toggle input:focus-visible + .toggle-slider { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Select / Range */
.settings-select {
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.settings-range {
  width: 130px;
  accent-color: var(--brand);
}

.btn-action {
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-action:hover { border-color: var(--brand); color: var(--brand-ink); }
.btn-action.danger { border-color: var(--danger); color: var(--danger-ink); }
.btn-action.danger:hover { background: var(--danger); color: #fff; }
.btn-action.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-action.primary:hover { background: var(--brand-dark); }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0s linear 0.2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; visibility: visible; transition: opacity 0.2s, visibility 0s; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.94);
  transition: transform 0.22s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 1.05rem; font-weight: 800; }
.modal-body { padding: 18px 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Form inputs */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 0.8rem; font-weight: 700; margin-bottom: 5px; color: var(--text-secondary); }

.form-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color 0.15s;
}

.form-input:focus { outline: none; border-color: var(--brand); }

.emoji-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.emoji-opt {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface2);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}

.emoji-opt.selected { border-color: var(--brand); background: var(--brand-light); }

.color-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.color-swatch.selected { border-color: var(--text-primary); transform: scale(1.15); }

/* PIN pad */
.pin-display {
  text-align: center;
  font-size: 2.2rem;
  letter-spacing: 0.4em;
  padding: 12px 0 20px;
  min-height: 60px;
  color: var(--brand-ink);
  font-weight: 800;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 280px;
  margin: 0 auto;
}

.pin-key {
  height: 60px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface2);
  color: var(--text-primary);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-key:active { transform: scale(0.92); background: var(--brand-light); }
.pin-key.del { color: var(--danger-ink); }
.pin-key:disabled { opacity: 0.45; cursor: not-allowed; }
.pin-key.ok { background: var(--brand); color: #fff; border-color: var(--brand); }

.pin-error { color: var(--danger-ink); font-size: 0.85rem; text-align: center; margin-top: 8px; font-weight: 600; }

/* ===== LOCK INDICATOR ===== */
#lock-indicator {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  right: max(16px, env(safe-area-inset-right, 0px));
  max-width: calc(100dvw - 32px);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: normal;
  overflow-wrap: anywhere;
  transition: all 0.15s;
}

#lock-indicator:hover { border-color: var(--brand); color: var(--brand-ink); }
#lock-indicator.unlocked { border-color: var(--success); color: var(--success-ink); }

/* ===== CATEGORIES VIEW ===== */
.category-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}

.category-card:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.category-card-icon { font-size: 2rem; }
.category-card-name { font-weight: 800; font-size: 0.9rem; }
.category-card-count { font-size: 0.75rem; color: var(--text-secondary); }

.categories-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

@media (min-width: 600px) {
  .categories-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1200px) {
  .categories-grid { grid-template-columns: repeat(5, 1fr); }
}

/* ===== PRIVACY NOTICE ===== */
.privacy-box {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.6;
  border: 1px solid var(--border);
}

.privacy-box h4 { color: var(--text-primary); font-size: 0.85rem; margin-bottom: 8px; }
.privacy-box ul { padding-left: 16px; }
.privacy-box li { margin-bottom: 4px; }

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text-primary);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 999;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1), opacity 0.3s;
  opacity: 0;
  pointer-events: none;
  white-space: normal;
  text-align: center;
  width: max-content;
  max-width: min(90vw, 480px);
  line-height: 1.35;
}

#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ===== SPEAKING ANIMATION ===== */
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(25,118,210,0.4); }
  70% { box-shadow: 0 0 0 10px rgba(25,118,210,0); }
  100% { box-shadow: 0 0 0 0 rgba(25,118,210,0); }
}

.tile.speaking { animation: pulse-ring 0.6s ease-out; border-color: var(--brand); }

/* ===== BOARD MANAGEMENT HEADER ===== */
#board-mgmt-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

#board-mgmt-bar select {
  flex: 1;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.88rem;
  padding: 0 10px;
}

/* Scrollable wrapper for category boards */
#board-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-inline: calc(0px - var(--content-padding, 14px));
  padding-inline: var(--content-padding, 14px);
  scrollbar-width: none;
}
#board-scroll::-webkit-scrollbar { display: none; }
#board-scroll #board-nav { flex-wrap: nowrap; }
.tile-order { position:absolute; bottom:4px; z-index:3; width:30px; height:30px; border:0; border-radius:50%; background:var(--surface); color:var(--brand-ink); font-size:1rem; box-shadow:var(--shadow); cursor:pointer; }
.tile-order.up { left:4px; } .tile-order.down { left:38px; }
.board-move { width:28px; height:28px; border-radius:50%; border:1px solid var(--border); background:var(--surface); color:var(--text-primary); font-size:.8rem; cursor:pointer; flex-shrink:0; }
.board-move:disabled,.tile-order:disabled { opacity:.35; cursor:default; }
html[data-high-contrast="true"] .tile[data-color] { background:#000; border-color:#fff; color:#fff; }
.phrase-chip { min-height:38px; border:1px solid var(--border); border-radius:20px; padding:4px 12px; background:var(--surface); color:var(--text-primary); font:inherit; white-space:nowrap; cursor:pointer; }
.phrase-delete { border:0; background:transparent; color:var(--danger-ink); cursor:pointer; padding:4px; }
#phrase-bar { display:flex; gap:6px; overflow-x:auto; padding:4px 0 8px; }
.msg-word { border:0; cursor:pointer; font:inherit; }
.msg-word:focus-visible { outline:2px solid var(--brand); }
.msg-actions #btn-repeat { font-size:1rem; }

/* Landscape tweaks */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --msg-h: 60px; --tab-h: 50px; }
  .tab-btn .tab-icon { font-size: 1.1rem; }
}

/* ===== KEYBOARD SHORTCUTS ===== */
.shortcuts-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.shortcuts-table th { text-align: left; padding: 6px 8px; color: var(--text-secondary); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.shortcuts-table td { padding: 7px 8px; border-top: 1px solid var(--border); }
.shortcuts-table td:first-child { font-family: monospace; background: var(--surface2); border-radius: 4px; color: var(--brand-ink); font-weight: 700; }

/* ===== QA FIXES ===== */
.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;
}
.board-chip-wrap { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; }
.board-del {
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: var(--danger); color: #fff; font-size: 0.7rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.trending-emoji { font-size: 1.4rem; line-height: 1; flex-shrink: 0; }
.trending-info .trending-bar-wrap { width: 100%; max-width: 120px; margin-top: 4px; }
.settings-warn { color: var(--danger-ink); font-weight: 600; }
.form-hint { font-size: 0.75rem; color: var(--text-secondary); margin-top: 6px; line-height: 1.45; }
.tile-audio-current { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: 0.8rem; color: var(--text-secondary); }
.btn-action { white-space: nowrap; flex-shrink: 0; }
.btn-action.small { height: 32px; padding: 0 10px; font-size: 0.75rem; }
/* Room at the bottom so the lock button never covers the last row of tiles */
#content { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

/* ===== ARTWORK ===== */
.board-chip-img { width: 22px; height: 22px; object-fit: contain; flex-shrink: 0; }
.msg-word { gap: 5px; }
.msg-img { width: 22px; height: 22px; object-fit: contain; }
.trending-img { width: 36px; height: 36px; object-fit: contain; display: block; }
.trending-mini-img { width: 18px; height: 18px; object-fit: contain; vertical-align: -4px; }
.category-card-img { width: 52px; height: 52px; object-fit: contain; display: block; }
.art-picker {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px;
  max-height: 228px; overflow-y: auto; margin-top: 8px; padding: 6px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface2);
}
.art-opt {
  aspect-ratio: 1; padding: 4px; border: 2px solid transparent; border-radius: 10px;
  background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.art-opt[hidden] { display: none; }
.art-opt img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.art-opt:hover { border-color: var(--brand); }
.art-opt.selected { border-color: var(--brand); background: var(--brand-light); }
/* Tall dialogs (picture picker) never run off small or landscape screens: the body scrolls */
.modal { max-height: calc(100dvh - 40px); display: flex; flex-direction: column; }
.modal-body { overflow-y: auto; min-height: 0; }
@media (orientation: landscape) and (max-height: 500px) {
  .tile-img { width: 50%; }
}

/* Defer off-screen cards only when a custom board is large enough to matter. */
.tile-grid--large-board > .tile-wrap[data-offscreen="true"] {
  content-visibility: auto;
  contain-intrinsic-size: auto var(--tile-intrinsic-block-size, 9rem);
}

/* Reflow dense panels before their controls become cramped on smaller screens. */
@media (max-width: 600px) {
  .category-card { padding: 12px; }
  .settings-row { flex-wrap: wrap; align-items: flex-start; }
  .settings-row > div:first-child { flex-basis: 100%; }
  .settings-row > :not(:first-child) { margin-inline-start: auto; }
  .settings-range { width: min(100%, 13rem); }
}
