/* ═══════════════════════════════════════════════
   RANK SCORE MASTER — Common Design System
   Mobile-first, dual theme, app-grade UI
═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;600&display=swap');

/* ── CSS Variables ── */
:root {
  --font-main: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 999px;

  /* Brand */
  --brand: #6366f1;
  --brand-dark: #4f46e5;
  --brand-light: #818cf8;
  --brand-glow: rgba(99, 102, 241, 0.25);
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-yellow: #f59e0b;
  --accent-blue: #3b82f6;
  --accent-orange: #f97316;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 200ms;
}

/* ── DARK THEME (default) ── */
[data-theme="dark"] {
  --bg-base: #09090b;
  --bg-surface: #111113;
  --bg-card: #18181b;
  --bg-card-hover: #1f1f23;
  --bg-input: #0f0f11;
  --bg-overlay: rgba(0,0,0,0.6);

  --border: rgba(255,255,255,0.08);
  --border-focus: var(--brand);
  --border-strong: rgba(255,255,255,0.15);

  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #52525b;
  --text-inverse: #09090b;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);
  --shadow-brand: 0 0 24px var(--brand-glow);

  --scrollbar-track: #111113;
  --scrollbar-thumb: #3f3f46;
}

/* ── LIGHT THEME ── */
[data-theme="light"] {
  --bg-base: #f4f4f5;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f9f9fb;
  --bg-input: #f4f4f5;
  --bg-overlay: rgba(0,0,0,0.3);

  --border: rgba(0,0,0,0.08);
  --border-focus: var(--brand);
  --border-strong: rgba(0,0,0,0.15);

  --text-primary: #09090b;
  --text-secondary: #52525b;
  --text-muted: #a1a1aa;
  --text-inverse: #fafafa;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --shadow-brand: 0 0 24px rgba(99,102,241,0.15);

  --scrollbar-track: #f4f4f5;
  --scrollbar-thumb: #d4d4d8;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 { font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); }
h2 { font-size: clamp(1.2rem, 3vw, 1.6rem); }
h3 { font-size: clamp(1rem, 2.5vw, 1.2rem); }
p { line-height: 1.6; }
a { color: var(--brand-light); text-decoration: none; }
a:hover { color: var(--brand); }

/* ── Layout ── */
.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--sp-4);
}

.container--wide {
  max-width: 960px;
}

/* ── Top Nav / Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 var(--sp-4);
  max-width: 960px;
  margin: 0 auto;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-decoration: none;
  flex-shrink: 0;
}

.app-logo__icon {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--brand) 0%, #a855f7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-brand);
}

.app-logo__icon svg {
  width: 20px;
  height: 20px;
  fill: #fff;
}

.app-logo__text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.app-logo__name {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.app-logo__tagline {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ── Theme Toggle ── */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--dur) var(--ease);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.theme-toggle svg { width: 18px; height: 18px; }

/* ── Back Button ── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  text-decoration: none;
  font-family: var(--font-main);
}

.btn-back:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-back svg { width: 16px; height: 16px; }

/* ── Page Main ── */
.page-main {
  padding: var(--sp-6) 0 var(--sp-12);
}

/* ── Card ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.card--hover:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ── Section Label ── */
.section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}

/* ── Form Elements ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.form-group:last-child { margin-bottom: 0; }

.form-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.form-label .required {
  color: var(--accent-red);
  margin-left: 2px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 10px var(--sp-3);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font-main);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  -webkit-appearance: none;
  appearance: none;
}

.form-input::placeholder { color: var(--text-muted); }
.form-input:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

.form-select-wrap {
  position: relative;
}

.form-select-wrap::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted);
  pointer-events: none;
}

.form-select-wrap .form-select { padding-right: 32px; }

/* ── Grid for 2-col on wider screens ── */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

@media (max-width: 480px) {
  .form-grid-2 { grid-template-columns: 1fr; }
}

/* ── Checkbox ── */
.checkbox-wrap {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  cursor: pointer;
  padding: var(--sp-3);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-input);
  transition: border-color var(--dur) var(--ease);
}

.checkbox-wrap:has(input:checked) {
  border-color: var(--brand);
  background: rgba(99,102,241,0.06);
}

.checkbox-wrap input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  accent-color: var(--brand);
  cursor: pointer;
}

.checkbox-text {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.checkbox-text strong { color: var(--text-primary); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 12px var(--sp-5);
  border-radius: var(--r-md);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  border: none;
  transition: all var(--dur) var(--ease);
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.btn--primary {
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99,102,241,0.35);
}

.btn--primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99,102,241,0.45);
}

.btn--primary:active { transform: translateY(0); }

.btn--secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.btn--secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--brand);
  color: var(--brand-light);
}

.btn--full { width: 100%; }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge--new { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.25); }
.badge--live { background: rgba(34,197,94,0.15); color: #4ade80; border: 1px solid rgba(34,197,94,0.25); }
.badge--closed { background: rgba(161,161,170,0.15); color: var(--text-muted); border: 1px solid var(--border); }
.badge--ssc { background: rgba(99,102,241,0.15); color: var(--brand-light); border: 1px solid rgba(99,102,241,0.25); }
.badge--rrb { background: rgba(249,115,22,0.15); color: #fb923c; border: 1px solid rgba(249,115,22,0.25); }

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--sp-5) 0;
}

/* ── Log / Output ── */
.log-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  max-height: 220px;
  overflow-y: auto;
  line-height: 1.8;
}

.log-ok { color: var(--accent-green); }
.log-err { color: var(--accent-red); }
.log-warn { color: var(--accent-yellow); }
.log-info { color: var(--text-muted); }

/* ── Score Box ── */
.score-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
}

.score-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-3);
  text-align: center;
}

.score-box--total {
  grid-column: 1 / -1;
  background: rgba(99,102,241,0.08);
  border-color: rgba(99,102,241,0.3);
}

.score-box__num {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: var(--sp-1);
  font-variant-numeric: tabular-nums;
}

.score-box--total .score-box__num {
  font-size: 2.4rem;
  color: var(--brand-light);
}

.score-box__label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.score-green { color: var(--accent-green); }
.score-red { color: var(--accent-red); }
.score-yellow { color: var(--accent-yellow); }
.score-blue { color: var(--accent-blue); }
.score-muted { color: var(--text-secondary); }

/* ── Tab Row ── */
.tab-row {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border-radius: var(--r-md);
  padding: 3px;
  margin-bottom: var(--sp-4);
}

.tab-btn {
  flex: 1;
  padding: var(--sp-2) var(--sp-3);
  border-radius: calc(var(--r-md) - 2px);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  font-family: var(--font-main);
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ── Utility ── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.fw-700 { font-weight: 700; }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.gap-3 { gap: var(--sp-3); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.fade-up { animation: fadeUp 0.4s var(--ease) both; }
.fade-up-1 { animation-delay: 0.05s; }
.fade-up-2 { animation-delay: 0.1s; }
.fade-up-3 { animation-delay: 0.15s; }
.fade-up-4 { animation-delay: 0.2s; }

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