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

:root {
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --border: #30363d;
  --accent: #58a6ff;

  /* Tier colors */
  --glimmer: #98c379;
  --spark: #69ff94;
  --blaze: #50fa7b;
  --inferno: #ff79c6;
  --wildcard: #bd93f9;
  --penalty: #ff5555;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-pixel: 'VT323', 'Courier New', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-pixel);
  font-size: 18px;
  line-height: 1.5;
  text-shadow: 0 0 3px rgba(140, 200, 255, 0.25);
}

/* CRT scanline overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0, 0, 0, 0.08) 3px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* === Select Screen === */
.select-screen {
  text-align: center;
  padding: 3rem 2rem;
  max-width: 900px;
  width: 100%;
  margin-top: auto;
  margin-bottom: auto;
}

.select-header {
  margin-bottom: 3rem;
}

.select-title {
  font-size: 2.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 0 12px rgba(88, 166, 255, 0.6), 0 0 28px rgba(88, 166, 255, 0.2);
  margin-bottom: 0.5rem;
}

.select-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  letter-spacing: 0.15em;
  text-transform: lowercase;
}

.hint {
  color: var(--text-muted);
  font-style: italic;
}

/* === Bouncer Grid === */
.bouncer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 360px));
  justify-content: center;
  gap: 1.5rem;
  width: 100%;
}

/* === Bouncer Card Form === */
.bouncer-card-form {
  display: contents;
}

/* === Bouncer Card === */
.bouncer-card {
  all: unset;
  display: block;
  width: 100%;
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease;
  text-align: left;
  color: var(--text);
}

.bouncer-card:hover {
  transform: translateY(-3px);
}

.card-glow {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 0;
}

.bouncer-card:hover .card-glow {
  opacity: 1;
}

/* Difficulty-based glow colors */
.bouncer-card[data-difficulty="easy"] .card-glow {
  box-shadow: 0 0 20px rgba(80, 250, 123, 0.2), inset 0 0 20px rgba(80, 250, 123, 0.05);
}
.bouncer-card[data-difficulty="medium"] .card-glow {
  box-shadow: 0 0 20px rgba(255, 183, 77, 0.2), inset 0 0 20px rgba(255, 183, 77, 0.05);
}
.bouncer-card[data-difficulty="hard"] .card-glow {
  box-shadow: 0 0 20px rgba(255, 85, 85, 0.2), inset 0 0 20px rgba(255, 85, 85, 0.05);
}

.card-inner {
  position: relative;
  z-index: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 1.5rem;
  text-align: left;
  transition: border-color 0.3s ease;
}

.bouncer-card:hover .card-inner {
  border-color: var(--text-muted);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}

.bouncer-name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

/* === Difficulty Badge === */
.difficulty-badge {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.2em 0.6em;
  flex-shrink: 0;
}

.difficulty-easy {
  color: #50fa7b;
  border: 1px solid rgba(80, 250, 123, 0.3);
  background: rgba(80, 250, 123, 0.08);
}

.difficulty-medium {
  color: #ffb74d;
  border: 1px solid rgba(255, 183, 77, 0.3);
  background: rgba(255, 183, 77, 0.08);
}

.difficulty-hard {
  color: #ff5555;
  border: 1px solid rgba(255, 85, 85, 0.3);
  background: rgba(255, 85, 85, 0.08);
}

.bouncer-oneliner {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.6;
  letter-spacing: 0.05em;
}

.meta-sep {
  opacity: 0.4;
}

/* === Responsive === */
@media (max-width: 600px) {
  .select-screen {
    padding: 2rem 1rem;
  }

  .select-title {
    font-size: 1.8rem;
  }

  .bouncer-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* === Game Screen === */
.game-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 780px;
  border-left: 1px solid #5f5f5f;
  border-right: 1px solid #5f5f5f;
}

/* === Game Header === */
.game-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  background: #1c1c1c;
  border-bottom: 1px solid #5f5f5f;
  flex-shrink: 0;
}

.door-icon {
  font-weight: bold;
  color: #f8f8f2;
}

.header-title {
  font-weight: bold;
  color: #f8f8f2;
}

.header-bouncer {
  margin-left: auto;
  color: #f1fa8c;
}

/* === Transcript === */
.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  border-bottom: 1px solid #5f5f5f;
  color: #f0f0f0;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}

/* Pushes content to the bottom when transcript is not yet full */
.transcript::before {
  content: '';
  flex: 1;
}

/* === Input Form === */
.input-form {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.4rem 1rem;
  border-bottom: 1px solid #5f5f5f;
  flex-shrink: 0;
  background: var(--bg);
}

.input-prompt {
  color: #8be9fd;
  font-weight: bold;
  padding-right: 0.5rem;
  flex-shrink: 0;
}

