:root {
  --bg: #0b0b0b;
  --surface: rgba(255, 255, 255, 0.08);
  --surface-strong: rgba(255, 255, 255, 0.18);
  --surface-soft: rgba(255, 255, 255, 0.05);
  --surface-active: rgba(255, 255, 255, 0.14);
  --surface-input: rgba(255, 255, 255, 0.12);
  --text: #f7f7f7;
  --muted: #e11d2e;
  --accent: #f7f7f7;
  --accent-contrast: #0b0b0b;
  --accent-strong: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.2);
  --board-light: #f0f0f0;
  --board-dark: #0f0f0f;
  --board-outline: rgba(255, 255, 255, 0.3);
  --board-outline-strong: rgba(255, 255, 255, 0.45);
  --piece-light: #ffffff;
  --focus: #e11d2e;
  --border: rgba(255, 255, 255, 0.18);
  --border-strong: rgba(255, 255, 255, 0.28);
  --piece-dark: #2b2b2b;
  --shadow: rgba(0, 0, 0, 0.6);
  --shadow-strong: rgba(0, 0, 0, 0.8);
  --toast-bg: rgba(10, 10, 10, 0.9);
  --check: #e11d2e;
  --bg-glow-1: rgba(255, 255, 255, 0.05);
  --bg-glow-2: rgba(225, 29, 46, 0.12);
  --bg-glow-3: rgba(9, 9, 9, 0.95);
  --bg-glow-4: rgba(0, 0, 0, 0.9);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.bg-layer {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 15% 10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(circle at 80% 20%, var(--bg-glow-2), transparent 55%),
    linear-gradient(120deg, var(--bg-glow-3), var(--bg-glow-4));
  pointer-events: none;
  z-index: -1;
}

#app {
  padding: 32px 28px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 6;
}

.brand-link {
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  text-decoration: none;
  gap: 8px;
}

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

.brand-logo {
  height: 18px;
  width: auto;
  display: block;
}

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

#homeView {
  width: min(100%, 480px);
  margin: 0 auto;
}

#settingsPanel {
  position: absolute;
  top: 72px;
  right: 28px;
  width: min(90vw, 560px);
  z-index: 5;
  box-shadow: 0 18px 40px var(--shadow-strong);
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
}

.icon {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.icon-button .icon {
  width: 18px;
  height: 18px;
}

.view {
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeUp 0.6s ease both;
}

.hidden {
  display: none;
}

.view-header h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 36px);
}

.view-header {
  text-align: center;
}

.view-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.block-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: center;
  width: 100%;
}

.mode-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  gap: 8px 12px;
  justify-content: center;
}

.mode-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 12px;
  background: var(--surface);
  backdrop-filter: blur(6px);
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  width: max-content;
}

.mode-card {
  width: 36px;
  height: 30px;
  padding: 0;
}

.mode-card .mode-icon {
  width: 16px;
  height: 16px;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px var(--shadow);
}

.card.active {
  border-color: var(--accent);
  box-shadow: 0 10px 26px var(--shadow-strong);
}

.card-title {
  font-weight: 600;
  font-size: 12px;
  line-height: 1;
}

.card-desc {
  color: var(--muted);
  font-size: 11px;
}

.mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
}

.info-wrap {
  position: relative;
}

.info-button {
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  display: grid;
  place-items: center;
}

.info-button .icon {
  width: 11px;
  height: 11px;
}

.info-tip {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
  white-space: normal;
  min-width: 220px;
  max-width: 320px;
  display: grid;
  gap: 6px;
  text-align: left;
  box-shadow: 0 10px 20px var(--shadow);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 2;
}

.info-wrap:hover .info-tip {
  opacity: 1;
  transform: translateY(0);
}

.info-line {
  display: block;
}

button,
input {
  font-family: "Space Grotesk", sans-serif;
}

button {
  border: 1px solid var(--border-strong);
  padding: 10px 16px;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 600;
}

.primary:hover {
  background: var(--accent-strong);
}

.ghost {
  background: var(--surface-soft);
}

