* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #0a66c2;
  --accent-hover: #004182;
  --path: #5bbad5;
  --number: #fff;
  --win: #57a773;
  --lose: #d45d5d;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 24px 16px;
}

#app {
  width: 100%;
  max-width: 920px;
}

header {
  margin-bottom: 14px;
}

.site-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.nav-link,
.inline-link {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.nav-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--path);
  flex-shrink: 0;
}

.nav-link-icon svg {
  width: 18px;
  height: 18px;
}

.nav-link:hover,
.inline-link:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--muted);
}

.inline-link {
  display: inline;
  padding: 0 4px;
  border: none;
  color: var(--path);
  text-decoration: underline;
  vertical-align: baseline;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.brand-logo {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.brand-text {
  text-align: left;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--muted);
  margin-top: 6px;
  font-size: 0.95rem;
  max-width: 280px;
  line-height: 1.4;
}

@media (max-width: 480px) {
  .brand {
    flex-direction: column;
    gap: 10px;
  }

  .brand-text {
    text-align: center;
  }

  .brand-logo {
    width: 64px;
    height: 64px;
  }

  .tagline {
    max-width: none;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  position: relative;
}

#lobby.panel {
  padding: 16px;
}

.hidden {
  display: none !important;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 16px;
}

input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.lobby-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.lobby-actions button {
  flex: 1;
}

.lobby-actions .play-btn {
  width: auto;
}

.challenge-panel {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.challenge-label {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.challenge-link-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.challenge-link-row input {
  flex: 1;
  margin-top: 0;
}

.home-demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 12px 0 0;
  text-align: center;
}

.home-demo-title {
  font-size: 1.15rem;
  margin-bottom: 4px;
}

.home-demo-copy {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
  margin: 0 0 10px;
}

.home-demo-video {
  max-width: min(360px, 72vw);
  width: 100%;
}

.leaderboard {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.leaderboard-title {
  font-size: 1rem;
  margin-bottom: 12px;
}

.leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.leaderboard-rank {
  width: 1.5rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  flex-shrink: 0;
}

.leaderboard-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.leaderboard-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
}

.leaderboard-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-wins {
  font-size: 0.9rem;
  color: var(--path);
  font-weight: 600;
  flex-shrink: 0;
}

.join-room {
  display: flex;
  gap: 10px;
}

.join-room input {
  flex: 1;
  margin-top: 0;
}

.status {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}

.status.error {
  color: var(--lose);
}

.play-btn {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
}

.live-pulse {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 920px;
  margin: 0 auto 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 0.95rem;
  color: var(--text);
}

.live-pulse-label {
  font-weight: 700;
  color: var(--win);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--win);
  box-shadow: 0 0 0 0 rgba(87, 167, 115, 0.55);
  animation: live-pulse 1.6s ease-out infinite;
  flex-shrink: 0;
}

@keyframes live-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(87, 167, 115, 0.55);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(87, 167, 115, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(87, 167, 115, 0);
  }
}

.queue-tease {
  text-align: center;
  margin: 0 0 16px;
  color: var(--path);
  font-size: 0.95rem;
  line-height: 1.5;
}

.home-card {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}

.home-card-title {
  font-size: 1rem;
  margin-bottom: 8px;
}

.home-card p {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 14px;
  font-size: 0.95rem;
}

.home-card .primary {
  min-width: 180px;
}

.login-google-wrap {
  display: flex;
  justify-content: center;
  margin: 16px 0 8px;
}

#google-btn-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

#user-profile,
.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 8px 0 4px;
  text-align: center;
}

.profile-avatar {
  width: 72px;
  height: 72px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.user-avatar.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.profile-avatar.avatar-fallback {
  font-size: 1.25rem;
}

.user-avatar.avatar-fallback::before {
  content: attr(data-initials);
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.profile-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.user-record {
  font-size: 0.95rem;
  color: var(--path);
  font-weight: 600;
}

.vs-record {
  font-size: 0.8rem;
  color: var(--path);
  margin-left: 6px;
}

.result-record {
  color: var(--path);
  font-weight: 600;
  margin-bottom: 20px;
}

#btn-sign-out {
  margin-top: 8px;
  min-width: 140px;
}

#room-actions {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.queue-count {
  text-align: center;
  font-size: 0.9rem;
  color: var(--path);
  font-weight: 600;
  margin-bottom: 12px;
}

#match-actions {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

#btn-cancel-queue {
  width: 100%;
  margin-top: 10px;
}

.puzzle-id {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.vs {
  font-size: 0.95rem;
}

.vs-dot {
  color: var(--muted);
  margin: 0 8px;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--path);
}

