:root {
  --ink: #14171C;
  --panel: #1C2129;
  --panel-border: #2A303A;
  --marquee: #FFB347;
  --signal: #5FD4D0;
  --text: #EDEEF0;
  --text-muted: #8B93A1;
}

* { box-sizing: border-box; }

/* Author rules that set `display` (.cabinet, .gate, ...) out-specify the
   browser's built-in `[hidden] { display: none }`, which would leave hidden
   elements on screen. Make `hidden` win everywhere. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  min-height: 100%;
}

body {
  background-image:
    repeating-linear-gradient(
      0deg,
      rgba(255,255,255,0.015) 0px,
      rgba(255,255,255,0.015) 1px,
      transparent 1px,
      transparent 3px
    );
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6vh 5vw 4rem;
}

header {
  text-align: center;
  margin-bottom: 3.5rem;
}

.wordmark {
  font-family: 'Bungee', sans-serif;
  font-size: clamp(2rem, 7vw, 4rem);
  color: var(--marquee);
  text-shadow:
    0 0 8px rgba(255,179,71,0.55),
    0 0 22px rgba(255,179,71,0.25);
  letter-spacing: 0.02em;
  margin: 0;
  animation: flicker 5s infinite;
}

@keyframes flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.85; }
  98% { opacity: 1; }
  99% { opacity: 0.9; }
}

.status-line {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  color: var(--signal);
  margin-top: 0.9rem;
  letter-spacing: 0.02em;
}

.status-line::after {
  content: '_';
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

main {
  width: 100%;
  max-width: 880px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
}

main.single {
  max-width: 480px;
  grid-template-columns: 1fr;
}

/* Grid for a section's list of cards. auto-fit collapses the unused tracks so
   justify-content can centre however many cards there are, and the capped max
   track keeps a lone card card-sized rather than stretched across the page. */
main.card-grid {
  max-width: 1100px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 280px));
  justify-content: center;
}

.cabinet {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.cabinet:hover,
.cabinet:focus-within {
  border-color: var(--signal);
  transform: translateY(-2px);
}

.cabinet-header {
  background: linear-gradient(180deg, rgba(255,179,71,0.14), transparent);
  border-bottom: 1px solid var(--panel-border);
  padding: 0.85rem 1.1rem;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.cabinet-screen {
  flex: 1;
  padding: 1.4rem 1.1rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.cabinet-screen p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.tag {
  align-self: flex-start;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--signal);
  border: 1px solid rgba(95,212,208,0.35);
  padding: 0.2rem 0.55rem;
  border-radius: 3px;
}

.cabinet a.enter {
  margin-top: auto;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  color: var(--marquee);
  text-decoration: none;
  border-top: 1px solid var(--panel-border);
  padding-top: 0.8rem;
}

.cabinet a.enter:hover,
.cabinet a.enter:focus-visible {
  color: var(--signal);
}

/* --- game start screen --- */

.start-screen {
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 2.5rem 1.1rem;
}

/* One button per game, stacked and centred as more are added. */
.game-list {
  align-items: center;
  gap: 1rem;
  padding: 2rem 1.1rem;
}

/* Works as both a <button> and an <a> (games link out to their own pages). */
.play-btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  font-family: 'Bungee', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--marquee);
  border: none;
  border-radius: 6px;
  padding: 0.7rem 2.6rem;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(255, 179, 71, 0.35);
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.play-btn:hover,
.play-btn:focus-visible {
  background: var(--signal);
  transform: translateY(-2px);
  box-shadow: 0 0 22px rgba(95, 212, 208, 0.45);
}

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

/* --- team picker --- */

.team-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 0.6rem 0 0.2rem;
}

.team-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

.team-label {
  font-family: 'Bungee', sans-serif;
  font-size: 1.3rem;
  color: var(--marquee);
  margin: 0;
  letter-spacing: 0.04em;
}

.team-square {
  width: 130px;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.5rem;
  background: var(--ink);
  border: 2px solid var(--signal);
  border-radius: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  overflow-wrap: anywhere;
}

.team-arrows {
  display: flex;
  gap: 0.6rem;
}