.player-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #8be9fd;
  font-family: var(--font-pixel);
  font-size: inherit;
  line-height: 1.5;
  outline: none;
  padding: 0.2rem 0;
}

.player-input::placeholder {
  color: #6272a4;
}

.send-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid #5f5f5f;
  padding: 0.2rem 0.8rem;
  font-family: var(--font-pixel);
  font-size: inherit;
  cursor: pointer;
  margin-left: 0.5rem;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.send-btn:hover {
  color: #8be9fd;
  border-color: #8be9fd;
}

/* === Status Bar === */
.status-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  padding: 0.35rem 1rem;
  background: #1a1a2e;
  flex-shrink: 0;
  font-size: 0.85rem;
}

.status-score {
  color: #b0b0b0;
}

.status-score .val {
  color: #50fa7b;
  font-weight: bold;
}

.status-progress {
  color: #8be9fd;
}

.status-rubric,
.status-wildcard,
.status-turns {
  color: #b0b0b0;
}

.status-sep {
  color: #6272a4;
}

/* === Messages === */
.message {
  padding: 0.15rem 0;
  line-height: 1.6;
}

.message + .message {
  margin-top: 0.4rem;
}

.speaker-label {
  font-weight: bold;
  margin-right: 0.4rem;
}

.bouncer-message .speaker-label {
  color: #f1fa8c;
  text-shadow: 0 0 8px rgba(241, 250, 140, 0.6);
}

.player-message .speaker-label {
  color: #8be9fd;
  text-shadow: 0 0 8px rgba(139, 233, 253, 0.6);
}

.system-message {
  color: var(--text-muted);
  font-style: italic;
}

/* === Score Feedback === */
.score-feedback {
  padding: 0.25rem 0 0.25rem 1rem;
  font-size: 0.8rem;
  opacity: 0.85;
}

.hit-line {
  line-height: 1.8;
}

.tier-glimmer  { color: var(--glimmer);  text-shadow: 0 0 6px var(--glimmer); }
.tier-spark    { color: var(--spark);    text-shadow: 0 0 8px var(--spark); }
.tier-blaze    { color: var(--blaze);    text-shadow: 0 0 10px var(--blaze); }
.tier-inferno  { color: var(--inferno);  text-shadow: 0 0 12px var(--inferno); }
.tier-wildcard { color: var(--wildcard); text-shadow: 0 0 12px var(--wildcard); }
.tier-penalty  { color: var(--penalty);  text-shadow: 0 0 8px var(--penalty); }

/* === Event Banner === */
.event-banner {
  border-left: 3px solid #c8a84b;
  background: rgba(200, 168, 75, 0.08);
  padding: 0.4rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}

.event-banner .event-name {
  font-weight: 700;
  color: #c8a84b;
  margin-right: 0.5rem;
}

.event-banner .event-text {
  color: #aaa;
}

/* === End Message === */
.end-message {
  border-left: 3px solid var(--text-muted);
  padding: 0.5rem 0.75rem;
  margin: 0.75rem 0 0.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.end-message.win {
  border-left-color: var(--inferno);
}

.end-message.loss {
  border-left-color: var(--penalty);
}

.end-icon {
  font-family: monospace;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}

.end-message.win .end-icon {
  color: var(--inferno);
}

.end-message.loss .end-icon {
  color: var(--penalty);
}

.end-text {
  font-weight: 600;
  color: var(--text-main);
}

.end-stats {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.play-again-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: underline;
  margin-top: 0.1rem;
}

.play-again-link:hover {
  color: var(--text-main);
}

/* === Loading Indicator === */
/* Input/button disabled state during htmx request (via hx-disabled-elt) */
.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.player-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Blinking cursor while bouncer text span is empty (streaming in progress) */
.message-text:empty::after {
  content: '▋';
  color: var(--text-muted);
  animation: blink-cursor 1s step-end infinite;
}
@keyframes blink-cursor { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* Error message partial (inline, returned by server for 429/410) */
.error-message { color: var(--penalty); font-style: italic; }

/* === Game Responsive === */
@media (max-width: 600px) {
  .game-screen {
    border-left: none;
    border-right: none;
  }

  .game-header {
    flex-wrap: wrap;
  }

  .status-bar {
    font-size: 0.75rem;
    gap: 0.15rem 0.5rem;
    padding: 0.35rem 0.5rem;
  }

  .input-form {
    padding: 0.4rem 0.5rem;
  }

  .send-btn {
    padding: 0.3rem 0.6rem;
    min-height: 36px;
  }

  /* Prevent iOS zoom on input focus */
  .player-input {
    font-size: 16px;
  }
}
