*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f0f14; --card: #1a1a28; --card-hover: #222236;
  --accent: #4f8; --text: #ccc; --muted: #777; --danger: #e44;
  --radius: 8px; --sidebar-w: 280px;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  overflow: hidden;
}

/* ── App shell ───────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; }
.sidebar-panel {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: #12121e; border-left: 1px solid #222;
  display: flex; flex-direction: column; overflow: hidden;
  transition: width 0.2s, min-width 0.2s;
}
.sidebar-panel.collapsed { width: 0; min-width: 0; overflow: hidden; border: none; }
.main-area { flex: 1; display: flex; flex-direction: column; overflow: auto; padding: 1.5rem; }

/* ── Sidebar tabs ───────────────────────────────────────────────── */
.sidebar-tabs { display: flex; border-bottom: 1px solid #222; flex-shrink: 0; }
.sidebar-tabs button {
  flex: 1; padding: 0.5rem; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 0.78rem; font-weight: 500;
  border-bottom: 2px solid transparent;
}
.sidebar-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.sidebar-content { flex: 1; overflow-y: auto; padding: 0.5rem; }
.sidebar-toggle {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  background: #12121e; border: 1px solid #222; color: var(--muted);
  cursor: pointer; padding: 0.4rem 0.3rem; border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.8rem; z-index: 10; transition: right 0.2s;
}
.sidebar-toggle.collapsed { right: -1px; }

/* ── Sidebar list ───────────────────────────────────────────────── */
.sidebar-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.35rem 0.5rem; border-radius: 4px; font-size: 0.82rem;
}
.sidebar-item:hover { background: var(--card-hover); }
.sidebar-item .rank { width: 1.8rem; color: var(--muted); font-size: 0.75rem; }
.sidebar-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item .score { color: var(--accent); font-size: 0.75rem; margin-left: 0.4rem; }

.history-entry {
  padding: 0.35rem 0.5rem; border-radius: 4px; font-size: 0.78rem;
  border-bottom: 1px solid #1a1a28;
}
.history-entry .winner { color: var(--accent); }
.history-entry .loser { color: var(--danger); }
.history-entry .delta { color: var(--muted); font-size: 0.7rem; }

