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

/* === Design tokens === */
:root {
  --bg:        #0f0f12;
  --surface:   #17171d;
  --surface-2: #1e1e26;
  --border:    #2a2a36;
  --text:      #e4e4f0;
  --muted:     #5a5a72;
  --accent:    #7c6af5;
  --accent-glow: rgba(124,106,245,0.35);
  --header-h:  46px;
}

html, body {
  height: auto;
  overflow: auto;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}


/* === Header === */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  height: 100%;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
h1 { font-size: 1rem; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; }
h1 span { color: var(--accent); }

.session-controls { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.session-label { color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
#session-display {
  font-family: monospace; font-size: 0.78rem; font-weight: 700;
  color: var(--text); letter-spacing: 0.06em; white-space: nowrap;
}
.presence-badge {
  font-size: 0.66rem; font-weight: 600;
  background: #1a2e1a; color: #4ade80; border: 1px solid #2a4a2a;
  padding: 0.12rem 0.4rem; border-radius: 3px; white-space: nowrap;
}
.local-only-badge {
  font-size: 0.66rem; font-weight: 600;
  background: #1a1a2e; color: #818cf8; border: 1px solid #2a2a4a;
  padding: 0.12rem 0.4rem; border-radius: 3px; white-space: nowrap;
}
.join-input {
  flex: 1; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 1.1rem; font-weight: 700;
  font-family: monospace; letter-spacing: 0.15em; text-transform: uppercase;
  padding: 0.4rem 0.6rem; outline: none; text-align: center;
}
.join-input:focus { border-color: var(--accent); }

/* === Buttons === */
.btn {
  cursor: pointer; border: none; border-radius: 6px;
  font-size: 0.78rem; font-weight: 500; padding: 0.32rem 0.65rem;
  transition: opacity 0.15s, transform 0.1s; white-space: nowrap;
}
.btn:hover  { opacity: 0.82; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost   { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.btn-sm { font-size: 0.72rem; padding: 0.25rem 0.5rem; }

/* === Main layout === */
main {
  padding: 0.6rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 0.75rem;
  align-items: start;
}

.layout-left {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.layout-right {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-left: 1px solid var(--border);
  padding-left: 0.75rem;
  position: sticky;
  top: calc(var(--header-h) + 0.6rem);
  max-height: calc(100vh - var(--header-h) - 1.2rem);
  overflow-y: auto;
}

/* === Tier list === */
.tier-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tier-row {
  display: flex;
  align-items: stretch;
  min-height: 80px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.tier-label {
  width: 100px;
  min-width: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.4rem;
  line-height: 1.2;
  flex-shrink: 0;
  cursor: pointer;
  transition: filter 0.12s;
}
.tier-label:hover { filter: brightness(1.2); }

.tier-joke          .tier-label { background: #ff69b4; color: #fff; }
.tier-overpowered   .tier-label { background: #4a0000; color: #ff9999; }
.tier-strong        .tier-label { background: #991b1b; color: #fff; }
.tier-above-vanilla .tier-label { background: #c2410c; color: #fff; }
.tier-vanilla       .tier-label { background: #ea580c; color: #fff; }
.tier-below-vanilla .tier-label { background: #ca8a04; color: #fff; }
.tier-weak          .tier-label { background: #15803d; color: #fff; }
.tier-underpowered  .tier-label { background: #1d4ed8; color: #fff; }

/* === Drop zones === */
.drop-zone {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  padding: 6px;
  background: var(--surface);
  overflow-y: auto;
  transition: background 0.12s, outline 0.12s;
}
.drop-zone.drag-over {
  background: var(--surface-2);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.drop-ghost {
  width: 68px;
  height: 68px;
  border-radius: 6px;
  border: 2px dashed var(--accent);
  background: var(--accent-glow);
  flex-shrink: 0;
  pointer-events: none;
}

/* === Character cards === */
.char-card {
  width: 68px;
  cursor: grab;
  user-select: none;
  transition: transform 0.1s, opacity 0.12s;
  flex-shrink: 0;
}
.char-card:hover  { transform: translateY(-2px); }
.char-card:active { cursor: grabbing; }
.char-card.dragging { opacity: 0.35; transform: scale(0.95); }

.char-avatar {
  width: 68px;
  height: 68px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  border: 2px solid var(--border);
  transition: border-color 0.15s;
}
.char-card:hover .char-avatar { border-color: var(--accent); }
.char-avatar img { width: 100%; height: 100%; object-fit: cover; }

.char-name {
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
  margin-top: 4px;
  color: var(--text);
  line-height: 1.3;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* === Shared unranked === */
.shared-unranked-section { flex-shrink: 0; }
.shared-unranked-section .section-heading { margin-bottom: 0.3rem; }
#pool-unranked {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 70px;
  max-height: 110px;
  overflow-y: auto;
}

/* === Section headings === */
.section-heading {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.section-tag {
  font-size: 0.58rem;
  font-weight: 600;
  padding: 0.12rem 0.35rem;
  border-radius: 3px;
}
.shared-tag  { background: #1a2e1a; color: #4ade80; border: 1px solid #2a4a2a; }
.private-tag { background: #1a1a2e; color: #818cf8; border: 1px solid #2a2a4a; }

/* === Private sidebar === */
.private-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.path-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.3rem 0.5rem;
  flex-shrink: 0;
}
#steam-path {
  font-family: monospace;
  font-size: 0.6rem;
  color: var(--muted);
  word-break: break-all;
  flex: 1;
  line-height: 1.3;
}
.btn-copy-path {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.1rem 0.25rem;
  border-radius: 3px;
  flex-shrink: 0;
}
.btn-copy-path:hover { background: var(--border); color: var(--text); }

.private-hint {
  color: var(--muted);
  font-size: 0.66rem;
  flex-shrink: 0;
  line-height: 1.3;
}
.private-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-y: visible;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 6px;
  align-content: flex-start;
}
.empty-private {
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.5rem;
  width: 100%;
  line-height: 1.5;
}
.empty-private code {
  background: var(--surface-2);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.68rem;
}

/* Private cards — smaller so 2 fit per row in 200px sidebar */
.private-card { width: 80px; }
.private-card .char-avatar { width: 80px; height: 80px; border-style: dashed; opacity: 0.85; }
.private-card:hover .char-avatar { border-style: solid; opacity: 1; }
.shared-card:hover .char-avatar { border-color: var(--accent); }

/* === Loading overlay === */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 900;
  backdrop-filter: blur(4px);
  gap: 1rem;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-overlay p {
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
}

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; backdrop-filter: blur(6px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; width: min(480px, 95vw);
  padding: 1.5rem; max-height: 90vh;
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 1rem; flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; padding: 0.2rem 0.4rem;
  border-radius: 4px; line-height: 1;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { overflow-y: auto; flex: 1; }
.modal-hint { color: var(--muted); font-size: 0.83rem; margin-bottom: 0.75rem; }
.error-text { color: #f87171; font-size: 0.82rem; margin-top: 0.6rem; }


/* === Power Rank Guide === */
.pr-modal {
  width: min(680px, 95vw);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 420px;
}

.pr-topbar {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.pr-nav {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 0;
}

.pr-nav-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.65rem 0.8rem;
  opacity: 0.55;
  transition: opacity 0.12s, background 0.12s;
  white-space: nowrap;
}
.pr-nav-btn:hover  { opacity: 0.85; background: rgba(255,255,255,0.04); }
.pr-nav-btn.active { opacity: 1; }

/* Nav button text colors */
.pr-nav-btn.pr-joke         { color: #ff69b4; }
.pr-nav-btn.pr-overpowered  { color: #ff9999; }
.pr-nav-btn.pr-strong       { color: #fca5a5; }
.pr-nav-btn.pr-above        { color: #fdba74; }
.pr-nav-btn.pr-vanilla      { color: #fed7aa; }
.pr-nav-btn.pr-below        { color: #fde68a; }
.pr-nav-btn.pr-weak         { color: #86efac; }
.pr-nav-btn.pr-underpowered { color: #93c5fd; }

.pr-nav-btn.active { background: rgba(255,255,255,0.06); }

.pr-topbar .modal-close {
  padding: 0 1rem;
  border-left: 1px solid var(--border);
  border-radius: 0;
  flex-shrink: 0;
}

.pr-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 3.5rem;
  text-align: center;
}

.pr-panel { display: none; flex-direction: column; align-items: center; gap: 1.5rem; }
.pr-panel:not(.hidden) { display: flex; }

.pr-panel-badge {
  font-size: 2.2rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.35rem 1.1rem;
  border-radius: 8px;
}

.pr-panel-body {
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--text);
  max-width: 520px;
}
.pr-panel-body strong { color: #fff; }

.pr-panel-lookout {
  font-size: 0.85rem;
  color: var(--muted);
}
.pr-panel-lookout span {
  font-weight: 700;
  color: var(--text);
  margin-right: 0.3rem;
}

/* Tier-matched badge colors */
.pr-panel-badge.pr-joke         { background: #ff69b422; color: #ff69b4; }
.pr-panel-badge.pr-overpowered  { background: #4a000044; color: #ff9999; }
.pr-panel-badge.pr-strong       { background: #991b1b33; color: #fca5a5; }
.pr-panel-badge.pr-above        { background: #c2410c33; color: #fdba74; }
.pr-panel-badge.pr-vanilla      { background: #ea580c33; color: #fed7aa; }
.pr-panel-badge.pr-below        { background: #ca8a0433; color: #fde68a; }
.pr-panel-badge.pr-weak         { background: #15803d33; color: #86efac; }
.pr-panel-badge.pr-underpowered { background: #1d4ed833; color: #93c5fd; }

/* === Utility === */
.hidden { display: none !important; }
