/* Big Chess 2×2 — shared design system. */

:root {
  --bg: #0b0d13;
  --bg-soft: #10131c;
  --panel: #161a26;
  --panel-2: #1c2130;
  --panel-3: #232939;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #e9ecf5;
  --muted: #9aa3b8;
  --faint: #6b7488;
  --accent: #f2c76e;
  --accent-strong: #ffd98a;
  --accent-ink: #1a1405;
  --danger: #ef6b6b;
  --danger-soft: rgba(239, 107, 107, 0.12);
  --success: #5fd08a;
  --success-soft: rgba(95, 208, 138, 0.12);
  --team-a: #4a90e2;
  --team-b: #e2574a;
  --p1: #4a90e2;
  --p2: #e2574a;
  --p3: #e2954a;
  --p4: #50c878;
  --light-square: #eddcbc;
  --dark-square: #b58863;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --header-h: 68px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scrollbar-color: #343b4d var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(1100px 540px at 82% -12%, rgba(74, 144, 226, 0.15), transparent 60%),
    radial-gradient(900px 520px at 6% 4%, rgba(242, 199, 110, 0.09), transparent 55%),
    var(--bg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5em;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.015em;
}

h1 {
  font-size: clamp(2.1rem, 4.6vw, 3.6rem);
}

h2 {
  font-size: clamp(1.35rem, 2.4vw, 1.8rem);
}

h3 {
  font-size: 1.05rem;
}

p {
  margin: 0 0 1em;
}

.lead {
  max-width: 34em;
  color: var(--muted);
  font-size: clamp(1rem, 1.35vw, 1.12rem);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(95, 208, 138, 0.14);
  animation: pulse-dot 1.8s ease-in-out infinite;
}

code,
.mono {
  font-family: var(--mono);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

::selection {
  background: rgba(242, 199, 110, 0.32);
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: 0 0 10px 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- layout ---------- */

.view {
  min-height: 100vh;
}

.container {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.narrow {
  width: min(520px, calc(100% - 40px));
  margin: 0 auto;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row-wrap {
  flex-wrap: wrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.spacer {
  flex: 1;
}

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

.faint {
  color: var(--faint);
}

.small {
  font-size: 0.86rem;
}

.tiny {
  font-size: 0.76rem;
}

.nowrap {
  white-space: nowrap;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 clamp(16px, 4vw, 34px);
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 19, 0.78);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  font-size: 1.02rem;
}

.brand:hover {
  color: var(--text);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(145deg, #2a3145, #171b27);
  border: 1px solid var(--border-strong);
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.brand-sub {
  display: block;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.nav-link {
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}

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

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.88rem;
  font-weight: 600;
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(140deg, #3b4560, #222838);
  border: 1px solid var(--border-strong);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  flex: none;
}

.avatar.lg {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

/* ---------- buttons ---------- */

.btn {
  --btn-bg: var(--panel-2);
  --btn-border: var(--border);
  --btn-text: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 11px 18px;
  border-radius: 11px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-text);
  font-weight: 700;
  font-size: 0.94rem;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  text-align: center;
  white-space: nowrap;
}

.btn:hover {
  background: color-mix(in srgb, var(--btn-bg) 82%, white 18%);
  color: var(--btn-text);
}

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

.btn[disabled],
.btn.is-busy {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  --btn-bg: linear-gradient(150deg, var(--accent-strong), var(--accent));
  --btn-border: transparent;
  --btn-text: var(--accent-ink);
  box-shadow: 0 10px 28px rgba(242, 199, 110, 0.18);
}

.btn-primary:hover {
  background: linear-gradient(150deg, #ffe4a6, #f5cd7c);
  color: var(--accent-ink);
}

.btn-ghost {
  --btn-bg: transparent;
  --btn-border: var(--border);
  --btn-text: var(--muted);
}

.btn-ghost:hover {
  --btn-text: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.btn-danger {
  --btn-bg: var(--danger-soft);
  --btn-border: rgba(239, 107, 107, 0.35);
  --btn-text: #ffb3b3;
}

.btn-danger:hover {
  background: rgba(239, 107, 107, 0.22);
  color: #ffd0d0;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
}

/* ---------- cards & chips ---------- */

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 40%), var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad {
  padding: clamp(18px, 2.4vw, 28px);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.chip-waiting {
  color: var(--accent);
  border-color: rgba(242, 199, 110, 0.28);
  background: rgba(242, 199, 110, 0.09);
}

.chip-playing {
  color: var(--success);
  border-color: rgba(95, 208, 138, 0.3);
  background: var(--success-soft);
}

.chip-playing::before {
  animation: pulse-dot 1.6s ease-in-out infinite;
}

.chip-finished {
  color: var(--faint);
}

.chip-error {
  color: #ffb3b3;
  border-color: rgba(239, 107, 107, 0.35);
  background: var(--danger-soft);
}

.chip-team-a {
  color: var(--team-a);
  border-color: rgba(74, 144, 226, 0.35);
  background: rgba(74, 144, 226, 0.1);
}

.chip-team-b {
  color: var(--team-b);
  border-color: rgba(226, 87, 74, 0.35);
  background: rgba(226, 87, 74, 0.1);
}

.chip-neutral {
  color: var(--muted);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 16px;
}

.field > label,
.label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.input,
.select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0e1119;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: #5c657a;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: rgba(242, 199, 110, 0.6);
  box-shadow: 0 0 0 3px rgba(242, 199, 110, 0.12);
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 52%, calc(100% - 14px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

.form-error {
  display: none;
  padding: 10px 13px;
  margin-bottom: 14px;
  border-radius: 9px;
  border: 1px solid rgba(239, 107, 107, 0.35);
  background: var(--danger-soft);
  color: #ffc2c2;
  font-size: 0.88rem;
}

.form-error.is-visible {
  display: block;
}

.form-hint {
  color: var(--faint);
  font-size: 0.8rem;
}

/* ---------- dialogs ---------- */

dialog.modal {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog.modal::backdrop {
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(4px);
}

.modal-body {
  padding: 24px;
}

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

.modal-head h2 {
  margin: 0;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ---------- toast ---------- */

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 15px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: rgba(24, 28, 40, 0.96);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.22s ease both;
  pointer-events: auto;
}

.toast.is-leaving {
  animation: toast-out 0.18s ease both;
}

.toast::before {
  content: "";
  width: 4px;
  border-radius: 4px;
  align-self: stretch;
  background: var(--accent);
  flex: none;
}

.toast-error::before {
  background: var(--danger);
}

.toast-success::before {
  background: var(--success);
}

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

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

/* ---------- connection & boot ---------- */

.conn-badge {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 110;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(22, 26, 38, 0.94);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.conn-badge[data-state="offline"] .conn-dot {
  background: var(--danger);
  animation: none;
}

.app-version {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(15, 17, 23, 0.72);
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  pointer-events: none;
  user-select: none;
}

@media (max-width: 700px) {
  .app-version {
    right: 10px;
    bottom: 10px;
    font-size: 0.6rem;
  }
}

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.boot-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-logo {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 22px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(145deg, #232a3b, #12151f);
  color: var(--accent);
  font-size: 42px;
  animation: boot-float 2.2s ease-in-out infinite;
}

.boot-text {
  color: var(--muted);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
}

@keyframes boot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text);
  padding: 24px;
  text-align: center;
}

/* ---------- seats / teams (shared) ---------- */

.seat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  min-width: 0;
}

.seat.is-you {
  border-color: rgba(242, 199, 110, 0.4);
  background: rgba(242, 199, 110, 0.06);
}

.seat.is-empty {
  border-style: dashed;
  color: var(--faint);
}

.seat.is-dead {
  opacity: 0.55;
}

.seat-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.seat-name {
  font-weight: 600;
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-role {
  font-size: 0.7rem;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.seat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.seat-dot.is-online {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(95, 208, 138, 0.16);
}

.team-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.015);
}

.team-block + .team-block {
  margin-top: 10px;
}

.team-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.team-block .seat + .seat {
  margin-top: 6px;
}

/* ---------- empty states / misc ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 44px 22px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-icon {
  font-size: 44px;
  line-height: 1;
  color: var(--faint);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 18px 0;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  flex: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 0.78rem;
}

@media (max-width: 720px) {
  .topbar {
    gap: 12px;
    padding: 0 14px;
  }

  .brand-sub {
    display: none;
  }

  .nav-link {
    padding: 7px 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
