/* Copyright © 2026 BiblePeep. All rights reserved. */
/* app.css
   Layout for the control view (app.html) and shared by settings.html for
   its button/modal base styles. Verse-view look itself comes from shared.css.

   Restyled to match the site's dark "Live Feed" brand (previously this was
   a plain light theme, inconsistent with the rest of the site).
*/

@import "tokens.css";

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
}

/* Phones: touch polish. Removes the ~300ms double-tap-to-zoom delay on
   controls and the grey tap flash, and stops iOS auto-inflating text. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button, a, select, summary {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* dvh = the visible height as the phone's browser bar shows/hides, so the
     controls never end up hidden behind it. 100vh above is the fallback. */
  height: 100dvh;
}

/* ---------- Header ---------- */

.app__header {
  position: relative;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.6rem 3.2rem 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.header-logo-link {
  display: inline-flex;
  flex-shrink: 0;
  order: 0;
}

.header-logo {
  height: 34px;
  width: auto;
  border-radius: 4px;
  flex-shrink: 0;
}

.app__header select {
  font-size: 0.88rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

/* On wide screens #header-menu is invisible to layout: its children sit
   directly in the header, ordered exactly as before the menu existed. */
.header-menu {
  display: contents;
}

#translation-select { order: 1; }
.search-wrap { order: 2; }
#browse-btn { order: 3; }
#upload-translation-btn { order: 4; }
#open-display-btn { order: 5; }
.header-menu a.btn-header { order: 6; }

.btn-header--menu,
.btn-header__label,
.browse-bar {
  display: none;
}

/* ---------- Search + its results dropdown ---------- */

.search-wrap {
  position: relative;
  flex: 1 1 340px;
  max-width: 640px;
  min-width: 180px;
}

#search-input {
  width: 100%;
  font-size: 0.88rem;
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

#search-input::placeholder {
  color: var(--muted);
}

#search-input:focus {
  outline: none;
  border-color: var(--cyan);
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  max-height: min(60vh, 420px);
  overscroll-behavior: contain;
  overflow-y: auto;
  z-index: 50;
  padding: 0.4rem;
}

/* ---------- Header buttons ---------- */

.btn-header {
  font-size: 0.85rem;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-header:hover {
  border-color: var(--cyan);
}

.btn-header--accent {
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  color: #0a0a0f;
  font-weight: 600;
  border: none;
}

.btn-header--icon {
  position: absolute;
  top: 50%;
  right: 1rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  color: var(--text);
}

/* ---------- Browse overlay (Book -> Chapter -> Verse) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
}

.browse-panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.4);
  width: min(760px, 92vw);
  height: min(560px, 80vh);
  height: min(560px, 80dvh);
  display: flex;
  overflow: hidden;
}

.browse-panel__close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.browse-panel__close:hover {
  color: var(--text);
  background: var(--bg);
}

.browse-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding: 0.9rem 0.6rem;
  overflow: hidden;
}

.browse-col:last-child {
  border-right: none;
}

.browse-col h3 {
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 0.4rem;
}

/* ---------- Shared nav-item styling (browse columns + search dropdown) ---------- */

.nav-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-list--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr));
  gap: 4px;
}

.nav-item {
  text-align: left;
  background: none;
  border: none;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  font-family: var(--font-body);
}

.nav-item:hover {
  background: rgba(139, 92, 246, 0.12);
}

.nav-item--active {
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  color: #0a0a0f;
  font-weight: 600;
}

.nav-item--grid {
  text-align: center;
  padding: 0.35rem;
}

.nav-item strong {
  color: inherit;
}

/* ---------- Live display ---------- */

.app__body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.app__display {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.display-panel {
  flex: 1;
  min-height: 0;
}

.controls {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--panel);
  border-top: 1px solid var(--border);
  justify-content: center;
}

.controls button {
  padding: 0.55rem 1.3rem;
  border-radius: 6px;
  border: none;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font-display);
  font-weight: 500;
}

.controls button:hover {
  border-color: var(--cyan);
}

#next-btn,
#prev-btn {
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  color: #0a0a0f;
  font-weight: 600;
  border: none;
}

#blank-btn:hover {
  border-color: #e05252;
  color: #e05252;
}

/* ---------- Shared button base (used by settings.html too) ---------- */

.btn {
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}

.btn--secondary {
  background: #eef0f3;
  color: #333;
}

