/* ==========================================================================
   Rep Odyssey — Phase 1 shell.
   Dark, portrait-only, with carved stone/wood framing and gold accents.
   ========================================================================== */

@font-face {
  font-family: 'Cinzel';
  src: url('../fonts/cinzel-600.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Cinzel';
  src: url('../fonts/cinzel-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #0d0b12;
  --ink-2: #16121e;
  --panel: #1d1827;
  --panel-2: #241e30;
  --edge: #3a3048;
  --edge-lit: #5b4a6e;
  --text: #ece6f5;
  --text-dim: #a89cc0;
  --gold: #ffd88a;
  --gold-deep: #c99a3c;
  --up: #7ec0ff;
  --down: #ffbe5a;
  --good: #7fd9a2;
  --bad: #ff8878;

  --r: 12px;
  --pad: 16px;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* Class rules like `.screen { display: flex }` outrank the UA's `[hidden]`
   rule, so hiding anything with the attribute needs this to actually stick. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(120% 60% at 50% 0%, #241c33 0%, transparent 70%),
    linear-gradient(180deg, var(--ink-2), var(--ink));
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

h1,
h2,
.counter-number,
.cal-step {
  font-family: 'Cinzel', 'Trajan Pro', Georgia, serif;
  letter-spacing: 0.02em;
}

.frame {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* ---------- top bar ---------- */

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: 10px var(--pad);
  border-bottom: 1px solid var(--edge);
  background: linear-gradient(180deg, rgba(255, 216, 138, 0.06), transparent);
}

/* Pinned to their columns: a `hidden` child leaves its grid cell entirely,
   which would otherwise shuffle the title into the 44px back-button slot. */
#btnBack {
  grid-column: 1;
}
.brand {
  grid-column: 2;
}
#btnSettings {
  grid-column: 3;
}

.brand {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  text-align: center;
  color: var(--gold);
  text-shadow: 0 1px 0 #000;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--edge);
  border-radius: var(--r);
  background: var(--panel);
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active {
  background: var(--panel-2);
}

/* ---------- screens ---------- */

.screens {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: var(--pad);
  padding-bottom: 32px;
}

.section-title {
  margin: 10px 0 -4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

.status {
  margin: 0;
  min-height: 22px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}
.status--warn {
  color: var(--down);
}
.status--bad {
  color: var(--bad);
}
.status--good {
  color: var(--good);
}

/* ---------- rep counter ---------- */

.counter {
  position: relative;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 22px 16px 18px;
  border: 1px solid var(--edge);
  border-radius: var(--r);
  background:
    radial-gradient(90% 120% at 50% 0%, rgba(255, 216, 138, 0.09), transparent 65%),
    linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 8px 24px rgba(0, 0, 0, 0.45);
}

.counter-number {
  font-size: clamp(64px, 22vw, 108px);
  font-weight: 700;
  line-height: 1;
  color: var(--gold);
  text-shadow:
    0 2px 0 #000,
    0 0 28px rgba(255, 216, 138, 0.28);
  font-variant-numeric: tabular-nums;
  transition: transform 90ms ease-out;
}
.counter-number.pulse {
  transform: scale(1.12);
}

.counter-label {
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ---------- depth meter ---------- */

.depth-track {
  position: relative;
  height: 16px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--ink-2);
  overflow: hidden;
}

.depth-zone {
  position: absolute;
  top: 0;
  bottom: 0;
}
.depth-zone--up {
  left: 0;
  background: rgba(126, 192, 255, 0.14);
}
.depth-zone--down {
  right: 0;
  background: rgba(255, 190, 90, 0.16);
}

.depth-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--up), var(--gold));
  transition: width 60ms linear;
}

.depth-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ---------- chips ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  padding: 5px 10px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.chip--warn {
  border-color: rgba(255, 190, 90, 0.4);
  color: var(--down);
}
.chip--good {
  border-color: rgba(127, 217, 162, 0.4);
  color: var(--good);
}
.chip--bad {
  border-color: rgba(255, 136, 120, 0.45);
  color: var(--bad);
}

/* ---------- plank gate chips ---------- */

.gates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 6px;
}

