:root {
  /* Accent gets overwritten at runtime from the /color API endpoint */
  --accent: #4f8cff;
  --accent-2: #9f6bff;
  --accent-soft: rgba(79, 140, 255, 0.16);
  --bg-0: #0a0b14;
  --bg-1: #12131f;
  --ink: #eef1ff;
  --ink-dim: #a2a7c4;
  --card-glass: rgba(255, 255, 255, 0.06);
  --stroke: rgba(255, 255, 255, 0.12);
  --radius: 24px;
  --shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--accent-soft), transparent 60%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
  overflow-x: hidden;
  transition: background 0.8s ease;
}

/* ---------- Background orbs ---------- */
.bg-orbs { position: fixed; inset: 0; z-index: 0; pointer-events: none; filter: blur(60px); }
.orb { position: absolute; border-radius: 50%; opacity: 0.55; mix-blend-mode: screen; animation: float 18s ease-in-out infinite; }
.orb-1 { width: 380px; height: 380px; background: var(--accent);   top: -80px;  left: -60px; }
.orb-2 { width: 320px; height: 320px; background: var(--accent-2); bottom: -60px; right: -40px; animation-delay: -6s; }
.orb-3 { width: 240px; height: 240px; background: #2be9c6; top: 40%; left: 60%; animation-delay: -11s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.08); }
  66% { transform: translate(-30px, 25px) scale(0.95); }
}

