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

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

:root {
  --board-max-size: clamp(240px, min(98vmin, calc(100vh - 1.5rem)), 1560px);
}

a {
  color: inherit;
  text-decoration: none;
}

.landing {
  max-width: 960px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
  text-align: center;
}

.landing h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.landing p {
  max-width: 640px;
  margin: 0 auto 2rem;
  line-height: 1.5;
}

.actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  padding: 0.75rem 1.75rem;
  border-radius: 0.75rem;
  background: #38bdf8;
  color: #0f172a;
  font-weight: 600;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn.secondary {
  background: #a855f7;
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 2rem;
  max-width: min(96vw, 1800px);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.layout-play {
  width: 100%;
  max-width: none;
}

.layout-play--session {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 4rem 1.5rem;
}

.layout-play--session .panel {
  width: min(100%, 420px);
}

.layout-play--game {
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100vh;
  padding: 2rem clamp(1.25rem, 4vw, 3rem);
}

.layout-play--game #game-panel {
  width: 100%;
  max-width: none;
}

.board-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  align-items: stretch;
  gap: 2rem;
  width: 100%;
  min-height: calc(100vh - 4rem);
}

.board-layout__board {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.board-layout__board .board-wrapper {
  width: 100%;
}

.board-surface {
  width: min(100%, var(--board-max-size));
  max-width: var(--board-max-size);
  height: min(100%, var(--board-max-size));
  max-height: var(--board-max-size);
  aspect-ratio: 1 / 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-layout__sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  height: 100%;
  align-self: stretch;
}

.board-layout__sidebar .board-toolbar {
  gap: 0.75rem;
}

.board-layout__sidebar .status-bar {
  margin-top: auto;
}

.panel {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 16px 40px -20px rgba(15, 23, 42, 0.8);
  transition: transform 0.4s ease, opacity 0.4s ease;
}

#session-panel.collapsed {
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
}

.panel h2 {
  margin-top: 0;
  font-size: 1.3rem;
}

.panel label {
  display: block;
  font-size: 0.85rem;
  color: #cbd5f5;
  margin-bottom: 0.25rem;
}

.panel input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.6);
  color: inherit;
  margin-bottom: 0.75rem;
}

.panel button {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border-radius: 0.6rem;
  border: none;
  background: #38bdf8;
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
}

.panel button.secondary {
  background: #a855f7;
  margin-top: 0.4rem;
}

.panel button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pin-display {
  margin-bottom: 1.5rem;
  padding: 1rem;
  border-radius: 0.8rem;
  background: rgba(148, 163, 184, 0.12);
}

.pin-value {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.45rem;
  margin: 0.75rem 0 0.25rem;
}

.share-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0 0.25rem;
}

.share-btn {
  padding: 0.55rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.6);
  color: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.share-btn:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.45);
}

.share-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.share-feedback {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  color: #fbbf24;
  min-height: 1em;
}

.share-feedback.error {
  color: #f87171;
}

.hint {
  font-size: 0.8rem;
  color: rgba(226, 232, 240, 0.8);
  margin: 0.4rem 0 0;
}

.join-section {
  margin-top: 1.25rem;
}

.board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.board-toolbar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: stretch;
}

.toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.6rem;
  border: none;
  background: rgba(148, 163, 184, 0.2);
  color: #e2e8f0;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.toggle-btn.enabled {
  background: #38bdf8;
  color: #0f172a;
}

.toggle-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.spectator-status {
  font-size: 0.75rem;
  color: rgba(226, 232, 240, 0.75);
}

.board-container {
  position: relative;
  width: min(100%, var(--board-max-size));
  max-width: var(--board-max-size);
  aspect-ratio: 1 / 1;
  --board-padding: clamp(1rem, 3vw, 1.6rem);
  margin: 0 auto;
}

.board {
  position: absolute;
  inset: var(--board-padding);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 1.2rem;
  overflow: hidden;
  border: 2px solid rgba(56, 189, 248, 0.4);
  background: #1e293b;
  width: auto;
  height: auto;
}

