/* tagAR prototype - calm, high contrast, large touch targets.
   Design rule: the child-facing screen shows one thing at a time. */

:root {
  --bg: #1c2733;
  --panel: #24313f;
  --panel-2: #2c3b4b;
  --ink: #f2f6fa;
  --ink-dim: #a7b6c6;
  --accent: #4da3ff;
  --success: #46c07a;
  --danger: #e2635b;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* The `hidden` attribute hides elements via `display: none` in the browser's default
   stylesheet, which ANY class rule setting `display` will beat. Several panels here are
   flex layouts, so without this they stay visible however often you set hidden - which
   is exactly what happened: the "no words yet" panel sat on top of a full vocabulary. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 18px;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }
.screen.scrollable { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(40px + var(--safe-bottom)); }

/* ---------- Home ---------- */
.home-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}
.wordmark { font-size: 56px; margin: 0; letter-spacing: -1.5px; font-weight: 700; }
.wordmark::first-letter { color: var(--accent); }
.tagline { color: var(--ink-dim); margin: 0 0 28px; font-size: 19px; }
.home-buttons { display: flex; flex-direction: column; gap: 16px; width: min(420px, 100%); }
.child-count { color: var(--ink-dim); font-size: 15px; margin-top: 18px; }
.build { color: #55677a; font-size: 12px; margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.build.stale { color: var(--accent); }

.big-button {
  appearance: none;
  border: 1px solid #3a4b5e;
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease;
}
.big-button:active { transform: scale(.985); }
.big-button.primary { background: var(--accent); border-color: var(--accent); color: #0d1a26; }
.bb-title { font-size: 26px; font-weight: 650; }
.bb-sub { font-size: 15px; opacity: .72; }

/* ---------- Bars, buttons ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: rgba(28,39,51,.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #33445a;
}
.bar h2 { font-size: 19px; margin: 0; font-weight: 600; }

.icon-button {
  appearance: none;
  border: 1px solid #41546a;
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 11px 18px;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  min-height: 46px;
}
.icon-button.accent { background: var(--accent); border-color: var(--accent); color: #0d1a26; font-weight: 600; }

.pill {
  appearance: none;
  border: 1px solid #41546a;
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 13px 22px;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  min-height: 48px;
}
.pill.success { background: var(--success); border-color: var(--success); color: #06240f; font-weight: 600; }
.pill.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.pill.wide { width: 100%; margin-top: 10px; }
.pill:disabled { opacity: .4; }
.tool-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }

/* ---------- Camera screens ---------- */
video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.explore-overlay, .capture-overlay { position: absolute; inset: 0; pointer-events: none; }
.explore-overlay > *, .capture-overlay > * { pointer-events: auto; }

.top-left  { position: absolute; top: calc(14px + var(--safe-top)); left: 14px; }
.top-right { position: absolute; top: calc(14px + var(--safe-top)); right: 14px; }

/* Adult information on a child's screen - present but quiet. */
.word-count {
  position: absolute;
  top: calc(26px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12,18,25,.6);
  color: #cbd7e3;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

/* The one big label - deliberately the only thing on screen */
.label-card {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -54%);
  background: rgba(255,255,255,.96);
  color: #16202b;
  border-radius: 28px;
  padding: 24px 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  animation: pop .22s ease-out;
  max-width: 78vw;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%,-50%) scale(.9); } }
.label-symbol { width: min(230px, 46vw); height: min(230px, 46vw); object-fit: contain; }
.label-word { font-size: clamp(38px, 8vw, 66px); font-weight: 700; letter-spacing: -1px; }

/* Find mode */
.find-prompt {
  position: absolute;
  top: calc(78px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,.96);
  color: #16202b;
  border-radius: 24px;
  padding: 18px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 16px 44px rgba(0,0,0,.4);
  max-width: 80vw;
}
.find-lead { font-size: 17px; color: #56687c; }
.find-symbol { width: 132px; height: 132px; object-fit: contain; }
.find-word { font-size: 34px; font-weight: 700; }
.find-actions { display: flex; gap: 10px; margin-top: 6px; }

/* Recognition */
.recognise-btn {
  position: absolute;
  bottom: calc(150px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12,18,25,.82);
  backdrop-filter: blur(10px);
  white-space: nowrap;
}
.recognise-status {
  position: absolute;
  bottom: calc(150px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12,18,25,.82);
  backdrop-filter: blur(10px);
  color: #cbd7e3;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 88vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recognise-status.working::after {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  margin-left: 8px;
  border: 2px solid #4da3ff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Vocabulary strip */
.strip {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  display: flex;
  gap: 12px;
  padding: 14px 14px calc(14px + var(--safe-bottom));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(to top, rgba(12,18,25,.88), rgba(12,18,25,0));
}
.strip::-webkit-scrollbar { display: none; }
.vocab-chip {
  flex: 0 0 auto;
  width: 104px;
  background: rgba(255,255,255,.94);
  color: #16202b;
  border: none;
  border-radius: 16px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font: inherit;
  cursor: pointer;
}
.vocab-chip:active { transform: scale(.96); }
.vocab-chip img { width: 68px; height: 68px; object-fit: contain; }
.vocab-chip span { font-size: 15px; font-weight: 600; text-align: center; }

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  padding: 24px;
}

/* ---------- Capture ---------- */
.capture-guide {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  pointer-events: none;
}
.reticle {
  width: min(62vw, 320px);
  aspect-ratio: 1;
  border: 3px dashed rgba(255,255,255,.75);
  border-radius: 26px;
}
#capture-hint {
  background: rgba(12,18,25,.72);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 16px;
  margin: 0;
  text-align: center;
  max-width: 80vw;
}
.capture-bottom {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(26px + var(--safe-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
}
.shutter {
  width: 82px; height: 82px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255,255,255,.45);
  background-clip: padding-box;
  cursor: pointer;
}
.shutter:active { transform: scale(.93); }
.shot-tally {
  min-width: 54px;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  background: rgba(12,18,25,.72);
  padding: 10px 14px;
  border-radius: 999px;
}

/* ---------- Library ---------- */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 16px;
}
.lib-card {
  background: var(--panel);
  border: 1px solid #3a4b5e;
  border-radius: var(--radius);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}
