:root {
  color-scheme: dark;
  --background: #100b22;
  --surface: rgba(30, 22, 58, 0.91);
  --surface-strong: #211743;
  --border: rgba(255, 255, 255, 0.13);
  --text: #f8f7ff;
  --muted: #aea7c7;
  --accent: #8c6cff;
  --accent-strong: #6847e7;
  --cyan: #56d8ff;
  --danger: #ff6b7a;
  --success: #4de29a;
  --warning: #ffd85d;
  --board-light: #e8def8;
  --board-dark: #7657a8;
  --highlight: rgba(86, 216, 255, 0.55);
  --last-move: rgba(255, 222, 89, 0.4);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 18% 0%, rgba(109, 77, 241, 0.3), transparent 32rem),
    radial-gradient(circle at 95% 18%, rgba(86, 216, 255, 0.14), transparent 28rem),
    var(--background);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.eyebrow {
  margin: 0;
  color: var(--cyan);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.16em;
}

.home-screen,
.loading-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.home-card {
  width: min(960px, 100%);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: clamp(24px, 5vw, 48px);
  background: var(--surface);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

.brand-mark {
  display: grid;
  width: 62px;
  height: 62px;
  margin-bottom: 18px;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  font-size: 2.5rem;
  box-shadow: 0 15px 45px rgba(109, 77, 241, 0.42);
}

.home-card h1,
.topbar h1 {
  margin: 5px 0 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1;
}

.lead {
  max-width: 720px;
  margin: 18px 0 28px;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.65;
}

.link-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  padding: 0 12px;
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(86, 216, 255, 0.12);
}

.generated-links {
  margin-top: 26px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.text-button {
  padding: 5px;
  background: transparent;
  color: var(--cyan);
  cursor: pointer;
}

.link-grid {
  display: grid;
  gap: 10px;
}

.link-card {
  display: grid;
  grid-template-columns: 48px minmax(120px, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.link-card > div:nth-child(2) {
  display: grid;
  gap: 2px;
}

.link-card span,
.link-card code {
  color: var(--muted);
  font-size: 0.74rem;
}

.link-card code {
  grid-column: 2 / -1;
  overflow-wrap: anywhere;
}

.link-icon {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-strong);
  font-size: 1.8rem;
}

.how-it-works {
  margin-top: 26px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.how-it-works h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.how-it-works p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  padding: 9px 13px;
  color: var(--text);
  font-weight: 760;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 120ms ease,
    filter 120ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.secondary-button {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
}

.danger-button {
  border: 1px solid rgba(255, 107, 122, 0.36);
  background: rgba(255, 107, 122, 0.19);
  color: #ffdadd;
}

.topbar {
  display: flex;
  max-width: 1180px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  margin: 0 auto;
  padding: 24px 24px 14px;
}

.room-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.role-pill,
.connection-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.05);
}

.connection-pill.connected {
  color: var(--success);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(300px, 760px) minmax(270px, 340px);
  gap: 24px;
  max-width: 1180px;
  align-items: start;
  margin: 0 auto;
  padding: 10px 24px 36px;
}

.board-column {
  min-width: 0;
}

.board-frame {
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 12px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02)),
    var(--surface-strong);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.38);
}

.chessboard {
  display: grid;
  width: min(100%, 720px);
  aspect-ratio: 1;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  overflow: hidden;
  margin: 0 auto;
  border-radius: 12px;
}

.square {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  place-items: center;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  user-select: none;
}

.square.light {
  background: var(--board-light);
}

.square.dark {
  background: var(--board-dark);
}

.square.last-move::after,
.square.selected::after {
  position: absolute;
  z-index: 1;
  inset: 0;
  content: "";
  pointer-events: none;
}

.square.last-move::after {
  background: var(--last-move);
}

.square.selected::after {
  box-shadow: inset 0 0 0 5px var(--highlight);
}

.piece {
  position: relative;
  z-index: 2;
  display: block;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
  font-size: clamp(1.9rem, 6.2vw, 4.9rem);
  line-height: 1;
  cursor: grab;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.25));
}

.piece.white {
  color: #fffdf4;
  text-shadow:
    -1px -1px 0 #252033,
    1px -1px 0 #252033,
    -1px 1px 0 #252033,
    1px 1px 0 #252033;
}

