/* BNB Comp Engine — Live (public mobile competitor view)
 * Static, mobile-first, dark. No build step, no framework. Mirrors the
 * gated app's Display in feel (dark surface, orange brand accent) but is a
 * completely separate, un-gated deploy — see README.md.
 */

:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --surface: #151515;
  --surface-raised: #1e1e1e;
  --border: #2a2a2a;
  --text: #f5f5f5;
  --text-dim: rgba(245, 245, 245, 0.65);
  --text-faint: rgba(245, 245, 245, 0.4);
  --brand: #f97316;
  --brand-dim: rgba(249, 115, 22, 0.15);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.18);
  --error: #ef4444;
  --error-dim: rgba(239, 68, 68, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

/* `app.js` shows/hides screens, the nav drawer, and the nav backdrop purely
 * via the HTML `hidden` attribute. Several rules below set an explicit
 * `display` on those same elements, and a class/id selector beats the
 * browser's low-specificity UA rule `[hidden] { display: none }` — so those
 * elements stayed visibly rendered even while `hidden` (this was the "nav
 * drawer permanently covers the content on mobile" bug). Make `hidden`
 * authoritative for every element in the app. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  min-height: 100dvh;
  width: 100%;
}

/* ---------------- Entry screen ---------------- */

#screen-entry {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(249, 115, 22, 0.08), transparent 60%),
    var(--bg);
}

.entry-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.brand-eyebrow {
  margin: 0 0 4px;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.brand-title {
  margin: 0 0 16px;
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--brand);
}

.entry-sub {
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.4;
}

#code-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#code-input {
  width: 100%;
  padding: 18px 12px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-align: center;
  text-indent: 0.5em; /* visually re-center against the trailing letter-spacing gap */
}

#code-input:focus {
  outline: none;
  border-color: var(--brand);
}

.btn-primary {
  padding: 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--brand);
  color: #10100f;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary:active {
  opacity: 0.85;
}

.error-text {
  margin: 4px 0 0;
  color: var(--error);
  font-size: 0.9rem;
}

/* ---------------- Loading screen ---------------- */

#screen-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  color: var(--text-dim);
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}

/* ---------------- App shell ---------------- */

#screen-app {
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 10px
    calc(8px + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 999px;
}

.icon-btn:active {
  background: var(--surface-raised);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.header-title {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.comp-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view-label {
  margin: 0;
  font-size: 0.72rem;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ---------------- Nav drawer ---------------- */

.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.55);
  /* `.nav-backdrop` is only ever in the DOM's rendered state (not display:none)
   * while `hidden` has just been removed, so this animation replays as a fade-in
   * every time the drawer opens; [hidden] above takes it fully out of the box
   * again on close, so there is never leftover space or an interactive backdrop
   * behind it. */
  animation: nav-backdrop-in 0.18s ease-out;
}

.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 30;
  width: min(78vw, 300px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: calc(20px + env(safe-area-inset-top)) 10px 20px
    calc(10px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: nav-drawer-in 0.22s ease-out;
}

@keyframes nav-backdrop-in {
  from {
    opacity: 0;
  }
}

@keyframes nav-drawer-in {
  from {
    transform: translateX(-100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .nav-backdrop,
  .nav-drawer {
    animation: none;
  }
}

.nav-item {
  text-align: left;
  padding: 14px 16px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-item.active {
  background: var(--brand-dim);
  color: var(--brand);
}

/* ---------------- Views ---------------- */

.view-container {
  flex: 1;
  padding: 16px 14px calc(40px + env(safe-area-inset-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.event-name {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--brand);
}

.division-name {
  margin: 2px 0 0;
  font-size: 0.95rem;
  color: var(--text-dim);
}

.status-pill {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: var(--brand-dim);
  color: var(--brand);
}

/* Current lifter(s) */

.lifters-row {
  display: flex;
  gap: 10px;
}

.lifters-row.single {
  justify-content: center;
}

.lifter-card {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.lifter-name {
  margin: 0 0 2px;
  font-size: 1.15rem;
  font-weight: 700;
  overflow-wrap: break-word;
}

.lifter-bib {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: var(--text-faint);
}

.lifter-weight {
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

.lifter-weight .unit {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: 2px;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}

.result-badge.good {
  background: var(--success-dim);
  color: var(--success);
}

.result-badge.nolift {
  background: var(--error-dim);
  color: var(--error);
}

.result-badge svg {
  width: 16px;
  height: 16px;
}

.result-badge.pending {
  background: transparent;
  color: var(--text-faint);
}

/* Up next */

.next-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.next-name {
  font-weight: 700;
}

.next-weight {
  font-weight: 800;
  color: var(--brand);
}

/* Timer */

.timer-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.timer-value {
  font-variant-numeric: tabular-nums;
  font-size: 1.4rem;
  font-weight: 700;
}

.timer-value.running {
  color: var(--brand);
}

.timer-value.urgent {
  color: var(--error);
}

/* Tables (standings / order of go) */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

table.data-table th,
table.data-table td {
  padding: 9px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

table.data-table th {
  color: var(--text-faint);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

table.data-table td.name-cell {
  text-align: left;
  font-weight: 600;
}

table.data-table tr.current-row td {
  background: var(--brand-dim);
}

.rank-1 {
  color: #f5c542;
  font-weight: 800;
}

.rank-2 {
  color: #cfcfcf;
  font-weight: 800;
}

.rank-3 {
  color: #d08a52;
  font-weight: 800;
}

.section-heading {
  margin: 0 0 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 12px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.order-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.order-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
}

.order-list li.current-row {
  background: var(--brand-dim);
  border-radius: var(--radius-sm);
}

.order-idx {
  flex-shrink: 0;
  width: 22px;
  color: var(--text-faint);
  font-size: 0.8rem;
  text-align: right;
}

.order-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-weight {
  flex-shrink: 0;
  color: var(--brand);
  font-weight: 700;
  font-size: 0.9rem;
}

/* Small helpers */

.text-center {
  text-align: center;
}

.mt-8 {
  margin-top: 8px;
}

/* ---------------- Narrow-phone tightening ---------------- */
/* Keeps the two-up lifters row, data tables, and order list from crowding or
 * overflowing horizontally on small phones (~360px and below). */

@media (max-width: 380px) {
  .view-container {
    padding-left: 10px;
    padding-right: 10px;
  }

  .lifters-row {
    gap: 8px;
  }

  .lifter-card {
    padding: 12px 8px;
  }

  .lifter-weight {
    font-size: 1.8rem;
  }

  table.data-table {
    font-size: 0.84rem;
  }

  table.data-table th,
  table.data-table td {
    padding: 8px 4px;
  }
}