.lib-card img { width: 84px; height: 84px; object-fit: contain; }
.lib-card .lc-word { font-size: 19px; font-weight: 650; }
.lib-card .lc-meta { font-size: 13px; color: var(--ink-dim); }
.lib-card .placeholder { width: 84px; height: 84px; display: grid; place-items: center; color: var(--ink-dim); font-size: 13px; border: 1px dashed #46596e; border-radius: 12px; }

.attribution a { color: var(--accent); }
.library-tools { padding: 8px 16px 30px; border-top: 1px solid #33445a; margin-top: 12px; }
.library-tools.top { border-top: none; margin-top: 0; padding-top: 14px; padding-bottom: 6px; }
.library-tools h3 { font-size: 17px; margin: 16px 0 6px; }
.library-tools.top h3 { margin-top: 0; }

.section-heading {
  font-size: 17px;
  margin: 20px 16px 0;
  padding-top: 16px;
  border-top: 1px solid #33445a;
}

.packs { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.pill.pack { text-align: left; }
.pill.pack.done { opacity: .55; border-style: dashed; }

/* ---------- Forms ---------- */
.form { padding: 18px 16px 40px; display: flex; flex-direction: column; gap: 26px; }
.field { display: flex; flex-direction: column; }
.field-label { font-size: 17px; font-weight: 650; margin-bottom: 6px; }
.hint { color: var(--ink-dim); font-size: 14.5px; line-height: 1.45; margin: 0 0 8px; }
input[type=text] {
  appearance: none;
  background: var(--panel);
  border: 1px solid #41546a;
  color: var(--ink);
  border-radius: 14px;
  padding: 15px 16px;
  font: inherit;
  font-size: 19px;
  width: 100%;
  -webkit-user-select: text;
  user-select: text;
}
input[type=text]:focus { outline: 2px solid var(--accent); border-color: transparent; }

.symbol-preview {
  width: 140px; height: 140px;
  background: #fff;
  border-radius: 16px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.symbol-preview img { width: 100%; height: 100%; object-fit: contain; }
.symbol-preview .placeholder { color: #7b8a99; font-size: 14px; text-align: center; padding: 8px; }

.symbol-results { display: flex; gap: 10px; overflow-x: auto; padding: 12px 0 4px; }
.symbol-results img {
  flex: 0 0 auto;
  width: 92px; height: 92px;
  background: #fff;
  border-radius: 12px;
  object-fit: contain;
  padding: 6px;
  border: 3px solid transparent;
  cursor: pointer;
}
.symbol-results img.chosen { border-color: var(--accent); }

.tier-choice { display: flex; flex-direction: column; gap: 10px; margin: 4px 0 14px; }
.tier {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--panel-2);
  border: 1px solid #41546a;
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
}
.tier:has(input:checked) { border-color: var(--accent); background: #2b3d51; }
.tier input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.tier strong { display: block; font-size: 16.5px; font-weight: 650; }
.tier em { display: block; font-style: normal; font-size: 14px; color: var(--ink-dim); margin-top: 3px; line-height: 1.4; }

.shots { display: flex; gap: 8px; flex-wrap: wrap; }
.shots img { width: 68px; height: 68px; object-fit: cover; border-radius: 10px; }
.rec-state { color: var(--ink-dim); font-size: 15px; }
.rec-state.live { color: var(--danger); font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(12,18,25,.94);
  border: 1px solid #41546a;
  color: var(--ink);
  padding: 14px 22px;
  border-radius: 999px;
  font-size: 16px;
  z-index: 50;
  max-width: 86vw;
  text-align: center;
}