.piece.black {
  color: #1c1628;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.18);
}

.coordinate {
  position: absolute;
  z-index: 3;
  color: rgba(20, 14, 35, 0.66);
  font-size: clamp(0.48rem, 1.1vw, 0.72rem);
  font-weight: 900;
  pointer-events: none;
}

.file-coordinate {
  right: 4px;
  bottom: 2px;
}

.rank-coordinate {
  top: 2px;
  left: 4px;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 2px;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 10px 14px;
}

.player-card.active {
  border-color: rgba(86, 216, 255, 0.5);
  background: rgba(86, 216, 255, 0.08);
}

.player-card > div:last-child {
  display: grid;
  gap: 1px;
}

.player-card strong {
  font-size: 1rem;
}

.player-piece {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-strong);
  font-size: 1.8rem;
}

.player-label,
.connection-state {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.connection-state.online {
  color: var(--success);
}

.game-panel {
  display: grid;
  position: sticky;
  top: 14px;
  gap: 14px;
}

.status-card,
.history-card,
.viewer-card,
.notice-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  backdrop-filter: blur(18px);
}

.status-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.status-card > div {
  display: grid;
  gap: 3px;
}

.status-label {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.status-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 18px currentColor;
}

.status-card.playing .status-dot {
  color: var(--success);
  background: var(--success);
}

.status-card.waiting .status-dot,
.status-card.paused .status-dot {
  color: var(--warning);
  background: var(--warning);
}

.status-card.ended .status-dot {
  color: var(--accent);
  background: var(--accent);
}

.notice-card {
  display: grid;
  gap: 4px;
  padding: 13px 15px;
}

.notice-card span {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.notice-card.warning {
  border-color: rgba(255, 216, 93, 0.35);
}

.notice-card.success {
  border-color: rgba(77, 226, 154, 0.35);
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.history-card {
  overflow: hidden;
}

.history-card .section-heading {
  margin: 0;
  border-bottom: 1px solid var(--border);
  padding: 14px 15px 10px;
}

.history-card .section-heading span {
  color: var(--muted);
  font-size: 0.72rem;
}

.move-list {
  max-height: 270px;
  overflow-y: auto;
  padding: 8px;
}

.move-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 8px;
  border-radius: 8px;
  padding: 7px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
}

.move-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.04);
}

.move-number,
.empty-history {
  color: var(--muted);
}

.empty-history {
  margin: 0;
  padding: 18px 10px;
  text-align: center;
}

.viewer-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

.viewer-card > div {
  display: grid;
  gap: 3px;
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  text-align: center;
}

.viewer-card > div:last-child {
  border-right: 0;
}

.viewer-card span {
  color: var(--muted);
  font-size: 0.62rem;
  text-transform: uppercase;
}

.viewer-card strong {
  font-size: 1.1rem;
}

.loading-screen {
  text-align: center;
}

.loading-screen h1 {
  margin-bottom: 8px;
}

.loading-screen p {
  color: var(--muted);
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  max-width: min(380px, calc(100vw - 40px));
  border: 1px solid rgba(77, 226, 154, 0.45);
  border-radius: 12px;
  padding: 12px 16px;
  background: #163b31;
  color: #e5fff4;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.error {
  border-color: rgba(255, 107, 122, 0.5);
  background: #4d1d29;
  color: #ffe6e9;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

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

  .game-panel {
    position: static;
  }

  .link-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .topbar {
    display: grid;
    gap: 12px;
  }

  .room-meta {
    justify-content: flex-start;
  }

  .game-layout,
  .topbar {
    padding-right: 12px;
    padding-left: 12px;
  }

  .board-frame {
    border-radius: 15px;
    padding: 7px;
  }

  .link-card {
    grid-template-columns: 44px 1fr;
  }

  .link-card .primary-button,
  .link-card .secondary-button {
    grid-column: auto;
  }

  .link-card code {
    grid-column: 1 / -1;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .viewer-card {
    grid-template-columns: 1fr;
  }

  .viewer-card > div {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .viewer-card > div:last-child {
    border-bottom: 0;
  }
}

.link-form.single-field {
  grid-template-columns: 1fr auto;
}

.game-switch {
  width: fit-content;
  margin: -8px 0 24px;
}