.board-file-labels,
.board-rank-labels {
  position: absolute;
  pointer-events: none;
  font-size: clamp(0.55rem, 1.4vw, 0.7rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(226, 232, 240, 0.65);
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.85);
}

.board-file-labels {
  left: var(--board-padding);
  right: var(--board-padding);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
}

.board-file-labels--top {
  top: calc(var(--board-padding) * 0.35);
}

.board-file-labels--bottom {
  bottom: calc(var(--board-padding) * 0.35);
}

.board-file-label {
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-rank-labels {
  top: var(--board-padding);
  bottom: var(--board-padding);
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  gap: 0.25rem;
}

.board-rank-labels--left {
  left: calc(var(--board-padding) * 0.35);
}

.board-rank-labels--right {
  right: calc(var(--board-padding) * 0.35);
}

.board-rank-label {
  display: flex;
  justify-content: center;
  align-items: center;
}

.square {
  position: relative;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  z-index: 0;
}

.square::before {
  content: "";
  position: absolute;
  inset: 0.2rem;
  border-radius: 0.85rem;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.square::after {
  content: "";
  position: absolute;
  inset: 0.15rem;
  border-radius: 0.85rem;
  border: 2px solid transparent;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 0;
}

.square.knowledge-certain::after {
  opacity: 1;
  transform: scale(1);
  border-color: rgba(250, 204, 21, 0.75);
  background: radial-gradient(
      circle at 50% 50%,
      rgba(250, 204, 21, 0.38) 0%,
      rgba(250, 204, 21, 0.16) 52%,
      transparent 78%
    );
  box-shadow: 0 0 14px rgba(250, 204, 21, 0.22);
}

.square.knowledge-possible::after {
  opacity: 1;
  transform: scale(1);
  border: 2px dashed rgba(56, 189, 248, 0.66);
  background: rgba(56, 189, 248, 0.14);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.18);
}

.square .piece,
.square .note,
.square .marker,
.square .origin-hints {
  position: relative;
  z-index: 1;
}

.square .marker {
  z-index: 2;
}

.square.origin-shared::before {
  opacity: 1;
  background: linear-gradient(
      145deg,
      var(--origin-highlight, rgba(148, 163, 184, 0.38)) 0%,
      rgba(15, 23, 42, 0.02) 65%,
      transparent 100%
    );
  box-shadow: inset 0 0 0 1px var(--origin-highlight, rgba(148, 163, 184, 0.4));
}

.square.light {
  background: rgba(148, 163, 184, 0.18);
}

.square.dark {
  background: rgba(30, 41, 59, 0.75);
}

.piece {
  font-size: clamp(1.4rem, 3.2vw, 2.2rem);
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.8));
}

.piece-white {
  color: #f8fafc;
}

.piece-black {
  color: #facc15;
}

.piece-unknown {
  color: rgba(226, 232, 240, 0.65);
}

.captured-tray {
  width: min(100%, var(--board-max-size));
  max-width: var(--board-max-size);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  min-height: 1.75rem;
  flex-wrap: wrap;
  transition: background 0.2s ease, border 0.2s ease, padding 0.2s ease;
}

.captured-tray:not(:empty) {
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.captured-tray--opponent:not(:empty) {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.35);
}

.captured-tray--own:not(:empty) {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.35);
}

.captured-piece {
  font-size: clamp(1.1rem, 2.8vw, 1.6rem);
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(15, 23, 42, 0.8));
}

.captured-piece--white {
  color: #f8fafc;
}

.captured-piece--black {
  color: #facc15;
}

.marker {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  align-items: center;
  justify-content: center;
  pointer-events: none;
  width: clamp(1.3rem, 3vw, 1.8rem);
  height: clamp(1.3rem, 3vw, 1.8rem);
  border-radius: 999px;
  background: rgba(226, 232, 240, 0.95);
  color: #0f172a;
  font-size: clamp(0.75rem, 1.8vw, 0.9rem);
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid rgba(148, 163, 184, 0.45);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.35);
  text-shadow: none;
  white-space: nowrap;
  display: none;
}

