/* ═══════════════════════════════════════════════════════════════
   Character Select — char_select.css
   Depends on global.css for CSS custom properties
   ═══════════════════════════════════════════════════════════════ */

/* ── Page base ──────────────────────────────────────────────── */

body.gvm.cs-body {
  background: var(--gvm-ink);
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 3px,
      rgba(255, 206, 163, 0.025) 3px,
      rgba(255, 206, 163, 0.025) 4px
    );
  background-attachment: fixed;
  background-size: auto;
}

.cs-main {
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.cs-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem 2rem;
  min-height: 0;
}

/* ── Heading ────────────────────────────────────────────────── */

.cs-heading {
  text-align: center;
  margin-bottom: 1rem;
}

.cs-title {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  background: linear-gradient(135deg, var(--gvm-tertiary) 0%, var(--gvm-gold) 50%, var(--gvm-tertiary) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0;
  padding: 0;
  line-height: 1.1;
}

.cs-title::after {
  content: '';
  display: block;
  height: 2px;
  width: 50%;
  margin: 0.5rem auto 0;
  background: linear-gradient(90deg, transparent, var(--gvm-tertiary), transparent);
}

.cs-subtitle {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: rgba(255, 206, 163, 0.5);
  margin: 0.35rem 0 0;
}

/* ── Vote banner ────────────────────────────────────────────── */

.cs-banner {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 0.45rem 1.5rem;
  margin: 0 auto 1.25rem;
  border-radius: 3px;
  max-width: 440px;
  transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.cs-banner[data-state="idle"] {
  background: rgba(214, 164, 58, 0.15);
  color: var(--gvm-tertiary);
  border: 1px solid rgba(214, 164, 58, 0.3);
}

.cs-banner[data-state="voted"] {
  background: rgba(28, 97, 114, 0.12);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(28, 97, 114, 0.35);
  box-shadow: none;
  font-weight: 600;
}

/* ── Above-grid row ─────────────────────────────────────────── */

.cs-above {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: center;
  margin-bottom: 1.25rem;
}

/* ── Character grid ─────────────────────────────────────────── */

.cs-grid-wrap {
  width: 100%;
}

.cs-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: 100%;
  border: 3px solid var(--gvm-tertiary);
  box-shadow:
    0 0 0 1px rgba(214, 164, 58, 0.2),
    0 0 50px rgba(214, 164, 58, 0.15),
    0 8px 40px rgba(0, 0, 0, 0.6);
  position: relative;
}

.cs-grid::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 4px,
    rgba(0, 0, 0, 0.06) 4px,
    rgba(0, 0, 0, 0.06) 5px
  );
  pointer-events: none;
  z-index: 2;
}

/* ── Grid cells ─────────────────────────────────────────────── */

.cs-cell {
  position: relative;
  overflow: visible;
  cursor: pointer;
  background-image: url('../img/gvm_char_select.png');
  background-size: 900% 500%;
  background-repeat: no-repeat;
  aspect-ratio: 136 / 137;
  outline: 1px solid rgba(214, 164, 58, 0.2);
  transition: transform 0.18s ease, outline-color 0.18s ease, box-shadow 0.18s ease;
  z-index: 1;
}

.cs-cell:not(.cs-cell--mystery):hover {
  transform: scale(1.1);
  outline: 2px solid var(--gvm-tertiary);
  z-index: 10;
  box-shadow: 0 0 20px rgba(214, 164, 58, 0.6);
}

.cs-cell:focus-visible {
  outline: 2px solid var(--gvm-tertiary);
  z-index: 10;
}

/* Mystery / unassigned cells — visible but non-interactive */
.cs-cell--mystery {
  cursor: default;
}

.cs-cell--mystery::before {
  content: '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.25);
  z-index: 3;
}

/* Character name label (revealed on hover) */
.cs-cell__label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 3px;
  font-size: clamp(0.42rem, 0.8vw, 0.58rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.88));
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 3;
}

.cs-cell:hover .cs-cell__label {
  opacity: 1;
}

/* ── Voted cell state ───────────────────────────────────────── */

.cs-cell--voted {
  outline: 2px solid var(--gvm-secondary);
  box-shadow: inset 0 0 0 2px var(--gvm-secondary), 0 0 14px rgba(28, 97, 114, 0.75);
  z-index: 4;
}

.cs-cell--voted::after {
  content: '✓';
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--gvm-secondary);
  color: #fff;
  font-size: 0.5rem;
  font-weight: 900;
  padding: 1px 3px;
  z-index: 5;
  line-height: 1.5;
  pointer-events: none;
}

/* ── Character preview (centered above grid) ────────────────── */

.cs-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.25rem;
  flex-shrink: 0;
  width: 200px;
  min-height: 26rem;
}

.cs-preview__portrait {
  position: relative;
  width: 200px;
  height: 200px;
  border: 2px solid var(--gvm-tertiary);
  border-radius: 4px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 30px rgba(214, 164, 58, 0.2);
}