.pill {
  border-radius: 999px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1;
  height: 28px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.pill .icon {
  width: 13px;
  height: 13px;
}

.pill.active {
  border-color: var(--accent);
  background: var(--surface-active);
}

.pill.glow-red {
  box-shadow: 0 0 12px rgba(226, 46, 68, 0.35), 0 0 22px rgba(226, 46, 68, 0.2);
}

.pill.glow-orange {
  box-shadow: 0 0 12px rgba(255, 143, 64, 0.35), 0 0 22px rgba(255, 143, 64, 0.2);
}

.pill.glow-purple {
  box-shadow: 0 0 12px rgba(154, 99, 255, 0.35), 0 0 22px rgba(154, 99, 255, 0.2);
}

.panel {
  border-radius: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeUp 0.5s ease both;
}

.panel.hidden {
  display: none;
}

.panel-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.palette-option {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
  cursor: pointer;
  background: var(--surface-soft);
}

.palette-swatch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.palette-swatch span {
  height: 20px;
  border-radius: 6px;
  display: block;
}

.palette-option.active {
  border-color: var(--accent);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.game-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.game-title {
  font-size: 20px;
  font-weight: 600;
}

.game-meta {
  color: var(--muted);
  font-size: 14px;
}

.game-actions {
  display: flex;
  gap: 10px;
}

.game-new {
  align-self: flex-start;
}

.game-layout {
  --board-size: min(80vh, 80vw);
  display: grid;
  grid-template-columns: 1fr minmax(0, var(--board-size)) 1fr;
  gap: 24px;
  align-items: start;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  grid-column: 2;
  width: min(100%, var(--board-size));
}

.board-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.board-area {
  position: relative;
  width: 100%;
}

.board-legend {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.75;
  pointer-events: none;
}

.board-legend-files {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  text-align: center;
}

.board-legend-ranks {
  position: absolute;
  top: 0;
  bottom: 0;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
  width: 18px;
}

.board-legend-left {
  left: -20px;
  text-align: right;
}

.board-legend-right {
  right: -20px;
  text-align: left;
}

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  background: var(--board-base, var(--board-light));
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--board-outline);
  box-shadow: 0 18px 32px var(--shadow-strong);
}

.square {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 0;
  position: relative;
  transition: background 0.15s ease, transform 0.15s ease;
}

.square.possible::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--focus);
  opacity: 0.6;
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 0;
}

.square.possible.possible-capture::after {
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--focus);
  opacity: 0.8;
}

.square.check::before {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  border: 2px solid var(--check);
  box-shadow: 0 0 12px rgba(226, 75, 75, 0.35);
  z-index: 0;
}

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

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

.square.selected {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.square.last-move {
  box-shadow: inset 0 0 0 2px var(--board-outline-strong);
}

.piece-icon {
  width: 70%;
  height: 70%;
  display: block;
  fill: currentColor;
  position: relative;
  z-index: 1;
}

.piece-white {
  color: var(--piece-light, var(--text));
}

.piece-black {
  color: var(--piece-dark);
}

.status-line {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 16px;
  grid-column: 3;
  justify-self: end;
  width: min(90vw, 280px);
}

.clock-card {
  border-radius: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.clock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
}

.clock-value {
  font-family: "JetBrains Mono", monospace;
  font-size: 18px;
}

.side-block {
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.move-list {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-line;
}

.captures {
  width: 100%;
  display: flex;
  justify-content: center;
}

.capture-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.capture-pieces {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  min-height: 16px;
}

.capture-pieces .piece-icon {
  width: 14px;
  height: 14px;
}

.capture-points {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text);
  min-width: 28px;
  text-align: right;
}

.rematch-wrap {
  display: flex;
  justify-content: center;
}

.rematch-wrap button {
  padding: 6px 16px;
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 12, 0.35);
  backdrop-filter: blur(6px);
  z-index: 12;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(90vw, 360px);
  border-radius: 18px;
  padding: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  box-shadow: 0 20px 40px var(--shadow-strong);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 0;
}

.modal-close:hover {
  transform: none;
}

.modal-body {
  display: flex;
  align-items: center;
  gap: 10px;
}

.share-url {
  flex: 1;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--surface-input);
  border: 1px solid var(--border);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.02em;
  animation: fadeUp 0.4s ease both;
}

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

@media (max-width: 920px) {
  .game-layout {
    --board-size: min(80vh, 90vw);
    grid-template-columns: 1fr;
  }

  .board-wrap,
  .side {
    grid-column: auto;
  }

  .side {
    width: min(90vw, 420px);
    justify-self: center;
  }
}

@media (max-width: 600px) {
  #app {
    padding: 24px 18px 40px;
  }

  #settingsPanel {
    right: 18px;
    left: 18px;
    width: auto;
  }

  .mode-grid {
    justify-content: center;
  }

  .segmented {
    grid-template-columns: repeat(2, max-content);
  }

  .game-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
.create-button {
  align-self: center;
  width: min(100%, 240px);
}
