:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-strong: #f0f3f8;
  --text: #17202a;
  --muted: #687386;
  --line: #dce2eb;
  --accent: #2f7d67;
  --accent-strong: #205a4c;
  --gold: #c58a18;
  --danger: #c74444;
  --danger-soft: #fff0f0;
  --white-player: #f4f6fa;
  --black-player: #262a33;
  --light-square: #e6d7ad;
  --dark-square: #75936a;
  --active-square: #ffd166;
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(47, 125, 103, 0.08), transparent 280px),
    var(--bg);
  color: var(--text);
}

button,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}

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

button:focus-visible,
.slot:focus-visible {
  outline: 3px solid rgba(47, 125, 103, 0.35);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 36px) 32px;
}

.topbar,
.planner-layout,
.status-row,
.action-row,
.section-heading,
.budget-head,
.round-row,
.file-labels {
  display: flex;
}

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

.topbar h1,
.section-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-actions,
.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.planner-layout {
  align-items: flex-start;
  gap: 22px;
}

.board-panel,
.side-panel,
.panel-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 45px rgba(30, 43, 62, 0.08);
}

.board-panel {
  flex: 1 1 780px;
  min-width: 0;
  padding: clamp(14px, 2vw, 22px);
}

.side-panel {
  flex: 0 0 360px;
  display: grid;
  gap: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.7);
}

.panel-block {
  box-shadow: none;
  padding: 16px;
}

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

.section-heading h2 {
  font-size: 1rem;
}

.seat-toggle,
.format-toggle,
.round-strip {
  display: grid;
  gap: 8px;
}

.seat-toggle {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.room-status {
  min-height: 42px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.35;
}

.format-toggle {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.round-strip {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 14px;
}

.seat-button,
.format-button,
.round-button {
  display: grid;
  gap: 3px;
  justify-items: center;
  min-width: 0;
  padding: 9px 8px;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.seat-button.is-active,
.format-button.is-active,
.round-button.is-active {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(47, 125, 103, 0.26);
}

.seat-button span,
.format-button span,
.round-button span {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.round-number {
  font-weight: 800;
}

.format-detail,
.round-cost {
  color: currentColor;
  font-size: 0.72rem;
  opacity: 0.78;
}

.status-row {
  align-items: stretch;
  gap: 10px;
  margin-bottom: 16px;
}

.turn-card,
.selected-card {
  flex: 1 1 0;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.mini-label {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.big-value {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 850;
}

.piece-dot,
.player-dot {
  display: inline-grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  font-size: 1.45rem;
  line-height: 1;
}

.player-dot.white {
  color: var(--black-player);
  background: var(--white-player);
  border: 1px solid var(--line);
}

.player-dot.black {
  color: white;
  background: var(--black-player);
}

.piece-dot {
  color: var(--text);
  background: white;
  border: 1px solid var(--line);
}

.board-wrap {
  width: min(74vh, 100%);
  min-width: min(100%, 320px);
  margin: 0 auto;
}

.file-labels {
  justify-content: space-around;
  padding: 0 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-labels {
  margin-bottom: 6px;
}

.bottom-labels {
  margin-top: 6px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  overflow: hidden;
  border: 8px solid #29362f;
  border-radius: var(--radius);
  box-shadow: 0 18px 36px rgba(27, 43, 38, 0.23);
}

.square {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
}

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

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

.square.rank-target::after {
  position: absolute;
  inset: 7%;
  border: 2px dashed rgba(23, 32, 42, 0.28);
  border-radius: 7px;
  content: "";
  pointer-events: none;
}

.square.rank-target.active::after {
  border-color: rgba(255, 209, 102, 0.95);
  background: rgba(255, 209, 102, 0.14);
}

.slot {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  min-height: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  border-radius: 0;
}

.slot:hover {
  transform: none;
  box-shadow: inset 0 0 0 4px rgba(255, 209, 102, 0.8);
}

.slot:disabled {
  cursor: default;
  opacity: 1;
}

.piece {
  position: relative;
  z-index: 1;
  display: inline-grid;
  width: 72%;
  height: 72%;
  place-items: center;
  border-radius: 50%;
  font-size: clamp(1.7rem, 5.6vw, 4rem);
  line-height: 1;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.34);
}

.piece.black-piece {
  color: #15191f;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.38),
    0 8px 14px rgba(0, 0, 0, 0.18);
}

.piece.white-piece {
  color: #fbfcff;
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.4),
    0 8px 14px rgba(0, 0, 0, 0.2);
}

.coordinate {
  position: absolute;
  right: 6px;
  bottom: 5px;
  z-index: 1;
  color: rgba(23, 32, 42, 0.45);
  font-size: clamp(0.55rem, 1.4vw, 0.78rem);
  font-weight: 800;
}

.locked-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 1;
  padding: 2px 5px;
  border-radius: 999px;
  color: white;
  background: rgba(23, 32, 42, 0.6);
  font-size: clamp(0.52rem, 1.1vw, 0.68rem);
  font-weight: 800;
}

.action-row {
  justify-content: center;
  margin-top: 18px;
}

.primary-button,
.ghost-button,
.danger-button {
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  color: white;
  background: var(--accent);
}

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

.ghost-button {
  color: var(--text);
  background: white;
  border: 1px solid var(--line);
}

.danger-button {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(199, 68, 68, 0.22);
}

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

.piece-button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 9px;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  text-align: left;
}

.piece-button.is-selected {
  border-color: var(--gold);
  background: #fff7e2;
  box-shadow: 0 8px 18px rgba(197, 138, 24, 0.18);
}

.piece-button .symbol {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  background: white;
  font-size: 1.55rem;
  line-height: 1;
}

.piece-button .piece-name {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
}

.piece-button .piece-value {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.piece-button:disabled {
  background: #eef1f6;
}

.budget-list,
.round-summary {
  display: grid;
  gap: 10px;
}

.budget-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.budget-head {
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.budget-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 850;
}

.budget-number {
  flex: 0 0 auto;
  font-weight: 850;
}

.meter {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: #d8dee8;
}

.meter-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.inventory-pill {
  display: grid;
  min-width: 0;
  gap: 2px;
  justify-items: center;
  padding: 7px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  font-size: 1.12rem;
  line-height: 1;
}

.inventory-pill strong {
  color: var(--muted);
  font-size: 0.78rem;
}

.budget-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.round-row {
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.round-row:last-child {
  border-bottom: 0;
}

.round-title {
  min-width: 0;
  font-weight: 850;
}

.round-points {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.fen-box {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: 20px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid rgba(47, 125, 103, 0.22);
  border-radius: var(--radius);
  color: var(--text);
  background: white;
  box-shadow: 0 18px 40px rgba(20, 30, 43, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

@media (max-width: 1060px) {
  .planner-layout {
    display: grid;
  }

  .side-panel {
    flex-basis: auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board-wrap {
    width: min(78vh, 100%);
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding-top: 18px;
  }

  .topbar,
  .status-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .action-row {
    width: 100%;
  }

  .topbar-actions button,
  .action-row button {
    flex: 1 1 150px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .piece-palette {
    grid-template-columns: 1fr;
  }

  .round-strip {
    grid-template-columns: repeat(5, minmax(54px, 1fr));
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .board {
    border-width: 5px;
  }

  .piece {
    font-size: clamp(1.35rem, 8vw, 2.8rem);
  }

  .locked-badge {
    display: none;
  }
}

@media (max-width: 460px) {
  .board-panel,
  .side-panel {
    margin-inline: -4px;
  }

  .round-button {
    padding-inline: 6px;
  }

  .coordinate {
    right: 4px;
    bottom: 3px;
  }
}