.btn--secondary:hover {
  background: #e2e5ea;
}

/* ---------- Upload modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: white;
  border-radius: 12px;
  padding: 1.75rem;
  width: 28rem;
  max-width: 90vw;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.modal h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: #16181d;
}

.modal__hint {
  font-size: 0.85rem;
  color: #8a8f9a;
  margin: 0 0 1.25rem;
  line-height: 1.45;
}

/* Drop zone: click or drag a file onto it */
.drop-zone {
  border: 1.5px dashed #d6d9e0;
  border-radius: 10px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  margin-bottom: 1rem;
}

.drop-zone:hover,
.drop-zone--active {
  border-color: var(--violet);
  background: rgba(139, 92, 246, 0.05);
}

.drop-zone__icon {
  width: 34px;
  height: 34px;
  margin: 0 auto 0.6rem;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
}

.drop-zone__label {
  font-size: 0.85rem;
  color: #4a4e58;
  margin: 0;
}

.drop-zone__label strong {
  color: var(--violet);
}

.drop-zone__filename {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #4a4e58;
  margin-top: 0.4rem;
  word-break: break-all;
}

.modal input[type="file"] {
  display: none;
}

.field-label {
  display: block;
  margin-bottom: 1rem;
}

.field-label span {
  display: block;
  font-size: 0.8rem;
  color: #6a6f79;
  margin-bottom: 0.3rem;
}

.field-label input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  border: 1px solid #d6d9e0;
  font-size: 0.88rem;
  font-family: inherit;
  color: #16181d;
}

.field-label input[type="text"]:focus {
  outline: none;
  border-color: var(--violet);
}

.upload-status {
  font-size: 0.85rem;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  line-height: 1.45;
}

.upload-status--info {
  background: #eef2ff;
  color: #3a3f5c;
}

.upload-status--success {
  background: #e6f7ec;
  color: #205c37;
}

.upload-status--error {
  background: #fdecec;
  color: #8a2222;
}

.upload-status--warning {
  background: #fff6e0;
  color: #6b5300;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal__actions .btn--primary {
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  color: #0a0a0f;
  font-weight: 600;
  font-family: var(--font-display);
}

.modal__actions .btn--primary:disabled {
  background: #d8dae0;
  color: #9a9ea8;
  cursor: not-allowed;
}

/* ---------- Phones & small tablets ----------
   "Compact" = narrower than 900px (phones, tablets in portrait) OR shorter
   than 500px (phones in landscape). The header becomes one slim row with a
   menu, the controls become big thumb-friendly buttons, and nothing needs
   zooming or scrolling to reach. */

@media (max-width: 900px), (max-height: 500px) {
  .app__header {
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.5rem calc(0.75rem + env(safe-area-inset-right)) 0.5rem calc(0.75rem + env(safe-area-inset-left));
  }

  .header-logo {
    height: 32px;
  }

  .search-wrap {
    order: 1;
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
  }

  #browse-btn {
    order: 2;
  }

  .btn-header--menu {
    order: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 2.75rem;
    min-height: 2.75rem;
  }

  .header-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: calc(0.5rem + env(safe-area-inset-right));
    width: min(20rem, calc(100vw - 1rem));
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5);
    z-index: 80;
  }

  .app__header.menu-open .header-menu {
    display: flex;
  }

  .app__header.menu-open .btn-header--menu {
    border-color: var(--cyan);
  }

  #translation-select,
  #upload-translation-btn,
  #open-display-btn,
  .header-menu a.btn-header {
    order: 0;
  }

  .header-menu > * {
    width: 100%;
    min-height: 2.75rem;
    text-align: center;
  }

  .header-menu > a.btn-header {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn-header--icon {
    position: static;
    transform: none;
    display: inline-flex;
    gap: 0.5rem;
    padding: 0.45rem 0.8rem;
  }

  .btn-header__label {
    display: inline;
  }

  /* Controls: Prev | Blank | Next, with the two big buttons filling the
     width so they're easy to hit with a thumb. */
  .controls {
    gap: 0.6rem;
    padding: 0.6rem calc(0.75rem + env(safe-area-inset-right)) calc(0.6rem + env(safe-area-inset-bottom)) calc(0.75rem + env(safe-area-inset-left));
  }

  .controls button {
    min-height: 3.25rem;
    font-size: 1rem;
  }

  #prev-btn { order: 1; flex: 1 1 0; }
  #blank-btn { order: 2; flex: 0 0 auto; }
  #next-btn { order: 3; flex: 1 1 0; }

  .display-panel {
    touch-action: pan-y;
  }
}

