:root {
  color-scheme: dark;
  --bg: #1f1711;
  --bg-deep: #120d09;
  --panel: #35281d;
  --panel-soft: #443326;
  --panel-light: #5a402b;
  --fg: #fff7ea;
  --muted: #d8c4a9;
  --line: rgba(255, 247, 234, 0.15);
  --gold: #f0be74;
  --leaf: #7ea35b;
  --danger: #d66f55;
  --light-square: #b7895e;
  --dark-square: #60452d;
  --shadow: 10px 10px 0 rgba(12, 8, 5, 0.42);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(126, 163, 91, 0.12), transparent 34rem),
    linear-gradient(225deg, rgba(185, 120, 63, 0.18), transparent 34rem),
    linear-gradient(180deg, var(--bg) 0%, #261b13 52%, var(--bg-deep) 100%);
  color: var(--fg);
  font-family:
    "Space Grotesk", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar,
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand,
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  font-weight: 900;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: #fff7ea;
  font-size: 0.78rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid rgba(255, 247, 234, 0.2);
  border-radius: 999px;
  background: rgba(126, 163, 91, 0.18);
  color: #f9eed7;
  font-size: 0.86rem;
  font-weight: 900;
}

.hero {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(320px, 1.18fr);
  gap: clamp(22px, 5vw, 64px);
  align-items: center;
  padding: clamp(44px, 9vw, 90px) 0;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 18px;
  color: #fff7ea;
  font-size: clamp(3.8rem, 10vw, 7.2rem);
  line-height: 0.9;
}

.lead {
  max-width: 38rem;
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.65;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.02)),
    var(--panel);
  box-shadow: var(--shadow);
}

.setup-panel {
  padding: clamp(18px, 3vw, 30px);
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field label {
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.input {
  width: 100%;
  min-height: 50px;
  border: 1px solid rgba(255, 247, 234, 0.2);
  border-radius: 8px;
  background: rgba(18, 13, 9, 0.45);
  color: var(--fg);
  padding: 0 14px;
  outline: none;
}

.input:focus {
  border-color: rgba(240, 190, 116, 0.68);
}

.actions,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  min-height: 46px;
  border: 1px solid rgba(255, 247, 234, 0.2);
  border-radius: 999px;
  background: #f4eadb;
  color: #1f1711;
  padding: 0 18px;
  font-weight: 950;
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
}

.btn.danger {
  background: rgba(214, 111, 85, 0.22);
  color: #ffe0d8;
}

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

.room-card {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.room-code {
  display: inline-flex;
  width: fit-content;
  border: 1px solid rgba(255, 247, 234, 0.2);
  border-radius: 8px;
  background: rgba(18, 13, 9, 0.5);
  color: #fff7ea;
  padding: 10px 14px;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  font-weight: 950;
  letter-spacing: 0.16em;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 360px);
  gap: clamp(18px, 4vw, 34px);
  align-items: start;
  padding: clamp(28px, 5vw, 52px) 0 28px;
}

.board-wrap {
  display: grid;
  gap: 14px;
}

.board-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.board-status {
  color: var(--muted);
  font-weight: 800;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(100%, 680px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(255, 247, 234, 0.22);
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
}

.square {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 0;
  color: #fff7ea;
  font-family: "Segoe UI Symbol", "Apple Color Emoji", serif;
  font-size: clamp(2rem, 7.2vw, 4.9rem);
  line-height: 1;
}

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

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

.square.selected {
  outline: 4px solid rgba(240, 190, 116, 0.86);
  outline-offset: -4px;
}

.square.legal::after {
  content: "";
  width: 24%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(255, 247, 234, 0.38);
}

.square.capture::after {
  content: "";
  position: absolute;
  inset: 9%;
  border: 4px solid rgba(255, 247, 234, 0.42);
  border-radius: 999px;
}

.square.last {
  box-shadow: inset 0 0 0 999px rgba(126, 163, 91, 0.23);
}

.piece-white {
  color: #fff4dc;
  text-shadow: 0 2px 0 rgba(31, 23, 17, 0.6);
}

.piece-black {
  color: #18110b;
  text-shadow: 0 1px 0 rgba(255, 247, 234, 0.35);
}

.side-panel {
  display: grid;
  gap: 14px;
}

.info-card {
  padding: 18px;
}

.info-card h2,
.info-card h3 {
  margin-bottom: 10px;
}

.players {
  display: grid;
  gap: 8px;
}

.player-row,
.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(255, 247, 234, 0.1);
  border-radius: 8px;
  background: rgba(18, 13, 9, 0.28);
  padding: 10px 12px;
}

.player-name {
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.warn {
  color: var(--gold);
  font-weight: 900;
}

.danger-text {
  color: #ffd2c6;
  font-weight: 900;
}

.history {
  display: grid;
  max-height: 280px;
  gap: 6px;
  overflow: auto;
  padding-right: 2px;
}

.empty-history {
  color: var(--muted);
  line-height: 1.5;
}

.promotion {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(18, 13, 9, 0.72);
  padding: 20px;
  z-index: 10;
}

.promotion-card {
  width: min(420px, 100%);
  padding: 22px;
}

.promotion-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.promotion-piece {
  min-height: 76px;
  border: 1px solid rgba(255, 247, 234, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg);
  font-size: 2.4rem;
}

.toast {
  min-height: 24px;
  color: var(--gold);
  font-weight: 800;
}

.loading-screen {
  display: grid;
  min-height: 80vh;
  place-items: center start;
}

.footer {
  justify-content: flex-start;
  color: var(--muted);
  font-size: 0.92rem;
}

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

  .board {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 22px, 1180px);
    padding-top: 14px;
  }

  .topbar,
  .footer {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: clamp(4rem, 18vw, 5.4rem);
  }

  .board-top,
  .inline-actions {
    align-items: flex-start;
    flex-direction: column;
  }
}
