/* ---------------------------------------------------------------------------
   Gurukul Photo Booth
   Built for one-handed use on a phone at a busy event: big targets, high
   contrast, no hover-only affordances.
--------------------------------------------------------------------------- */

:root {
  --navy:       #1a2b4a;
  --navy-light: #2d4470;
  --gold:       #c9a227;
  --gold-soft:  #f5e9c4;

  --bg:      #f4f6fa;
  --card:    #ffffff;
  --text:    #1a2b4a;
  --muted:   #6b7a90;
  --border:  #e2e7f0;
  --danger:  #c0392b;
  --success: #1e8449;

  --radius: 14px;
  --shadow: 0 2px 12px rgba(26, 43, 74, 0.08);
  --shadow-lg: 0 8px 32px rgba(26, 43, 74, 0.16);
}

* { box-sizing: border-box; }

/* A display value on a class beats the browser default [hidden] rule, so
   hidden overlays would still paint. This restores it for every element. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0 0 4px; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

.muted  { color: var(--muted); font-size: 0.9rem; }
.small  { font-size: 0.8rem; }
.center { text-align: center; }
.break  { word-break: break-all; }
.error  { color: var(--danger); font-size: 0.9rem; margin: 8px 0 0; }

code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

/* ------------------------------- Top bar ------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--navy);
  color: #fff;
  box-shadow: var(--shadow);
}

.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand-icon { margin-right: 4px; }

.tabs { display: flex; gap: 4px; margin-left: auto; }

.tab {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover  { color: #fff; background: rgba(255, 255, 255, 0.1); }
.tab.active { color: var(--navy); background: var(--gold); font-weight: 600; }

/* -------------------------------- Layout -------------------------------- */
main {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.view { display: none; }
.view.active { display: block; animation: fade 0.25s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.step {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }

.step-num {
  flex: 0 0 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

/* ------------------------------ Celebrities ------------------------------ */
.celeb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.celeb-card {
  border: 3px solid transparent;
  border-radius: 12px;
  background: var(--bg);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  font: inherit;
  color: inherit;
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}
.celeb-card:hover { transform: translateY(-2px); }
.celeb-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.celeb-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}
.celeb-card span {
  display: block;
  padding: 8px 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* --------------------------- Celebrity manager --------------------------- */
.celeb-manage { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.celeb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border-radius: 10px;
  padding: 8px 12px;
}
.celeb-row img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 auto;
}
.celeb-row span { flex: 1; font-weight: 600; font-size: 0.92rem; }

/* -------------------------------- Camera -------------------------------- */
.camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0d1626;
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.camera-wrap video,
.camera-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Mirror the live preview so it feels like a mirror; the capture un-mirrors. */
.camera-wrap video { transform: scaleX(-1); }

.camera-placeholder { color: rgba(255, 255, 255, 0.5); text-align: center; }
.camera-placeholder p:first-child { font-size: 2.5rem; margin: 0; }

.camera-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
}

/* -------------------------------- Buttons -------------------------------- */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 20px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
  display: inline-block;
  text-align: center;
}
.btn:hover:not(:disabled) { filter: brightness(1.07); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--navy); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-danger { color: var(--danger); border-color: #f0d0cc; }

.btn-lg    { padding: 15px 28px; font-size: 1.05rem; }
.btn-sm    { padding: 7px 12px; font-size: 0.82rem; }
.btn-block { display: block; width: 100%; }

.topbar .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, 0.3); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

/* -------------------------------- Result -------------------------------- */
.result-wrap {
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  margin-bottom: 16px;
}
.result-wrap img { width: 100%; display: block; }

.result-actions { display: flex; flex-direction: column; gap: 8px; }

/* -------------------------------- Forms -------------------------------- */
label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

input, select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.cost-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--gold-soft);
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 18px;
  font-size: 0.95rem;
}
.cost-box strong { font-size: 1.3rem; color: var(--navy); }

/* -------------------------------- Login -------------------------------- */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, var(--navy), var(--navy-light));
  padding: 20px;
}

.login-card {
  background: var(--card);
  padding: 36px 28px;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card label { text-align: left; }
.login-card .btn { margin-top: 22px; }
.login-logo { font-size: 2.6rem; margin-bottom: 6px; }

/* -------------------------------- History -------------------------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  background: var(--card);
  border-radius: 12px;
  padding: 16px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat strong { display: block; font-size: 1.5rem; color: var(--navy); }
.stat span   { font-size: 0.78rem; color: var(--muted); }

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.history-card {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.history-card img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

.history-meta { padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.history-actions { display: flex; gap: 6px; margin-top: 8px; }
.history-actions .btn { flex: 1; }

.badge {
  align-self: flex-start;
  background: var(--bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-top: 2px;
}
.badge-paid { background: #d8f0e0; color: var(--success); }

/* -------------------------------- Modal -------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(13, 22, 38, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  position: relative;
  background: var(--card);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: 0;
  background: transparent;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.modal-img { width: 100%; border-radius: 10px; display: block; }

.qr-box { text-align: center; margin: 16px 0; }
.qr-box img {
  width: 100%;
  max-width: 260px;
  border: 8px solid #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.qr-amount {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--navy);
  margin: 12px 0 0;
}

/* ------------------------------ Loading ------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(26, 43, 74, 0.93);
  color: #fff;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 20px;
}
.overlay .muted { color: rgba(255, 255, 255, 0.62); }

.spinner {
  width: 46px;
  height: 46px;
  border: 4px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------- Toast -------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 400;
  background: var(--navy);
  color: #fff;
  padding: 13px 22px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  text-align: center;
}
.toast-error { background: var(--danger); }

/* ------------------------------ Responsive ------------------------------ */
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 10px 12px; }
  .brand { font-size: 0.95rem; }
  .tabs { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
  .tab { flex: 1; padding: 9px 6px; font-size: 0.82rem; }
  main { padding: 14px 12px 48px; }
  .step { padding: 16px; }
  .celeb-grid { grid-template-columns: repeat(2, 1fr); }
  .history-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
