/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg:             #0a0a0a;
  --surface:        #161616;
  --surface2:       #222222;
  --border:         rgba(255, 255, 255, 0.1);
  --text:           #ffffff;
  --text-muted:     #888888;
  --text-dim:       #444444;

  --accent:         #e94560;
  --accent-hover:   #c73350;

  --c-success:      #00c853;
  --c-vip:          #b8860b;
  --c-warning:      #e65100;
  --c-danger:       #c62828;
  --c-neutral:      #333333;

  --radius:         12px;
  --radius-sm:      8px;
  --radius-lg:      20px;

  --header-h:       56px;
  --safe-top:       env(safe-area-inset-top,    0px);
  --safe-bottom:    env(safe-area-inset-bottom, 0px);

  --ease:           200ms ease;
  --ease-slow:      350ms cubic-bezier(0.32, 0.72, 0, 1);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── Scanner page ───────────────────────────────────────────── */
.scanner-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
  position: absolute;
  top: var(--safe-top);
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
}

.header-logo {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--text);
}

/* ── Camera ─────────────────────────────────────────────────── */
.camera-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#canvas { display: none; }

/* ── Scanner frame ──────────────────────────────────────────── */
.scanner-frame {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scanner-box {
  position: relative;
  width: min(72vw, 72vh, 280px);
  height: min(72vw, 72vh, 280px);
}

.c { position: absolute; width: 22px; height: 22px; border-color: var(--accent); border-style: solid; border-width: 0; }
.c.tl { top: 0; left: 0;  border-top-width: 3px; border-left-width:  3px; border-top-left-radius:     4px; }
.c.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius:    4px; }
.c.bl { bottom: 0; left: 0;  border-bottom-width: 3px; border-left-width:  3px; border-bottom-left-radius:  4px; }
.c.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 4px; }

/* ── Overlay ────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.overlay.show { display: flex; }

.overlay-bg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.show .overlay-bg { animation: fadeScale 200ms ease both; }

.overlay-success { background: var(--c-success); }
.overlay-vip     { background: linear-gradient(135deg, #7b5c00 0%, #ffd700 50%, #7b5c00 100%); background-size: 200%; animation: shimmer 3s linear infinite; }
.overlay-warning { background: var(--c-warning); }
.overlay-danger  { background: var(--c-danger); }
.overlay-neutral { background: var(--c-neutral); }

.overlay-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 48px 32px;
  pointer-events: none;
}

.overlay-title {
  font-size: clamp(40px, 13vw, 64px);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.3);
  margin-bottom: 12px;
}

.overlay-sub {
  font-size: clamp(17px, 5vw, 22px);
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  min-height: 1.4em;
  margin-bottom: 40px;
}

.overlay-hint {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(32px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: rgba(30,30,30,0.96);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.toast[hidden] { display: none; }
.toast:not([hidden]) { animation: slideUp 200ms ease both; }

/* ── Settings drawer ────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.drawer-backdrop[hidden] { display: none; }

.settings-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transform: translateY(100%);
  transition: transform var(--ease-slow);
  padding-bottom: var(--safe-bottom);
  max-height: 85vh;
  overflow-y: auto;
}

.settings-drawer.open { transform: translateY(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 { font-size: 17px; font-weight: 700; }

.drawer-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.settings-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

.settings-email {
  font-size: 13px;
  color: var(--text-muted);
  word-break: break-all;
  line-height: 1.4;
}

.settings-stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
}

.settings-stat strong {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background var(--ease), opacity var(--ease);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  width: 100%;
}

.btn:active { opacity: 0.7; }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover  { background: var(--surface2); }
.btn-outline.active { background: rgba(233,69,96,0.12); border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: rgba(198,40,40,0.12);
  color: #ff6b6b;
  border: 1px solid rgba(198,40,40,0.25);
}

.btn-danger:hover { background: rgba(198,40,40,0.2); }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--ease);
  flex-shrink: 0;
}

.icon-btn:active { background: rgba(255,255,255,0.18); }

/* ── Login page ─────────────────────────────────────────────── */
.login-page {
  height: 100%;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(32px + var(--safe-top)) 24px calc(48px + var(--safe-bottom));
}

.login-wrap {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.login-logo {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 6px;
}

.login-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-hint {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.5;
}

.login-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
}

.login-section[hidden] { display: none; }

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color var(--ease);
  -webkit-appearance: none;
}

.input::placeholder { color: var(--text-dim); }
.input:focus { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover    { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.form-error {
  font-size: 13px;
  color: #ff6b6b;
  text-align: center;
}

.form-error[hidden] { display: none; }

.sent-icon  { font-size: 52px; line-height: 1; margin-bottom: 4px; }

/* ── Animations ─────────────────────────────────────────────── */
@keyframes fadeScale {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes shimmer {
  0%   { background-position: 0%   50%; }
  100% { background-position: 200% 50%; }
}
