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

:root {
  --pos:     #22c55e;
  --neg:     #ef4444;
  --bg:      #111;
  --surface: #1a1a1a;
  --border:  #2a2a2a;
  --text:    #f1f1f1;
  --muted:   #777;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.hidden { display: none !important; }

/* ── Login ── */
#login-screen {
  height: 100dvh;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#login-box {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-title {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
}

#login-sub {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}

#login-box input {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

#login-box input:focus { border-color: #555; }

#login-error {
  color: var(--neg);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
}

#login-btn {
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  padding: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}

#login-btn:hover { opacity: 0.85; }
#login-btn:active { opacity: 0.7; }

/* ── App ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  user-select: none;
}

#topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 4px;
}

#user-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

#topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

#ranking-btn, #logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 8px;
  transition: color 0.15s;
}

#ranking-btn svg, #logout-btn svg { width: 22px; height: 22px; }
#ranking-btn:hover { color: var(--text); }
#logout-btn:hover { color: var(--neg); }

/* ── Card ── */
#card-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  min-height: 0;
}

#card {
  position: relative;
  width: min(92vw, 480px);
  height: 100%;
  max-height: min(72vh, 640px);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
  cursor: grab;
  will-change: transform;
  background: #222;
  transition: width 0.25s ease, max-height 0.25s ease, border-radius 0.25s ease, padding 0.25s ease;
}

#card:active { cursor: grabbing; }

#bg-blur {
  position: absolute;
  inset: -20px;
  background-size: cover;
  background-position: center;
  filter: blur(20px) brightness(0.4);
  transform: scale(1.1);
  z-index: 0;
}

#card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
  transition: opacity 0.1s;
}

#card-img.loading { opacity: 0; }

#admin-kill-btn {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(239,68,68,.85);
  color: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, transform 0.1s;
}

#admin-kill-btn svg { width: 16px; height: 16px; pointer-events: none; }
#admin-kill-btn:hover { background: rgba(239,68,68,1); }
#admin-kill-btn:active { transform: scale(0.9); }

#app.is-admin #admin-kill-btn { display: flex; }

#card-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
  display: none;
}

#overlay-pos, #overlay-neg {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 80px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  border-radius: 18px;
}

#overlay-pos { background: linear-gradient(135deg, rgba(34,197,94,.55), rgba(134,239,172,.25)); color: #fff; }
#overlay-neg { background: linear-gradient(135deg, rgba(239,68,68,.55), rgba(252,165,165,.25)); color: #fff; }

#spinner {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#spinner.visible { opacity: 1; }

.spin-ring {
  width: 44px; height: 44px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── Buttons ── */
#btn-area {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 14px 24px max(24px, env(safe-area-inset-bottom, 24px));
  transition: opacity 0.22s ease, max-height 0.22s ease, padding 0.22s ease;
  max-height: 120px;
  overflow: hidden;
}

#app.expanded #btn-area {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}

#app.expanded #topbar {
  opacity: 0;
  max-height: 0;
  padding: 0;
  pointer-events: none;
  overflow: hidden;
  transition: opacity 0.22s ease, max-height 0.22s ease, padding 0.22s ease;
}

#topbar {
  transition: opacity 0.22s ease, max-height 0.22s ease, padding 0.22s ease;
  max-height: 60px;
  overflow: hidden;
  position: relative;
  z-index: 10;
}

#app.expanded #card-area {
  padding: 0;
}

#app.expanded #card {
  width: 100vw;
  max-height: 100dvh;
  max-height: 100vh;
  border-radius: 0;
}

.btn {
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn:active { transform: scale(0.92); }
.btn svg { display: block; pointer-events: none; }

.btn-neg {
  width: 68px; height: 68px;
  background: rgba(239,68,68,.12);
  border: 2px solid var(--neg);
  color: var(--neg);
}
.btn-neg svg { width: 28px; height: 28px; }
.btn-neg:hover { background: rgba(239,68,68,.22); }

.btn-pos {
  width: 68px; height: 68px;
  background: rgba(34,197,94,.12);
  border: 2px solid var(--pos);
  color: var(--pos);
}
.btn-pos svg { width: 28px; height: 28px; }
.btn-pos:hover { background: rgba(34,197,94,.22); }

.btn-undo {
  width: 48px; height: 48px;
  background: rgba(255,255,255,.05);
  border: 1.5px solid var(--border);
  color: var(--muted);
}
.btn-undo svg { width: 18px; height: 18px; }
.btn-undo:hover { background: rgba(255,255,255,.1); }
.btn-undo:disabled { opacity: 0.25; cursor: not-allowed; }

/* ── Done / Empty ── */
#done-screen, #empty-screen {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeUp 0.35s ease;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } }

#done-box {
  text-align: center;
  padding: 32px 28px;
  max-width: 340px;
}

.done-icon { font-size: 56px; margin-bottom: 16px; }
#done-box h2 { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
#done-box p  { color: var(--muted); font-size: 14px; line-height: 1.6; margin-bottom: 24px; }
#done-box code { background: #2a2a2a; padding: 2px 6px; border-radius: 4px; font-size: 13px; }

.done-btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
  transition: opacity 0.15s;
}

.done-btn:hover { opacity: 0.85; }

/* ── Ranking ── */
#ranking-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  animation: fadeUp 0.2s ease;
}

#ranking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#ranking-header h2 { font-size: 18px; font-weight: 700; }

#ranking-actions { display: flex; gap: 8px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--surface); color: var(--text); }

#ranking-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 12px 24px;
}

.score-pos  { color: var(--pos); }
.score-neg  { color: var(--neg); }
.score-zero { color: var(--muted); }

.rank-empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 24px;
  font-size: 14px;
}

/* ── Score groups ── */
.score-group { border-bottom: 1px solid var(--border); }

.group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.group-header:active { background: var(--surface); }

.group-score {
  font-size: 22px;
  font-weight: 800;
  min-width: 44px;
  letter-spacing: -0.02em;
}

.group-label {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
}

.group-count {
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 20px;
  color: var(--muted);
}

.group-arrow {
  width: 18px;
  height: 18px;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.group-header.open .group-arrow { transform: rotate(180deg); }

.group-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.group-content.open { max-height: 9999px; }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  padding: 2px 4px 10px;
}

.g-thumb-wrap {
  position: relative;
}

.g-thumb {
  aspect-ratio: 1 / 1;
  width: 100%;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface);
  display: block;
}

.g-thumb-dead {
  opacity: 0.35;
  filter: grayscale(1);
}

.dead-badge {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--neg);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
}