.cs-preview__info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  width: 100%;
  min-height: 8rem;
}

.cs-preview__placeholder {
  font-size: 4rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.08);
  user-select: none;
  line-height: 1;
}

.cs-preview__placeholder--hidden { display: none; }

.cs-preview__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  transition: opacity 0.25s ease;
}

.cs-preview__img--hidden { display: none; }

.cs-preview__name {
  font-size: 1rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gvm-gold);
  margin: 0.4rem 0 0;
  line-height: 1.2;
  min-height: 1.4em;
}

.cs-preview__house {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 206, 163, 0.5);
  margin: 0;
}

.cs-preview__job {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.7);
  font-style: italic;
  margin: 0;
}

.cs-preview__bio {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gvm-gold);
  border-bottom: 1px solid var(--gvm-gold);
  text-decoration: none;
  font-weight: 700;
  transition: opacity 0.15s ease;
  margin-top: 0.15rem;
}

.cs-preview__bio[aria-hidden="true"] { display: none; }
.cs-preview__bio:hover { opacity: 0.7; }

/* ── Vote button ────────────────────────────────────────────── */

.cs-vote-btn {
  display: block;
  width: 200px;
  margin: 0.5rem auto 0;
  padding: 0.55rem 0.5rem;
  background: var(--gvm-tertiary);
  color: var(--gvm-ink);
  border: none;
  border-radius: 3px;
  font-weight: 900;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease, background 0.3s ease;
  flex-shrink: 0;
}

.cs-vote-btn:hover:not(:disabled) {
  opacity: 0.85;
  transform: translateY(-1px);
}

.cs-vote-btn:disabled {
  opacity: 0.35;
  cursor: default;
  transform: none;
}

.cs-vote-btn--voted {
  background: transparent;
  color: rgba(255, 255, 255, 0.22);
  border: none;
  font-size: 0.6rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  padding: 0.2rem 0;
  opacity: 1 !important;
  cursor: default;
}

/* ── Undo button ────────────────────────────────────────────── */

.cs-undo-btn {
  display: block;
  width: 200px;
  margin: 0.4rem auto 0;
  padding: 0.55rem 0.5rem;
  background: transparent;
  color: var(--gvm-tertiary);
  border: 1px solid var(--gvm-tertiary);
  border-radius: 3px;
  font-weight: 900;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}

/* Keep space reserved even when hidden so layout doesn't jump */
.cs-undo-btn[hidden] {
  display: block !important;
  visibility: hidden;
  pointer-events: none;
}

.cs-undo-btn:hover {
  background: rgba(214, 164, 58, 0.12);
  color: var(--gvm-gold);
  border-color: var(--gvm-gold);
}

/* ── Results panel ──────────────────────────────────────────── */

.cs-results {
  width: 100%;
  max-width: 440px;
  margin: 0 auto 2.5rem;
  display: flex;
  flex-direction: column;
  border: 2px solid rgba(214, 164, 58, 0.4);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  padding: 0.75rem 0.65rem;
  overflow-y: auto;
}

.cs-results__title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: var(--gvm-tertiary);
  margin: 0 0 0.8rem;
  text-align: center;
  font-weight: 900;
}

.cs-results__empty {
  font-size: 0.68rem;
  color: rgba(255, 206, 163, 0.35);
  text-align: center;
  margin: 0;
  font-style: italic;
}

/* Vote bars */
.vote-bar {
  margin-bottom: 0.6rem;
}

.vote-bar__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.25rem;
  margin-bottom: 0.2rem;
}

.vote-bar__name {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vote-bar__pct {
  font-size: 0.58rem;
  color: var(--gvm-gold);
  flex-shrink: 0;
}

.vote-bar__track {
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.vote-bar__fill {
  height: 100%;
  background: var(--gvm-tertiary);
  border-radius: 2px;
  transition: width 0.6s ease;
}

.vote-bar--mine .vote-bar__name { color: var(--gvm-gold); font-weight: 700; }
.vote-bar--mine .vote-bar__fill { background: var(--gvm-secondary); }

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 900px) {
  .cs-preview { width: 160px; min-height: 24rem; }
  .cs-preview__portrait { width: 160px; height: 160px; }
  .cs-vote-btn { width: 160px; }
  .cs-undo-btn { width: 160px; }
}

@media (max-width: 767px) {
  .cs-stage { padding: 1rem 0.75rem 1.5rem; }

  .cs-preview { width: 140px; min-height: 22rem; }
  .cs-preview__portrait { width: 140px; height: 140px; }
  .cs-vote-btn { width: 140px; }
  .cs-undo-btn { width: 140px; }
}

@media (max-width: 480px) {
  .cs-preview__job { display: none; }
  .cs-preview__name { font-size: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  .cs-cell,
  .cs-turn-banner,
  .cs-panel,
  .cs-panel__img { transition: none; animation: none; }
  @keyframes cs-pulse-gold { from, to { box-shadow: none; } }
}