.team-arrows button {
  width: 46px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.team-arrows button:hover,
.team-arrows button:focus-visible {
  color: var(--signal);
  border-color: var(--signal);
}

.team-middle {
  display: flex;
  justify-content: center;
  flex: 1 1 auto;
}

/* Stack the two sides once there isn't room for three columns. */
@media (max-width: 520px) {
  .team-picker {
    justify-content: center;
  }

  .team-middle {
    order: 1;
    flex-basis: 100%;
  }
}

/* Same footprint as a.enter, for cards that aren't clickable yet. */
.cabinet .enter-note {
  margin-top: auto;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--panel-border);
  padding-top: 0.8rem;
}

a:focus-visible,
.cabinet:focus-within {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

footer {
  margin-top: 4rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .wordmark,
  .status-line::after {
    animation: none;
  }
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--ink);
}

.gate[hidden] {
  display: none;
}

.gate-box {
  width: 100%;
  max-width: 320px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 2rem 1.75rem;
  text-align: center;
}

.gate-title {
  font-family: 'Bungee', sans-serif;
  font-size: 1.6rem;
  color: var(--marquee);
  text-shadow:
    0 0 8px rgba(255,179,71,0.55),
    0 0 22px rgba(255,179,71,0.25);
  margin: 0 0 0.5rem;
}

.gate-box .status-line {
  font-size: 0.8rem;
  margin-top: 0;
  margin-bottom: 1.5rem;
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.gate-form input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 0.7rem 0.75rem;
}

.gate-form input:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.gate-form button {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--signal);
  border: none;
  border-radius: 4px;
  padding: 0.7rem 0.75rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.gate-form button:hover,
.gate-form button:focus-visible {
  background: var(--marquee);
}

.gate-error {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: var(--marquee);
  margin: 0.9rem 0 0;
}

.gate-success {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: var(--signal);
  margin: 0.9rem 0 0;
}

.gate-warning {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text-muted);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
  margin: 1rem 0 0;
  text-align: left;
}

.gate-switch {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.4rem;
  background: none;
  border: none;
  color: var(--signal);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  cursor: pointer;
}

.gate-switch:hover,
.gate-switch:focus-visible {
  color: var(--marquee);
  text-decoration: underline;
}

/* --- signed-in header bar --- */

.userbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 2rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.userbar-btn {
  background: none;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: inherit;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

.userbar-btn:hover,
.userbar-btn:focus-visible {
  color: var(--signal);
  border-color: var(--signal);
}

/* --- chat: room list --- */

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.room-list a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1rem;
  background: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.room-list a:hover,
.room-list a:focus-visible {
  border-color: var(--signal);
  color: var(--signal);
}

.room-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.empty-note {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

/* --- chat: composer + messages --- */

.compose {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.4rem;
}

.compose input {
  flex: 1;
  min-width: 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 0.6rem 0.7rem;
}

.compose input:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.compose button {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--signal);
  border: none;
  border-radius: 4px;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.compose button:hover:not(:disabled),
.compose button:focus-visible {
  background: var(--marquee);
}

.compose button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Vertical variant for forms with more than one field. */
.compose-stack {
  flex-direction: column;
  align-items: stretch;
}

.message-list {
  list-style: none;
  margin: 0 0 1.2rem;
  padding: 0.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-height: 55vh;
  overflow-y: auto;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.message-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
}

.message-author {
  color: var(--marquee);
  font-weight: 500;
}

.message.is-mine .message-author {
  color: var(--signal);
}

.message-time {
  color: var(--text-muted);
}

.message-text {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* --- creator-only delete controls --- */

.message-delete {
  margin-left: auto;
  background: none;
  border: none;
  padding: 0 0.2rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.message:hover .message-delete,
.message-delete:focus-visible {
  opacity: 1;
}

.message-delete:hover,
.message-delete:focus-visible {
  color: #ff6b6b;
}

.message-delete:disabled {
  opacity: 0.4;
  cursor: default;
}

.danger-btn {
  align-self: flex-start;
  margin-top: 0.4rem;
  background: none;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 0.45rem 0.8rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.danger-btn:hover,
.danger-btn:focus-visible {
  color: #ff6b6b;
  border-color: #ff6b6b;
}

.danger-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* --- wide single-column layout for chat pages --- */

main.wide {
  max-width: 640px;
  grid-template-columns: 1fr;
}

/* --- join-code reveal after creating a chat --- */

.code-reveal {
  margin-top: 1.1rem;
  padding: 1rem;
  background: var(--ink);
  border: 1px solid var(--signal);
  border-radius: 4px;
  text-align: left;
}

.code-reveal p {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--text);
}

.code-reveal p:last-child {
  margin: 0;
}

.code-reveal strong {
  color: var(--marquee);
}