/* ---------- Layout ---------- */
.stage {
  position: relative; z-index: 1;
  max-width: 520px; margin: 0 auto; padding: 28px 20px 40px;
  min-height: 100vh; display: flex; flex-direction: column;
}
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 34px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.3px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 16px var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--card-glass); border: 1px solid var(--stroke); color: var(--ink-dim);
}
.pill-dot { width: 8px; height: 8px; border-radius: 50%; background: #f5a623; }
.pill[data-state="loading"] .pill-dot { animation: blink 1s infinite; }
.pill[data-state="ok"]    { color: #9ff5c6; } .pill[data-state="ok"]    .pill-dot { background: #34e39a; animation: none; }
.pill[data-state="error"] { color: #ffb3b3; } .pill[data-state="error"] .pill-dot { background: #ff5d5d; animation: none; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- Card ---------- */
.card-wrap { perspective: 1400px; display: flex; justify-content: center; }
.card {
  position: relative; width: 100%; max-width: 440px; height: 500px;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}
.card.flipped { transform: rotateY(180deg); }

.face {
  position: absolute; inset: 0; border-radius: var(--radius);
  backface-visibility: hidden; overflow: hidden;
  padding: 26px; display: flex; flex-direction: column;
  background:
    linear-gradient(155deg, rgba(255,255,255,0.10), rgba(255,255,255,0.02)),
    var(--bg-1);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.15);
}
.back { transform: rotateY(180deg); }

/* Holographic sheen sweep */
.holo-sheen {
  position: absolute; inset: -40% -10%;
  background: linear-gradient(115deg, transparent 30%, var(--accent-soft) 45%, rgba(255,255,255,0.22) 50%, var(--accent-soft) 55%, transparent 70%);
  transform: translateX(-30%); opacity: 0; transition: opacity 0.4s;
  pointer-events: none; mix-blend-mode: screen;
}
.card-wrap:hover .holo-sheen { opacity: 1; animation: sweep 2.6s ease-in-out infinite; }
@keyframes sweep { 0% { transform: translateX(-40%); } 100% { transform: translateX(40%); } }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; }
.uni-name { font-size: 15px; font-weight: 700; color: var(--ink); max-width: 70%; line-height: 1.3; }
.chip {
  width: 46px; height: 34px; border-radius: 7px;
  background: linear-gradient(135deg, #ffe6a3, #cfa14a 55%, #b9832f);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
  position: relative;
}
.chip::after {
  content: ""; position: absolute; inset: 6px;
  background-image: linear-gradient(rgba(0,0,0,0.35) 1px, transparent 1px), linear-gradient(90deg, rgba(0,0,0,0.35) 1px, transparent 1px);
  background-size: 8px 8px; border-radius: 3px;
}

/* Identity */
.identity { display: flex; align-items: center; gap: 18px; margin-top: 34px; }
.avatar {
  width: 96px; height: 96px; border-radius: 22px; flex-shrink: 0;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-size: 40px; font-weight: 800; color: #fff;
  box-shadow: 0 12px 30px -10px var(--accent), inset 0 0 0 2px rgba(255,255,255,0.25);
  letter-spacing: 1px;
}
.identity-text { display: flex; flex-direction: column; gap: 3px; }
.label { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--ink-dim); }
.name { font-size: 30px; font-weight: 800; line-height: 1.05; text-transform: capitalize; }
.student-id { font-size: 13px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

/* Stats */
.stats {
  margin-top: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  padding: 16px 0 20px; border-top: 1px solid var(--stroke);
}
.stat { text-align: center; }
.stat-val { display: block; font-size: 24px; font-weight: 800; color: var(--accent); text-transform: capitalize; }
.stat-food { font-size: 20px; }
.stat-key { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-dim); }

/* Buttons */
.flip-btn {
  align-self: center; display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: 999px; border: none; cursor: pointer;
  font-size: 14px; font-weight: 700; color: #0a0b14;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px -8px var(--accent);
  transition: transform 0.15s, box-shadow 0.15s;
}
.flip-btn:hover { transform: translateY(-2px); box-shadow: 0 16px 30px -10px var(--accent); }
.flip-btn:active { transform: translateY(0); }
.flip-btn.ghost {
  background: transparent; color: var(--ink);
  border: 1px solid var(--stroke); box-shadow: none;
}

/* Back face */
.back-title { font-size: 18px; margin-bottom: 4px; }
.detail-list { list-style: none; margin: 18px 0; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.detail-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 4px; border-bottom: 1px solid rgba(255,255,255,0.07);
}
.d-key { color: var(--ink-dim); font-size: 13.5px; font-weight: 600; }
.d-val { font-size: 14px; font-weight: 700; text-align: right; word-break: break-word; }

.barcode { height: 46px; margin: 6px 0 18px; display: flex; gap: 2px; align-items: stretch; opacity: 0.85; }
.barcode span { flex: 1; background: var(--ink); border-radius: 1px; }

/* ---------- Error ---------- */
.error-panel {
  margin: 30px auto 0; max-width: 440px; width: 100%; text-align: center;
  padding: 28px; border-radius: var(--radius);
  background: var(--card-glass); border: 1px solid var(--stroke);
}
.error-title { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.error-sub { color: var(--ink-dim); font-size: 14px; margin-bottom: 14px; }
.error-cmd {
  display: inline-block; padding: 8px 14px; border-radius: 8px;
  background: #000; color: #6ef0b0; font-family: ui-monospace, monospace; font-size: 13px; margin-bottom: 18px;
}
.retry-btn {
  display: block; margin: 0 auto; padding: 11px 26px; border-radius: 999px; border: none; cursor: pointer;
  font-weight: 700; color: #0a0b14; background: linear-gradient(120deg, var(--accent), var(--accent-2));
}

/* ---------- Footer ---------- */
.footer { margin-top: auto; padding-top: 26px; text-align: center; font-size: 12px; color: var(--ink-dim); }
.footer .sep { margin: 0 8px; opacity: 0.5; }

/* ---------- Loading skeleton state ---------- */
.card.loading .name,
.card.loading .stat-val,
.card.loading .uni-name,
.card.loading .student-id {
  color: transparent; border-radius: 6px;
  background: linear-gradient(90deg, rgba(255,255,255,0.06), rgba(255,255,255,0.16), rgba(255,255,255,0.06));
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
.card.loading .avatar { animation: shimmer 1.3s infinite; background-size: 200% 100%;
  background-image: linear-gradient(90deg, rgba(255,255,255,0.06), rgba(255,255,255,0.16), rgba(255,255,255,0.06)); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Reveal animation once data arrives */
.card.revealed .identity,
.card.revealed .stats,
.card.revealed .card-head { animation: rise 0.6s cubic-bezier(0.16,1,0.3,1) backwards; }
.card.revealed .stats { animation-delay: 0.08s; }
.card.revealed .flip-btn { animation: rise 0.6s cubic-bezier(0.16,1,0.3,1) 0.16s backwards; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 480px) {
  .card { height: 470px; }
  .name { font-size: 26px; }
  .avatar { width: 82px; height: 82px; font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