.split-screen {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 12px;
}

.board-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-title {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
  width: 100%;
}

.opponent-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 8px;
  text-align: center;
}

.opponent-panel .snake-line {
  stroke: #e07a5f;
}

.opponent-panel .snake-start {
  fill: #57a773;
}

.opponent-panel .snake-head,
.opponent-panel .snake-finish {
  fill: #f4a261;
}

.opponent-panel .cell.on-path {
  background: rgba(224, 122, 95, 0.12);
}

.opponent-panel .cell.on-path.path-head {
  box-shadow: inset 0 0 0 2px #f4a261;
}

.grid-wrap {
  display: flex;
  justify-content: center;
  touch-action: none;
  user-select: none;
  width: 100%;
}

.grid-stage {
  position: relative;
  display: inline-block;
}

.numbers-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.numbers-layer .num {
  position: absolute;
  transform: translate(-50%, -50%);
}

.path-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

.grid {
  display: grid;
  gap: 0;
  background: var(--border);
  border: 2px solid var(--border);
  border-radius: 4px;
  position: relative;
}

.opponent-panel .cell {
  width: 32px;
  height: 32px;
  cursor: default;
}

.opponent-panel .snake-line {
  stroke-width: 10;
}

.opponent-panel .num,
.opponent-panel .numbers-layer .num {
  width: 20px;
  height: 20px;
  font-size: 0.7rem;
}

@media (max-width: 720px) {
  .split-screen {
    grid-template-columns: 1fr;
  }

  .opponent-panel .cell {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 400px) {
  .you-panel .cell {
    width: 40px;
    height: 40px;
  }
}

.snake-line {
  fill: none;
  stroke: #3eb8d4;
  stroke-width: 16;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.snake-start {
  fill: #57a773;
  stroke: #fff;
  stroke-width: 2.5;
}

.snake-head {
  fill: #ffd166;
  stroke: #fff;
  stroke-width: 2.5;
  transform-origin: center;
  transform-box: fill-box;
  animation: pulse-head 1s ease-in-out infinite;
}

.snake-finish {
  fill: #ffd166;
  stroke: #57a773;
  stroke-width: 3;
}

@keyframes pulse-head {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.cell {
  width: 48px;
  height: 48px;
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  cursor: pointer;
}

.cell.on-path {
  background: rgba(62, 184, 212, 0.12);
}

.cell.on-path.path-start {
  box-shadow: inset 0 0 0 2px #57a773;
}

.cell.on-path.path-head {
  box-shadow: inset 0 0 0 2px #ffd166;
}

.cell .num,
.numbers-layer .num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--number);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wall-h,
.wall-v {
  position: absolute;
  background: var(--text);
  z-index: 5;
  pointer-events: none;
}

.wall-h {
  height: 3px;
  width: calc(100% + 4px);
  bottom: -2px;
  left: -2px;
}

.wall-v {
  width: 3px;
  height: calc(100% + 4px);
  right: -2px;
  top: -2px;
}

#result {
  text-align: center;
}

#result h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

#result h2.win {
  color: var(--win);
}

#result h2.lose {
  color: var(--lose);
}

#result-time {
  color: var(--muted);
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.result-actions button {
  flex: 1;
  min-width: 140px;
  max-width: 220px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  z-index: 1000;
}

.modal-backdrop:not(.hidden) {
  display: flex;
}

.modal {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: min(85vh, 720px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px 24px;
  margin: auto;
  text-align: center;
}

.modal-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.modal-title {
  font-size: 1.35rem;
  margin-bottom: 16px;
  width: 100%;
  text-align: center;
}

.modal-panel p {
  line-height: 1.6;
  margin-bottom: 12px;
  max-width: 34ch;
}

.modal-panel p:last-child {
  margin-bottom: 0;
}

.modal-muted {
  color: var(--muted);
  font-size: 0.95rem;
}

.rules-video {
  position: relative;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.rules-video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.about-links {
  list-style: none;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.about-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.about-link:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--muted);
}

.about-link-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
}

.about-link-icon svg {
  width: 20px;
  height: 20px;
}

.about-link-icon.linkedin {
  background: rgba(10, 102, 194, 0.18);
  color: #5ba4e8;
}

.about-link-icon.website {
  background: rgba(91, 186, 213, 0.15);
  color: var(--path);
}

.about-link-text {
  color: var(--path);
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 25, 0.82);
  border-radius: 12px;
  z-index: 10;
}

.countdown-number {
  font-size: 6rem;
  font-weight: 700;
  line-height: 1;
  color: var(--path);
  font-variant-numeric: tabular-nums;
}
