:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #14161a;
  --muted: #5f6672;
  --border: #dfe2e8;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --highlight: #fde68a;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.04);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a21;
    --text: #eef0f4;
    --muted: #9aa3b2;
    --border: #272c36;
    --accent: #60a5fa;
    --accent-text: #0b1220;
    --danger: #f87171;
    --highlight: #5b4a10;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

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

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0;
}

h2 {
  font-size: 1.15rem;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Layout */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  font-size: 1.1rem;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 64px;
  display: grid;
  gap: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

#live-indicator::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #22c55e;
  animation: pulse 2s ease-in-out infinite;
}

/* Buttons and inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--muted);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type='text'],
input[type='password'] {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 6px;
}

/* Upload */
.upload {
  padding: 20px;
}

.upload h2 {
  margin-bottom: 14px;
}

.dropzone {
  display: grid;
  gap: 4px;
  place-items: center;
  text-align: center;
  padding: 28px 16px;
  margin: 0 0 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 400;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

.dropzone:hover,
.dropzone.dragging,
.dropzone:focus-within {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.dropzone input[type='file'] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-title {
  font-weight: 600;
  word-break: break-all;
}

.row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.grow {
  flex: 1 1 220px;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

progress {
  flex: 1;
  height: 10px;
  accent-color: var(--accent);
}

.status {
  min-height: 1.4em;
  margin: 12px 0 0;
  font-size: 0.92rem;
}

.error {
  color: var(--danger);
}

/* Items */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
}

.empty {
  padding: 32px 16px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.item {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.thumb {
  aspect-ratio: 16 / 9;
  background: #000;
}

.thumb img,
.thumb video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.item-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.item-title {
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.stats {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--bg);
  transition: background 0.3s;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat.big {
  padding: 8px 18px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.stat.big .stat-value {
  font-size: 2.2rem;
  color: var(--accent);
}

.stat-value.small {
  font-size: 1rem;
  font-weight: 600;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
}

.stat.bump {
  animation: bump 1.6s ease-out;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.qr {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.qr[hidden] {
  display: none;
}

.qr img {
  background: #fff;
  border-radius: 6px;
  max-width: 100%;
  height: auto;
}

.qr-actions {
  display: grid;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.92rem;
  z-index: 10;
}

.toast[hidden] {
  display: none;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin-bottom: 6px;
}

.login-card form {
  display: grid;
  gap: 4px;
  margin-top: 20px;
}

.login-card input {
  margin-bottom: 12px;
}

.login-card .btn {
  margin-top: 4px;
  min-height: 46px;
}

.login-card .error {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

[hidden] {
  display: none !important;
}

@keyframes bump {
  0% {
    background: var(--highlight);
    transform: scale(1.04);
  }
  100% {
    background: var(--bg);
    transform: scale(1);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@media (max-width: 480px) {
  .stats {
    grid-template-columns: 1fr 1fr;
  }
  .stat.big {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stat.bump,
  #live-indicator::before {
    animation: none;
  }
  .stat.bump {
    background: var(--highlight);
  }
}