.gate {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.2;
}

.gate::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--edge-lit);
}

.gate[data-state='pass'] {
  border-color: rgba(127, 217, 162, 0.45);
  color: var(--good);
}
.gate[data-state='pass']::before {
  background: var(--good);
  box-shadow: 0 0 7px rgba(127, 217, 162, 0.7);
}

.gate[data-state='fail'] {
  border-color: rgba(255, 136, 120, 0.45);
  color: var(--bad);
}
.gate[data-state='fail']::before {
  background: var(--bad);
  box-shadow: 0 0 7px rgba(255, 136, 120, 0.7);
}

.reject {
  margin: -4px 0 0;
  min-height: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--down);
}

/* ---------- debug panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--edge);
  border-radius: var(--r);
  background: var(--panel);
}

.preview {
  position: relative;
  aspect-ratio: 3 / 4;
  max-height: 46svh;
  margin: 0 auto;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

.preview video,
.preview canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Front camera: mirror both layers together so the points sit on the body. */
  transform: scaleX(-1);
}

.preview-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 11px;
  color: var(--bad);
}
.preview-badge[data-ok='1'] {
  color: var(--good);
}

.graph {
  width: 100%;
  height: 110px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--ink-2);
}

.readouts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
  font-size: 11px;
  color: var(--text-dim);
}
.readouts b {
  display: block;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---------- buttons ---------- */

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.actions--tight {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

.btn {
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--edge-lit);
  border-radius: var(--r);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.btn:active {
  transform: translateY(1px);
  background: var(--panel);
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn--primary {
  border-color: var(--gold-deep);
  background: linear-gradient(180deg, #3a2d18, #271d10);
  color: var(--gold);
}
.btn--ghost {
  background: transparent;
  color: var(--text-dim);
  font-weight: 500;
}
.btn--danger {
  border-color: rgba(255, 136, 120, 0.5);
  color: var(--bad);
}

/* ---------- dev tools ---------- */

.dev {
  border: 1px dashed var(--edge);
  border-radius: var(--r);
  padding: 10px 12px;
}
.dev summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
}
.dev-hint {
  margin: 8px 0;
  font-size: 12px;
  color: var(--text-dim);
}
kbd {
  padding: 1px 6px;
  border: 1px solid var(--edge-lit);
  border-radius: 5px;
  background: var(--ink-2);
  font-size: 11px;
}

/* ---------- settings ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.field label {
  font-size: 13px;
  color: var(--text-dim);
}

select,
input[type='range'] {
  width: 100%;
  min-height: 44px;
  padding: 10px;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
}
input[type='range'] {
  padding: 0;
  accent-color: var(--gold);
}

.switch {
  width: 52px;
  height: 30px;
  accent-color: var(--gold);
}

.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}
.version {
  margin-top: 18px;
  text-align: center;
  opacity: 0.6;
}

/* ---------- calibration overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--pad);
  background: rgba(8, 6, 12, 0.94);
}

.cal-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(100%, 420px);
  text-align: center;
}

.cal-preview {
  aspect-ratio: 3 / 4;
  max-height: 44svh;
  border: 1px solid var(--edge);
  border-radius: var(--r);
  overflow: hidden;
  background: #000;
}
.cal-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.cal-step {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-deep);
}
.cal-message {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.cal-progress {
  height: 10px;
  border: 1px solid var(--edge);
  border-radius: 999px;
  background: var(--ink-2);
  overflow: hidden;
}
.cal-hint {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(255, 190, 90, 0.4);
  border-radius: var(--r);
  background: rgba(255, 190, 90, 0.08);
  color: var(--down);
  font-size: 13px;
  line-height: 1.45;
}

.cal-progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  transition: width 80ms linear;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(90vw, 460px);
  padding: 12px 16px;
  border: 1px solid var(--edge-lit);
  border-radius: var(--r);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast--bad {
  border-color: rgba(255, 136, 120, 0.6);
  color: var(--bad);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