.marker-hidden {
  display: none;
}

.marker-explicit {
  display: inline-flex;
}

.marker-explicit[data-marker="dot"] {
  width: clamp(1rem, 2.4vw, 1.3rem);
  height: clamp(1rem, 2.4vw, 1.3rem);
  font-size: clamp(0.65rem, 1.6vw, 0.75rem);
  font-weight: 700;
}

.note {
  position: absolute;
  bottom: 0.35rem;
  right: 0.35rem;
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  font-size: 0.75rem;
  color: rgba(226, 232, 240, 0.95);
}

.square.unknown {
  box-shadow: inset 0 0 0 1px rgba(248, 250, 252, 0.08);
}

.square.unknown .note {
  color: rgba(226, 232, 240, 0.95);
  text-shadow: 0 0 8px rgba(15, 23, 42, 0.9);
}

.origin-hints {
  position: absolute;
  bottom: 0.35rem;
  left: 0.35rem;
  display: none;
  gap: 0.2rem;
  pointer-events: none;
}

.origin-hints--visible {
  display: flex;
}

.origin-hint {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 999px;
  background: var(--origin-color, rgba(148, 163, 184, 0.5));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.48rem;
  font-weight: 600;
  color: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(15, 23, 42, 0.18);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.3);
}

.square.unknown-multi {
  box-shadow: inset 0 0 0 1px rgba(248, 171, 88, 0.45),
    inset 0 0 12px rgba(248, 171, 88, 0.25);
}

.note-piece {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.3rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.note-piece + .note-piece {
  margin-left: 0.2rem;
}

.note-piece--king {
  background: rgba(248, 113, 113, 0.28);
  border-color: rgba(248, 113, 113, 0.6);
}

.note-piece--queen {
  background: rgba(196, 181, 253, 0.28);
  border-color: rgba(167, 139, 250, 0.55);
}

.note-piece--rook {
  background: rgba(96, 165, 250, 0.28);
  border-color: rgba(96, 165, 250, 0.55);
}

.note-piece--bishop {
  background: rgba(56, 189, 248, 0.28);
  border-color: rgba(56, 189, 248, 0.55);
}

.note-piece--knight {
  background: rgba(253, 186, 116, 0.28);
  border-color: rgba(251, 146, 60, 0.55);
}

.note-piece--pawn {
  background: rgba(134, 239, 172, 0.28);
  border-color: rgba(74, 222, 128, 0.55);
}

.note-piece--unknown {
  background: rgba(148, 163, 184, 0.25);
  border-color: rgba(148, 163, 184, 0.5);
}

.note-glyph {
  font-size: 0.85rem;
  line-height: 1;
}

.square.selected {
  outline: 3px solid rgba(56, 189, 248, 0.6);
  z-index: 1;
}

.square.highlight {
  background: rgba(168, 85, 247, 0.3);
}

.square.en-passant::after {
  content: "EP";
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  font-size: 0.55rem;
  color: rgba(248, 250, 252, 0.6);
}

.status-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.6);
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.status-line strong {
  font-size: 0.9rem;
}

.tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag {
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(148, 163, 184, 0.2);
}

.messages {
  min-height: 1.6rem;
  font-size: 0.85rem;
  color: #fbbf24;
}

.hidden {
  display: none !important;
}

.watch-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.watch-controls button {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border-radius: 0.6rem;
  border: none;
  background: rgba(148, 163, 184, 0.4);
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
}

.watch-controls button.active {
  background: #38bdf8;
  color: #0f172a;
}

.watch-controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

  .layout-play--game {
    padding: 1.5rem 1rem 3rem;
  }

  .board-layout {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 1.5rem;
  }

  .board-surface {
    width: 100%;
  }

  .board-layout__sidebar {
    height: auto;
  }

  .board-layout__sidebar .status-bar {
    margin-top: 0;
  }

  .board {
    width: 100%;
  }
}
