/* ============================================
   Skorr — Professional Theme
   ============================================ */

/* --- Brand tokens --- */
:root {
  --sk-brand-from: #6366f1;
  --sk-brand-to: #06b6d4;
  --sk-brand-gradient: linear-gradient(
    135deg,
    var(--sk-brand-from),
    var(--sk-brand-to)
  );
  --sk-surface-glow: rgba(99, 102, 241, 0.06);
  --sk-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --sk-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  --sk-shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.04);
  --sk-radius: 10px;
  --sk-radius-lg: 16px;
  --sk-transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Pico overrides --- */
:root {
  --pico-block-spacing-vertical: 0.75rem;
  --pico-block-spacing-horizontal: 0.75rem;
  --pico-form-element-spacing-vertical: 0.35rem;
  --pico-form-element-spacing-horizontal: 0.5rem;
  --pico-nav-element-spacing-vertical: 0.5rem;
  --pico-nav-element-spacing-horizontal: 0.5rem;
  --pico-typography-spacing-vertical: 0.75rem;
  --pico-border-radius: var(--sk-radius);
  --pico-font-family:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

/* --- Global resets --- */
body {
  background: var(--pico-background-color);
  min-height: 100dvh;
}

/* --- Navigation --- */
nav {
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--pico-muted-border-color);
  margin-bottom: 0.5rem;
}

