:root {
  --orange: #c94f00;
  --orange-bright: #ff8a00;
  --orange-dark: #963900;
  --ink: #292d32;
  --ink-soft: #454b52;
  --paper: #f3f4f6;
  --line: #d9dde2;
  --muted: #6b7280;
  --success: #168653;
  --success-bright: #1faa6a;
  --error: #dc3545;
  --error-bright: #ef4b5b;
  --warning: #e8a020;
  --white: #ffffff;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(41, 45, 50, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.screen {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 18px 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.screen--center {
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.screen--scan { padding-top: 0; gap: 14px; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 0.92rem; }

.brand {
  padding: 28px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.brand__mark {
  width: 66px;
  height: 66px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--orange-bright), var(--orange-dark));
  color: var(--white);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: 0.5px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.stack { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); }
.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  font-size: 1rem;
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(201, 79, 0, 0.15);
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: default; }

.btn--primary {
  background: var(--orange);
  color: var(--white);
}
.btn--primary:hover { background: var(--orange-dark); }

.btn--ghost {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
}
.btn--ghost:hover { border-color: var(--orange); color: var(--orange); }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { background: rgba(41, 45, 50, 0.07); }

.alert {
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 0.9rem;
}
.alert--error { background: rgba(220, 53, 69, 0.1); color: #a11f2c; }
.alert--success { background: rgba(22, 134, 83, 0.1); color: #0f5e3b; }

.install-hint { text-align: center; margin-top: 6px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0 4px;
}
.topbar__identity { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; }
.topbar__logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--line);
  flex: 0 0 auto;
}
.topbar__identity strong { display: block; font-size: 1rem; }
.topbar__identity span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__event { flex: 1; min-width: 0; }
.topbar__event strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.section-title { padding: 6px 2px 0; }

.event-list { display: flex; flex-direction: column; gap: 12px; }

.event-card {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  box-shadow: 0 2px 10px rgba(41, 45, 50, 0.04);
  transition: border-color 0.15s, transform 0.08s;
}
.event-card:hover { border-color: var(--orange); }
.event-card:active { transform: scale(0.994); }
.event-card__image {
  width: 96px;
  min-height: 96px;
  object-fit: cover;
  background: var(--ink);
  flex: 0 0 auto;
}
.event-card__body { padding: 12px 14px; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.event-card__body strong { font-size: 1rem; line-height: 1.25; }
.event-card__body .muted { font-size: 0.84rem; }
.event-card__meta { display: flex; gap: 12px; margin-top: 4px; font-size: 0.8rem; color: var(--muted); }
.event-card__meta b { color: var(--ink-soft); }
.event-card__progress {
  height: 5px;
  border-radius: 99px;
  background: var(--paper);
  overflow: hidden;
  margin-top: 6px;
}
.event-card__progress span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--orange-bright), var(--orange));
  border-radius: inherit;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  background: var(--white);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.topbar--scan {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  padding-top: calc(10px + env(safe-area-inset-top));
  margin: 0 -18px;
  padding-left: 18px;
  padding-right: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}
.stat span { display: block; font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.stat small { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.4px; }

.scanner {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 62vh;
  border-radius: 18px;
  overflow: hidden;
  background: #14171a;
  box-shadow: var(--shadow);
}
.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.scanner__frame {
  position: absolute;
  inset: 12%;
  border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(11, 13, 15, 0.35);
  pointer-events: none;
}
.scanner__frame::before,
.scanner__frame::after {
  content: "";
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px solid var(--orange-bright);
}
.scanner__frame::before {
  top: -2px;
  left: -2px;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 16px;
}
.scanner__frame::after {
  bottom: -2px;
  right: -2px;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 16px;
}
.scanner__message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--white);
  background: rgba(20, 23, 26, 0.82);
  font-size: 0.92rem;
  line-height: 1.4;
}

.scan-actions { display: flex; gap: 10px; }
.scan-actions .btn { flex: 1; }

.manual { display: flex; flex-direction: column; gap: 12px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.manual__actions { display: flex; gap: 10px; }
.manual__actions .btn { flex: 1; }

.result {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--white);
  background: var(--success);
  animation: result-in 0.18s ease-out;
}
.result--error { background: var(--error); }
.result--warning { background: var(--warning); }
.result__icon {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-size: 2.6rem;
  font-weight: 700;
}
.result h3 { font-size: 1.7rem; }
.result p { font-size: 1.02rem; max-width: 420px; opacity: 0.95; }
.result__details {
  margin: 8px 0 0;
  width: 100%;
  max-width: 380px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  text-align: left;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 14px 16px;
}
.result__details dt { opacity: 0.8; }
.result__details dd { margin: 0; font-weight: 600; word-break: break-word; }
.result .btn--primary { background: var(--white); color: var(--ink); margin-top: 8px; min-width: 200px; }

@keyframes result-in {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--orange);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--warning);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
}

@media (min-width: 620px) {
  .screen { padding-top: 32px; }
  .scanner { max-height: 500px; }
}

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