/* ── Top bar ─────────────────────────────────────────────────────── */
.top-bar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.top-bar h1 { font-size: 1.2rem; color: #fff; }

/* ── Collection list ─────────────────────────────────────────────── */
#section-list { }
#collections { list-style: none; }
#collections li {
  padding: 0.6rem 0.8rem; background: var(--card); border-radius: var(--radius);
  margin-bottom: 0.4rem; transition: background 0.15s;
}
#collections li:hover { background: var(--card-hover); }
#collections .list-main { display: flex; align-items: center; gap: 0.5rem; }
#collections .list-main a { color: var(--accent); text-decoration: none; font-weight: 500; flex: 1; }
#collections .list-main .date { color: var(--muted); font-size: 0.78rem; }
#collections .list-desc { color: var(--muted); font-size: 0.78rem; margin-top: 0.25rem; padding-left: 0; }
.tag { display: inline-block; background: #2a2a3a; color: var(--muted); font-size: 0.65rem; padding: 0.1rem 0.4rem; border-radius: 3px; margin: 0 0.1rem; }
.detail-desc { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.25rem; }
#detail-meta { padding: 0 0 0.5rem 0; }

/* ── Voting area ─────────────────────────────────────────────────── */
.vs-container {
  display: flex; gap: 1rem; align-items: stretch; flex: 1;
  max-height: 70vh;
}
.vs-card {
  flex: 1; background: var(--card); border-radius: var(--radius); padding: 2rem 1.5rem;
  text-align: center; cursor: pointer; border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  position: relative;
}
.vs-card:hover { border-color: var(--accent); transform: scale(1.015); background: var(--card-hover); }
.vs-card.key-hint::after {
  content: "←"; position: absolute; left: 0.5rem; top: 50%; transform: translateY(-50%);
  font-size: 1.5rem; color: var(--accent); opacity: 0.5;
}
.vs-card:last-child.key-hint::after { content: "→"; left: auto; right: 0.5rem; }
.vs-card .card-name { font-size: 1.5rem; color: #fff; margin-bottom: 0.5rem; word-break: break-word; }
 .vs-card .card-elo { font-size: 0.85rem; color: var(--muted); }
 .vs-card .card-glicko { font-size: 0.75rem; color: #aaf; margin-top: 0.1rem; }
 .vs-card .card-rd { font-size: 0.75rem; color: #666; margin-top: 0.1rem; }
 .vs-card .card-votes { font-size: 0.75rem; color: #555; margin-top: 0.25rem; }
.vs-separator {
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: bold; color: #333; width: 3rem;
  flex-shrink: 0;
}
.vs-card.voted {
  animation: voteFlash 0.4s ease-out;
}
@keyframes voteFlash {
  0% { border-color: var(--accent); box-shadow: 0 0 20px rgba(68,255,136,0.3); }
  100% { border-color: transparent; box-shadow: none; }
}

/* ── Card content ─────────────────────────────────────────────────── */
.card-image { max-width: 200px; max-height: 150px; border-radius: 4px; margin: 0.4rem 0; }
.card-rating { color: #ff0; font-size: 0.85rem; margin: 0.2rem 0; }
.card-details { margin-top: 0.3rem; font-size: 0.78rem; color: var(--muted); }

/* ── Buttons / inputs ────────────────────────────────────────────── */
button, .btn {
  cursor: pointer; border: none; border-radius: 6px; padding: 0.5rem 1rem;
  font-size: 0.85rem; font-weight: 500; transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #111; }
.btn-primary:hover { background: #3d6; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c22; }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.75rem; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: #fff; }

.form-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.form-row input {
  flex: 1; padding: 0.5rem; border: 1px solid #333; border-radius: 6px;
  background: var(--card); color: var(--text); font-size: 0.85rem;
}
.form-row input:focus, form input:focus, form textarea:focus { outline: none; border-color: var(--accent); }
form textarea {
  padding: 0.5rem; border: 1px solid #333; border-radius: 6px;
  background: var(--card); color: var(--text); font-size: 0.85rem;
  font-family: inherit; resize: vertical;
}
.detail-form {
  display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem;
  padding: 0.8rem; background: var(--card); border-radius: var(--radius);
}
.detail-form input, .detail-form textarea {
  padding: 0.5rem; border: 1px solid #333; border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 0.85rem;
  font-family: inherit; transition: border-color 0.15s;
}
.detail-form input::placeholder, .detail-form textarea::placeholder {
  color: var(--muted); opacity: 0.7;
}
.detail-form input:focus, .detail-form textarea:focus { outline: none; border-color: var(--accent); }
.detail-form textarea { resize: vertical; }
.card-link {
  display: block; margin-top: 0.3rem; font-size: 0.75rem; color: var(--accent);
  text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-link:hover { text-decoration: underline; }

.section { display: none; }
.section.active { display: flex; flex-direction: column; height: 100%; }

.back-link { color: var(--muted); cursor: pointer; font-size: 0.82rem; display: inline-block; }
.back-link:hover { color: var(--accent); }

.empty-state { color: var(--muted); font-size: 0.85rem; padding: 1rem 0; }
.kb-hint { color: var(--muted); font-size: 0.75rem; text-align: center; margin-top: 0.5rem; }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 2rem; right: 2rem; background: #222;
  color: #fff; padding: 0.6rem 1.2rem; border-radius: var(--radius); font-size: 0.85rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 100;
  border: 1px solid #333;
}
.toast.show { opacity: 1; }

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(15,15,20,0.6); display: none; align-items: center;
  justify-content: center; z-index: 200;
}
.spinner-overlay.show { display: flex; }
.spinner {
  width: 32px; height: 32px; border: 3px solid #333;
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error / retry ──────────────────────────────────────────────── */
.error-state { text-align: center; padding: 1rem; color: var(--danger); }
.error-state .retry-btn {
  margin-top: 0.5rem; cursor: pointer; color: var(--accent);
  background: none; border: 1px solid var(--accent); border-radius: 4px;
  padding: 0.2rem 0.6rem; font-size: 0.78rem;
}

/* ── Keyboard shortcut hint ──────────────────────────────────────── */
.shortcut-help {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid #333; border-radius: var(--radius);
  padding: 0.5rem 1rem; font-size: 0.75rem; color: var(--muted);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 100;
}
.shortcut-help.show { opacity: 1; }

/* ── Mobile ──────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #app { flex-direction: column; }
  .sidebar-panel { width: 100%; min-width: 100%; max-height: 40vh; border-left: none; border-top: 1px solid #222; }
  .main-area { padding: 0.8rem; }
  .vs-container { flex-direction: column; max-height: none; gap: 0.5rem; }
  .vs-card { padding: 1rem; }
  .vs-card .card-name { font-size: 1.1rem; }
  .vs-separator { width: 100%; height: 2rem; }
  .top-bar { flex-wrap: wrap; }
  .top-bar select { margin-left: 0; }
}

/* ── Auth ──────────────────────────────────────────────────────────── */
.auth-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.8rem; background: #1a1a2e; border-radius: 6px; margin-bottom: 1rem;
}
.auth-user { color: #e0e0e0; font-weight: 600; }
.auth-btn {
  padding: 0.3rem 0.8rem; border: 1px solid #444; border-radius: 4px;
  background: #2a2a3e; color: #ccc; cursor: pointer; font-size: 0.85rem;
}
.auth-btn:hover { background: #3a3a5e; }
.auth-page {
  max-width: 400px; margin: 4rem auto; padding: 2rem;
  background: #1a1a2e; border-radius: 8px;
}
.auth-page h2 { margin: 0 0 1.2rem; color: #e0e0e0; }
.auth-page label { display: block; margin: 0.6rem 0 0.2rem; color: #aaa; font-size: 0.9rem; }
.auth-page input {
  width: 100%; padding: 0.5rem; border: 1px solid #444; border-radius: 4px;
  background: #2a2a3e; color: #e0e0e0; font-size: 1rem; box-sizing: border-box;
}
.auth-page input:focus { border-color: #666; outline: none; }
.auth-page button[type="submit"] {
  width: 100%; margin-top: 1rem; padding: 0.6rem; border: none; border-radius: 4px;
  background: #3a6ea5; color: #fff; font-size: 1rem; cursor: pointer;
}
.auth-page button[type="submit"]:hover { background: #4a7eb5; }
.auth-error { color: #e55; font-size: 0.9rem; margin-bottom: 0.5rem; }
.auth-switch { margin-top: 1rem; text-align: center; color: #aaa; font-size: 0.9rem; }
.auth-switch a { color: #7ab; }
