/*
 * AR Collectible Card - mobile UI
 * Plain CSS, no build step. Mobile portrait first.
 */

:root {
  --bg: #0e0f1a;
  --bg-soft: #171a2b;
  --panel: rgba(18, 20, 34, 0.86);
  --text: #f5f6fa;
  --text-dim: rgba(245, 246, 250, 0.62);
  --accent: #ffb937;
  --accent-strong: #ff9f1a;
  --ok: #2ecc8f;
  --err: #ff5d6c;
  --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; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/*
 * Background goes on <html> only: MindAR injects the camera <video> with
 * z-index -2, and an opaque <body> background would paint on top of it.
 * The html background becomes the viewport background (painted first).
 */
html { background: var(--bg); }

/* The a-frame canvas + MindAR video stay behind every UI layer. */
a-scene {
  position: fixed !important;
  inset: 0;
  z-index: 1;
}

/* ---------- shared bits ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(28px + var(--safe-bottom));
  text-align: center;
}

.hidden { display: none !important; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0.02em;
}

.spin {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- start overlay ---------- */

#start-screen {
  background:
    radial-gradient(120% 90% at 50% 0%, #262a49 0%, var(--bg) 58%),
    var(--bg);
  z-index: 30;
}

.start-emblem {
  width: 88px;
  height: 88px;
  border-radius: 24px;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 14px 40px rgba(255, 159, 26, 0.28);
}

.start-emblem svg { width: 46px; height: 46px; }

.start-title {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.start-card-name {
  margin: 0 0 30px;
  font-size: 14px;
  color: var(--text-dim);
}

#start-button {
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 17px 58px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  color: #1a1206;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 12px 32px rgba(255, 159, 26, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

#start-button:active { transform: scale(0.96); }
#start-button:disabled { opacity: 0.45; box-shadow: none; cursor: default; }

.start-hint {
  margin-top: 16px;
  max-width: 280px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-dim);
}

/* ---------- error overlay ---------- */

#error-screen {
  background: rgba(10, 11, 19, 0.94);
  z-index: 40;
}

.error-box {
  width: 100%;
  max-width: 330px;
  padding: 26px 24px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.error-icon {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 93, 108, 0.14);
  color: var(--err);
  font-size: 22px;
  font-weight: 700;
}

.error-title { margin: 0 0 8px; font-size: 17px; font-weight: 600; }

.error-detail {
  margin: 0 0 20px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-dim);
  word-break: break-word;
}

#error-retry {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 11px 30px;
  border-radius: 999px;
  cursor: pointer;
}

#error-retry:active { background: rgba(255, 255, 255, 0.08); }

/* ---------- HUD (on top of live camera) ---------- */

#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 20px calc(26px + var(--safe-bottom));
}

#hud-top {
  width: 100%;
  display: flex;
  justify-content: center;
}

#card-name { font-size: 13px; font-weight: 600; }

#hud-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#status-pill { transition: opacity 0.25s ease; }

#status-pill.ok {
  color: #0c2b1e;
  background: var(--ok);
  font-weight: 600;
}

/* scanning hint: reticle + text */
#scan-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  transition: opacity 0.3s ease;
}

.reticle {
  position: relative;
  width: 190px;
  height: 120px;
  opacity: 0.95;
}

.reticle i {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 6px;
}

.reticle i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.reticle i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.reticle i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.reticle i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }

.reticle::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: sweep 1.8s ease-in-out infinite;
}

@keyframes sweep {
  0%, 100% { top: 12%; opacity: 0.4; }
  50% { top: 82%; opacity: 1; }
}

#scan-text {
  font-size: 14px;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.65);
}

/* toast for non-fatal problems (e.g. model load failed) */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%) translateY(8px);
  z-index: 25;
  max-width: 82%;
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(255, 93, 108, 0.35);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