/* Second screen only makes sense with a pointer and room for two windows. */
@media (pointer: coarse) and (max-width: 760px), (pointer: coarse) and (max-height: 500px) {
  #open-display-btn {
    display: none;
  }
}

/* Finger-sized targets. 16px text in inputs stops iOS from zooming the page
   when a field is tapped. */
@media (pointer: coarse) {
  .header-logo-link {
    min-height: 2.75rem;
    align-items: center;
  }

  .controls button {
    min-height: 2.75rem;
  }

  .btn-header,
  .app__header select,
  #search-input,
  .nav-item,
  .browse-panel__close,
  .btn,
  .modal input[type="text"] {
    min-height: 2.75rem;
  }

  #search-input,
  .app__header select,
  .modal input[type="text"],
  select {
    font-size: 16px;
  }

  .nav-item {
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
  }

  .nav-item--grid {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .browse-panel__close {
    min-width: 2.75rem;
  }
}

/* Tablets in portrait keep the three-column Browse, just bigger. */
@media (pointer: coarse) and (min-width: 601px) {
  .nav-item {
    font-size: 0.95rem;
  }
}

/* ---------- Browse as one step at a time (phones) ---------- */

@media (max-width: 600px), (max-height: 500px) {
  .overlay {
    align-items: stretch;
    justify-content: stretch;
    backdrop-filter: none;
    background: var(--bg);
  }

  .browse-panel {
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .browse-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    min-height: 3.5rem;
    padding: 0.4rem 3.75rem 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
  }

  .browse-bar__back {
    flex-shrink: 0;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
  }

  .browse-bar__title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .browse-panel__close {
    top: 0.45rem;
    right: 0.6rem;
    font-size: 1.6rem;
    width: 2.75rem;
    height: 2.75rem;
  }

  .browse-col {
    display: none;
    flex: 1;
    min-height: 0;
    border: none;
    padding: 0.5rem 0.5rem 0.75rem;
  }

  .browse-col h3 {
    display: none;
  }

  .browse-panel[data-step="books"] .browse-col[data-col="books"],
  .browse-panel[data-step="chapters"] .browse-col[data-col="chapters"],
  .browse-panel[data-step="verses"] .browse-col[data-col="verses"] {
    display: flex;
  }

  .browse-col .nav-list {
    flex: 1;
    min-height: 0;
    overscroll-behavior: contain;
  }

  .nav-item {
    min-height: 3rem;
    font-size: 1.02rem;
    line-height: 1.35;
    padding: 0.7rem 0.75rem;
  }

  .nav-item strong {
    margin-right: 0.35rem;
  }

  .nav-list--grid {
    grid-template-columns: repeat(auto-fill, minmax(4rem, 1fr));
    gap: 8px;
    align-content: start;
  }

  .nav-item--grid {
    min-height: 3.25rem;
    border: 1px solid var(--border);
  }
}

/* ---------- Phone in landscape: controls become a side rail ----------
   The screen is very short, so Prev/Blank/Next move beside the verse
   instead of under it, giving the verse the full height. */

@media (max-height: 500px) and (orientation: landscape) {
  .app__header {
    padding-top: 0.3rem;
    padding-bottom: 0.3rem;
  }

  .app__display {
    flex-direction: row;
  }

  .display-panel {
    flex: 1;
    min-width: 0;
  }

  .controls {
    flex-direction: column;
    width: calc(7rem + env(safe-area-inset-right));
    padding: 0.5rem calc(0.5rem + env(safe-area-inset-right)) 0.5rem 0.5rem;
    border-top: none;
    border-left: 1px solid var(--border);
    justify-content: stretch;
  }

  .controls button {
    min-height: 0;
    padding: 0.4rem;
  }

  #prev-btn, #next-btn { flex: 1 1 0; }
  #blank-btn { flex: 0 0 auto; min-height: 2.75rem; }
}

/* ---------- Upload modal on small screens ---------- */

@media (max-width: 600px), (max-height: 500px) {
  .modal {
    max-height: calc(100dvh - 1.5rem);
    overflow-y: auto;
    padding: 1.25rem;
    max-width: calc(100vw - 1.5rem);
  }

  .modal__actions .btn {
    flex: 1;
    min-height: 2.75rem;
  }
}