nav a {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

nav a strong {
  font-size: 1.1rem;
  background: var(--sk-brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-logo {
  vertical-align: middle;
  margin-right: 0;
}

/* --- Headings --- */
h1,
h2,
h3 {
  --pico-typography-spacing-vertical: 0.5rem;
}

h2 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* --- Articles / Cards --- */
article {
  padding: 1.25rem;
  border-radius: var(--sk-radius-lg);
  box-shadow: var(--sk-shadow-sm);
  border: 1px solid var(--pico-muted-border-color);
  transition: box-shadow var(--sk-transition);
}

article:hover {
  box-shadow: var(--sk-shadow-md);
}

article > header {
  padding: 0.75rem 1.25rem;
  margin: -1.25rem -1.25rem 1.25rem;
  border-radius: var(--sk-radius-lg) var(--sk-radius-lg) 0 0;
  border-bottom: 1px solid var(--pico-muted-border-color);
  background: var(--sk-surface-glow);
}

article > footer {
  padding: 0.75rem 1.25rem;
  margin: 1.25rem -1.25rem -1.25rem;
  border-radius: 0 0 var(--sk-radius-lg) var(--sk-radius-lg);
  border-top: 1px solid var(--pico-muted-border-color);
}

/* --- Tables --- */
table th,
table td {
  padding: 0.5rem 0.75rem;
}

table thead th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pico-muted-color);
  font-weight: 600;
}

/* --- Form elements (compact) --- */
button,
[type="submit"],
[type="button"],
[role="button"],
select,
input:not([type="checkbox"]):not([type="radio"]) {
  --pico-form-element-spacing-vertical: 0.3rem;
  --pico-form-element-spacing-horizontal: 0.5rem;
  padding-top: calc(var(--pico-form-element-spacing-vertical) - 2px);
}

/* Primary buttons get the brand gradient */
button[type="submit"]:not(.outline):not(.secondary),
a[role="button"]:not(.outline):not(.secondary) {
  background: var(--sk-brand-gradient);
  border-color: var(--sk-brand-from);
  transition:
    opacity var(--sk-transition),
    box-shadow var(--sk-transition);
}

button[type="submit"]:not(.outline):not(.secondary):hover,
a[role="button"]:not(.outline):not(.secondary):hover {
  opacity: 0.9;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

/* --- Home page --- */
.hero {
  text-align: center;
  padding: 2.5rem 1rem 2rem;
  margin-bottom: 1.5rem;
}

.hero-logo {
  width: 72px;
  height: 72px;
  margin-bottom: 1rem;
  filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.3));
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: var(--sk-brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

/* SK0RR wordmark with inline flap */
.skorr-wordmark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.1em;
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 0.75rem;
}

.skorr-wordmark span {
  background: var(--sk-brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.flap-digit {
  width: 0.75em;
  height: 0.95em;
  vertical-align: baseline;
  position: relative;
  top: 0.02em;
  filter: drop-shadow(0 2px 6px rgba(99, 102, 241, 0.3));
}

/* Typed description with block cursor */
.hero-typed {
  color: var(--pico-muted-color);
  font-size: 1.1rem;
  max-width: 440px;
  margin: 0 auto;
  line-height: 1.6;
  min-height: 5.3em;
}

.hero-typed::after {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 1.15em;
  background: var(--sk-brand-from);
  vertical-align: text-bottom;
  margin-left: 1px;
  animation: cursor-blink 0.7s step-end infinite;
}

@keyframes cursor-blink {
  0%,
  50% {
    opacity: 1;
  }
  51%,
  100% {
    opacity: 0;
  }
}

.hero p {
  color: var(--pico-muted-color);
  font-size: 1.1rem;
  max-width: 440px;
  margin: 0 auto;
  line-height: 1.6;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.home-grid article {
  text-align: center;
}

.home-grid article header {
  font-weight: 600;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.card-icon {
  width: 22px;
  height: 22px;
  opacity: 0.7;
}

/* --- Player dot --- */
.player-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}

.player-rank-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: middle;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

/* --- Share section --- */
.share-section {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.share-section input {
  margin-bottom: 0;
  font-family: monospace;
  font-size: 0.85rem;
}

.share-section button {
  white-space: nowrap;
  margin-bottom: 0;
  transition:
    color var(--sk-transition),
    border-color var(--sk-transition),
    background var(--sk-transition);
}

.share-section button:hover {
  color: var(--pico-primary);
  border-color: var(--pico-primary);
  background: var(--pico-primary-focus);
}

/* --- QR code --- */
.qr-container {
  text-align: center;
  margin-top: 1rem;
}

.qr-image {
  max-width: 180px;
  border-radius: var(--sk-radius);
  border: 1px solid var(--pico-muted-border-color);
  padding: 8px;
  background: white;
}

/* --- Toast notifications --- */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  pointer-events: none;
  z-index: 1000;
  max-width: 320px;
}

.toast {
  pointer-events: auto;
  background: var(--sk-brand-gradient);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--sk-radius);
  margin-bottom: 0.5rem;
  cursor: pointer;
  animation: toast-slide-fade 3.2s forwards;
  box-shadow: var(--sk-shadow-md);
  font-size: 0.9rem;
}

@keyframes toast-slide-fade {
  0% {
    opacity: 0;
    transform: translateX(20px);
  }
  8% {
    opacity: 1;
    transform: translateX(0);
  }
  70% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(20px);
  }
}

.toast:hover {
  animation-play-state: paused;
  opacity: 1 !important;
}

/* --- Scoreboard highlights --- */
.winner td {
  background: var(--sk-surface-glow);
}

.winner td:first-child {
  border-left: 3px solid var(--sk-brand-from);
}

.totals-row td {
  border-top: 2px solid var(--sk-brand-from);
  font-weight: 600;
}

.category-group-header td {
  background: var(--pico-muted-border-color);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.3rem 0.75rem;
  font-weight: 600;
}

.current-round td {
  background: var(--sk-surface-glow);
}

.current-player td,
th.current-player {
  background: var(--sk-surface-glow);
}

/* --- Scorekeeper controls --- */
.scorekeeper-controls {
  margin-bottom: 1rem;
}

.scorekeeper-controls fieldset[role="group"] {
  margin-bottom: 0;
}

/* --- Icon buttons --- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.6rem;
  line-height: 1;
}

.icon-btn svg {
  display: block;
  pointer-events: none;
}

.icon-btn:hover {
  background: var(--sk-surface-glow);
  border-color: var(--sk-brand-from);
  color: var(--sk-brand-from);
}

.score-delete-btn {
  padding: 0.1rem 0.3rem;
  margin-left: 0.5rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

.player-icon-btn {
  padding: 0.25rem;
  margin-bottom: 0;
  line-height: 1;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--sk-radius);
  background: none;
  cursor: pointer;
  color: var(--pico-muted-color);
  transition: all var(--sk-transition);
}

.player-icon-btn:hover {
  color: var(--sk-brand-from);
  border-color: var(--sk-brand-from);
  background: var(--sk-surface-glow);
}

/* --- Player crown --- */
.player-crown {
  flex-shrink: 0;
  vertical-align: middle;
  margin-right: 0.4rem;
}

/* --- WebSocket status indicator --- */
.ws-status {
  position: fixed;
  bottom: 0.5rem;
  right: 0.5rem;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  background: var(--pico-card-background-color);
  border: 1px solid var(--pico-muted-border-color);
  box-shadow: var(--sk-shadow-sm);
}

.ws-status.connected {
  color: #16a34a;
}

.ws-status.disconnected {
  color: #dc2626;
}

/* --- Utilities --- */
.input-uppercase {
  text-transform: uppercase;
}

.error-text {
  color: #dc2626;
  font-weight: 500;
}

.hidden {
  display: none;
}

.table-scroll {
  overflow: auto;
  border-radius: var(--sk-radius);
}

/* Scoreboard: vertical grid lines + no-wrap sizing */
#scoreboard table th,
#scoreboard table td {
  white-space: nowrap;
}

#scoreboard table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--pico-card-background-color);
}

