:root {
  --bg: #f4f4f4;
  --bg-accent: #ebebeb;
  --ink: #0a0a0a;
  --muted: #6b6b6b;
  --line: rgba(0, 0, 0, 0.1);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.06);
  --shadow-soft: 0 1px 0 rgba(255, 255, 255, 0.8) inset, 0 8px 22px rgba(0, 0, 0, 0.04);
  --radius: 18px;
  --radius-sm: 12px;
  --ok: #111111;
  --warn: #333333;
  --live: #111111;
  --empty: #e4e4e4;
  --empty-hover: #d4d4d4;
  --font: "Inter", system-ui, sans-serif;
  --display: "Inter", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1000px 520px at 8% -8%, #ffffff 0%, transparent 55%),
    radial-gradient(800px 480px at 100% 0%, #f0f0f0 0%, transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
}

button,
input {
  font: inherit;
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-logo {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1;
  color: var(--ink);
}

.brand-sub,
.panel-copy,
.empty-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-copy.tight {
  margin-top: 2px;
  font-size: 0.8rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--line);
}

.pill-muted {
  color: var(--muted);
}

.pill-live {
  color: #111;
  background: #f0f0f0;
  border-color: rgba(0, 0, 0, 0.16);
}

.app-shell.is-cooling .cell {
  cursor: not-allowed;
}

.app-shell.is-cooling .cell:hover {
  transform: none;
}

.cell.show-cooldown-timer {
  z-index: 5;
}

.cell.show-cooldown-timer .cell-timer {
  opacity: 1;
  visibility: visible;
}

.cell-timer {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  font-size: clamp(0.7rem, 2vw, 0.95rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: #111;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.cell.is-shaking {
  transition: none !important;
  animation: cell-shake 220ms ease-in-out;
}

@keyframes cell-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-2px);
  }
  50% {
    transform: translateX(2px);
  }
  75% {
    transform: translateX(-1px);
  }
}

.you-chip,
.leader-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.you-chip {
  padding: 7px 12px 7px 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 0.9rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--you, #888);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--you, #888) 18%, white);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.side-stack {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel-head.compact {
  margin-bottom: 12px;
}

.panel-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.panel-title.sm {
  font-size: 1.05rem;
  font-weight: 650;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.dot.empty {
  background: var(--empty);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.dot.yours {
  background: #111;
}

.dot.taken {
  background: #9a9a9a;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, #fafafa, #f2f2f2);
  border: 1px solid var(--line);
}

.cell {
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: 7px;
  cursor: pointer;
  background: var(--empty);
  position: relative;
  transition:
    transform 120ms ease,
    box-shadow 160ms ease,
    background 160ms ease,
    filter 160ms ease;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.cell:hover {
  transform: translateY(-1px) scale(1.04);
  background: var(--empty-hover);
  z-index: 1;
}

.cell:not(.is-empty) {
  background: color-mix(in srgb, var(--owner, #888) 88%, white);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--owner, #888) 40%, transparent),
    0 3px 8px rgba(0, 0, 0, 0.08);
}

.cell.is-mine {
  outline: none;
}

.cell.is-flash {
  animation: flash 650ms ease;
}

.cell-inner {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.cell.htmx-request {
  filter: brightness(0.92);
  cursor: wait;
}

@keyframes flash {
  0% {
    transform: scale(1);
    filter: brightness(1.35);
  }
  55% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.stat-value {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.leader-row {
  width: 100%;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
}

.rank {
  width: 18px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.leader-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
}

.leader-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.profile-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  border: 0;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.field input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
}

.field input[type="text"]:focus {
  outline: 2px solid rgba(0, 0, 0, 0.18);
  border-color: rgba(0, 0, 0, 0.35);
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.color-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.color-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.color-chip {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--chip);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.color-option input:checked + .color-chip {
  box-shadow:
    0 0 0 2px #fff,
    0 0 0 4px #111;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: #111;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
  opacity: 0.92;
}

.form-error {
  margin: 0;
  color: #111;
  font-size: 0.85rem;
  font-weight: 600;
}

.form-ok {
  margin: 0;
  color: var(--ok);
  font-size: 0.85rem;
  font-weight: 600;
}

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 40;
  width: min(320px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(17, 17, 17, 0.94);
  color: #fff;
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  animation: toast-in 220ms ease, toast-out 280ms ease 2.5s forwards;
}

.toast-ok {
  background: rgba(17, 17, 17, 0.94);
}

.toast-warn {
  background: rgba(55, 55, 55, 0.96);
}

.toast-live .swatch {
  flex-shrink: 0;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(4px);
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .grid {
    gap: 6px;
  }

  .cell {
    border-radius: 5px;
  }

  .color-row {
    gap: 8px;
  }

  .color-option {
    width: 48px;
    height: 48px;
  }

  .color-chip {
    width: 32px;
    height: 32px;
  }
}