/* Sticky first column */
#scoreboard table th:first-child,
#scoreboard table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--pico-card-background-color);
  box-shadow: 2px 0 0 var(--pico-muted-color);
}

#scoreboard table thead th:first-child {
  z-index: 3;
}

.table-scroll {
  overflow-x: auto;
}

#scoreboard table th + th,
#scoreboard table td + td {
  border-left: 1px solid var(--pico-muted-border-color);
  text-align: center;
}

/* Game play layout: article fills viewport, scoreboard scrolls */
.game-play {
  height: calc(100dvh - 5rem);
}

.game-play article {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.game-play article > header {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.game-play {
  min-height: 20rem;
}
.game-play #scoreboard {
  flex: 1;
  overflow: auto;
}

.game-play #scoreboard .table-scroll {
  height: 100%;
}

.game-play #score-input,
.game-play .game-controls {
  flex-shrink: 0;
}

/* Game controls: subtitle left, buttons right */
.game-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
}

.game-controls #game-subtitle {
  margin-bottom: 0;
}

.game-controls #game-status .scorekeeper-controls {
  margin-bottom: 0;
}

/* --- Lobby --- */
.lobby-action {
  margin-top: 1rem;
}

.lobby-section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--pico-muted-color);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.game-code-display {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.game-code-display kbd {
  font-size: 1rem;
  letter-spacing: 0.1em;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
}

/* --- Player list --- */
.player-list-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
}

.player-rename-form {
  display: none;
  gap: 0.25rem;
  align-items: center;
}

.player-rename-form.active {
  display: flex;
}

.player-rename-form input[type="text"] {
  margin-bottom: 0;
  padding: 0.2rem 0.4rem;
  width: auto;
}

.player-rename-form button {
  padding: 0.2rem 0.4rem;
  margin-bottom: 0;
}

/* --- Finished / Results page --- */
.results-header {
  text-align: center;
  padding-bottom: 0.5rem;
}

.results-header h2 {
  margin-bottom: 0.25rem;
}

.winner-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  border-radius: var(--sk-radius);
  background: var(--sk-brand-gradient);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 600;
  box-shadow: var(--sk-shadow-md);
}

.winner-banner .trophy {
  font-size: 1.5rem;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
}

.rank-1 {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #78350f;
}

.rank-2 {
  background: linear-gradient(135deg, #d1d5db, #9ca3af);
  color: #374151;
}

.rank-3 {
  background: linear-gradient(135deg, #fdba74, #f97316);
  color: #7c2d12;
}

.rank-other {
  background: var(--pico-muted-border-color);
  color: var(--pico-muted-color);
}

/* --- Fieldset/legend polish --- */
fieldset {
  border-radius: var(--sk-radius);
}

legend {
  font-weight: 600;
  font-size: 0.9rem;
}

/* --- Join page --- */
.join-card {
  max-width: 480px;
  margin: 2rem auto;
}

/* --- Create page --- */
.create-card {
  max-width: 560px;
  margin: 0 auto;
}

/* --- Inline cell editing --- */
.score-cell {
  cursor: pointer;
  transition: background var(--sk-transition);
}

.score-cell:hover {
  background: var(--gt-glow, var(--sk-surface-glow));
}

input.cell-input {
  width: 5rem;
  max-width: 100%;
  height: auto;
  text-align: center;
  padding: 0.2rem 0.3rem;
  margin: 0;
  margin-bottom: 0;
  font-size: inherit;
  line-height: 1.4;
  border: 2px solid var(--gt-primary, var(--sk-brand-from));
  border-radius: 4px;
  background: var(--pico-background-color);
  color: var(--pico-color);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gt-primary, var(--sk-brand-from)) 20%, transparent);
  --pico-form-element-spacing-vertical: 0;
  --pico-form-element-spacing-horizontal: 0;
}

.cell-edit-hint {
  text-align: center;
  color: var(--pico-muted-color);
  margin: 0.5rem 0 0;
}

/* --- Game Theme System --- */
.themed article > header {
  background: var(--gt-glow);
  border-bottom: 2px solid var(--gt-primary);
  position: relative;
  overflow: hidden;
}

.themed article > header h2 {
  color: var(--gt-primary);
  position: relative;
  z-index: 1;
}

.theme-watermark {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.5rem;
  opacity: 0.12;
  pointer-events: none;
  line-height: 1;
  z-index: 0;
}

.themed .totals-row td {
  border-top-color: var(--gt-primary);
}

.themed .category-group-header td {
  background: var(--gt-glow);
  color: var(--gt-primary);
  border-left: 3px solid var(--gt-primary);
}

.themed #scoreboard table thead th {
  color: var(--gt-secondary);
  border-bottom: 2px solid var(--gt-primary);
}

.themed .current-player td,
.themed th.current-player {
  background: var(--gt-glow);
}

.themed .current-round td {
  background: var(--gt-glow);
}

.themed button[type="submit"]:not(.outline):not(.secondary),
.themed a[role="button"]:not(.outline):not(.secondary) {
  background: linear-gradient(135deg, var(--gt-primary), var(--gt-secondary));
  border-color: var(--gt-primary);
}

.themed button[type="submit"]:not(.outline):not(.secondary):hover,
.themed a[role="button"]:not(.outline):not(.secondary):hover {
  box-shadow: 0 4px 14px color-mix(in srgb, var(--gt-primary) 35%, transparent);
}

.themed .winner td {
  background: var(--gt-glow);
}

.themed .winner td:first-child {
  border-left-color: var(--gt-primary);
}

.themed .winner-banner {
  background: linear-gradient(135deg, var(--gt-primary), var(--gt-secondary));
}

/* --- Responsive tweaks --- */
@media (max-width: 576px) {
  .hero h1,
  .skorr-wordmark {
    font-size: 2.2rem;
  }
  .hero p {
    font-size: 1rem;
  }
  .hero {
    padding: 1.5rem 0.5rem 1rem;
  }
  article {
    padding: 1rem;
  }
  article > header {
    padding: 0.6rem 1rem;
    margin: -1rem -1rem 1rem;
  }
  article > footer {
    margin: 1rem -1rem -1rem;
  }
}
