:root {
  --ink: #18243d;
  --paper: #fff7df;
  --cloud: #f7ead7;
  --teal: #1f7a7a;
  --teal-dark: #14545c;
  --gold: #f2c14e;
  --coral: #e96b56;
  --plum: #5a3d6b;
  --green: #5f8a4d;
  --blue: #3a7ca5;
  --shadow: 0 22px 70px rgba(11, 22, 40, 0.28);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  letter-spacing: 0;
  background:
    linear-gradient(180deg, rgba(255, 247, 223, 0.88) 0 16%, rgba(255, 247, 223, 0) 16%),
    linear-gradient(135deg, #143c55 0%, #24736f 42%, #e8b84b 42% 48%, #bb4f4a 48% 100%);
}

button {
  font: inherit;
  color: inherit;
}

.app {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  position: relative;
  overflow-x: hidden;
}

.app::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 44px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 44px);
  mask-image: linear-gradient(to bottom, black, transparent 70%);
}

.topbar {
  width: min(1180px, 100%);
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--paper);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(255, 247, 223, 0.9);
  background: linear-gradient(145deg, var(--gold), #f8dc77 45%, var(--coral));
  border-radius: 16px 16px 8px 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
  font-size: 28px;
  color: var(--ink);
}

.eyebrow,
.panel-kicker {
  margin: 0 0 4px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 800;
  opacity: 0.82;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 4vw, 3rem);
  line-height: 1;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.22rem;
  line-height: 1.18;
}

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

.language-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(42px, 1fr));
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 247, 223, 0.2);
  border: 1px solid rgba(255, 247, 223, 0.44);
  backdrop-filter: blur(12px);
}

.lang-button,
.icon-button,
.text-button,
.choice-button {
  border: 0;
  cursor: pointer;
}

.lang-button {
  min-height: 38px;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--paper);
  background: transparent;
  font-weight: 900;
}

.lang-button.active {
  background: var(--paper);
  color: var(--ink);
}

.icon-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--paper);
  background: rgba(255, 247, 223, 0.2);
  border: 1px solid rgba(255, 247, 223, 0.44);
  backdrop-filter: blur(12px);
  font-size: 1.25rem;
  font-weight: 900;
}

.game-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 360px);
  gap: clamp(16px, 3vw, 28px);
  align-items: start;
}

.board-stage {
  display: grid;
  place-items: center;
  gap: 10px;
}

.match-ribbon {
  min-height: 44px;
  width: min(680px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border: 2px solid rgba(255, 247, 223, 0.64);
  border-radius: 999px;
  background: rgba(24, 36, 61, 0.74);
  color: var(--paper);
  box-shadow: var(--shadow);
}

.match-ribbon span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--ink);
  background: var(--gold);
  font-weight: 900;
}

.match-ribbon strong {
  font-size: clamp(0.86rem, 2vw, 1rem);
  text-align: right;
}

.board-wrap {
  width: min(680px, calc(100vw - 32px), calc(100vh - 150px));
  padding: clamp(10px, 2vw, 16px);
  border: 4px solid #f5c769;
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0)),
    #7c4c34;
  box-shadow: var(--shadow), inset 0 0 0 6px rgba(24, 36, 61, 0.18);
}

.board-with-ranks {
  display: grid;
  grid-template-columns: 18px 1fr 18px;
  align-items: center;
  gap: 6px;
}

.coordinates {
  color: rgba(255, 247, 223, 0.82);
  font-size: 0.75rem;
  font-weight: 900;
  line-height: 1;
  user-select: none;
}

.coordinates.files {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  padding: 0 24px;
  margin: 0 0 6px;
  text-align: center;
}

.coordinates.files.bottom {
  margin: 6px 0 0;
}

.coordinates.ranks {
  height: 100%;
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  place-items: center;
}

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border: 3px solid rgba(24, 36, 61, 0.7);
  border-radius: 12px;
  background: var(--paper);
}

.square {
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 0;
  display: grid;
  place-items: center;
  position: relative;
  padding: 0;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

.square.light {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0)),
    #f5d999;
}

.square.dark {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.08)),
    #3f8376;
}

.square:hover {
  filter: brightness(1.05);
}

.square.selected::after,
.square.last-move::after {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 12px;
  border: 4px solid var(--coral);
  pointer-events: none;
}

.square.last-move::after {
  border-color: rgba(242, 193, 78, 0.86);
}

.square.legal-target::before {
  content: "";
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(24, 36, 61, 0.28);
  position: absolute;
}

.piece {
  display: grid;
  place-items: center;
  width: 86%;
  height: 86%;
  border-radius: 50%;
  font-family: "Times New Roman", "DejaVu Serif", serif;
  font-size: clamp(2.25rem, 8vw, 4.75rem);
  font-weight: 900;
  line-height: 1;
  transform: translateY(-3%);
  z-index: 1;
}

.piece-white {
  color: #fff9df;
  -webkit-text-stroke: 0.75px #152238;
  text-shadow:
    0 1px 0 #152238,
    0 5px 9px rgba(0, 0, 0, 0.28);
  filter: drop-shadow(0 5px 0 rgba(112, 73, 42, 0.32));
}

.piece-black {
  color: #071225;
  -webkit-text-stroke: 0.85px #f6d778;
  text-shadow:
    0 1px 0 #f6d778,
    0 8px 12px rgba(0, 0, 0, 0.3);
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.34));
}

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

.setup-panel,
.waiting-panel,
.status-panel,
.moves-panel {
  padding: 18px;
  border: 2px solid rgba(255, 247, 223, 0.72);
  border-radius: 8px;
  background: rgba(255, 247, 223, 0.94);
  box-shadow: 0 16px 42px rgba(11, 22, 40, 0.22);
}

.setup-panel h2,
.waiting-panel h2,
.status-panel h2,
.moves-panel h2 {
  color: var(--ink);
}

.setup-panel {
  background: linear-gradient(135deg, #fff7df, #f8dfa1);
}

.waiting-panel {
  background: linear-gradient(135deg, #e8f3ef, #fff7df);
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choice-button {
  min-height: 112px;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 12px;
  border: 3px solid rgba(24, 36, 61, 0.18);
  border-radius: 8px;
  background: #fff;
  box-shadow: inset 0 -8px 0 rgba(24, 36, 61, 0.08);
}

.choice-button span {
  font-family: "Times New Roman", "DejaVu Serif", serif;
  font-size: 3.2rem;
  line-height: 1;
}

.black-choice {
  color: var(--paper);
  background: linear-gradient(145deg, #4d5871, #152238);
}

.player-track {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.player-pill {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  border: 2px solid rgba(24, 36, 61, 0.12);
  border-radius: 999px;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.56);
}

.player-pill.active {
  border-color: var(--coral);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(233, 107, 86, 0.14);
}

.mini-piece {
  font-family: "Times New Roman", "DejaVu Serif", serif;
  font-size: 1.4rem;
  line-height: 1;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-header h2 {
  margin: 0;
}

.text-button {
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--paper);
  background: var(--teal-dark);
  font-weight: 900;
}

.move-list {
  min-height: 150px;
  max-height: min(42vh, 330px);
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.move-list li {
  min-height: 46px;
  display: grid;
  grid-template-columns: 34px 64px 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(24, 36, 61, 0.12);
}

.move-list span {
  color: var(--coral);
  font-weight: 900;
}

.move-list strong {
  font-size: 1.05rem;
}

.move-list small {
  opacity: 0.72;
  line-height: 1.2;
}

.move-list .empty-moves {
  grid-template-columns: 1fr;
  opacity: 0.75;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.58);
  z-index: 10;
}

.modal-panel {
  width: min(420px, 100%);
  padding: 20px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

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

.promotion-grid button {
  min-height: 76px;
  border: 2px solid rgba(24, 36, 61, 0.16);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-family: "Times New Roman", "DejaVu Serif", serif;
  font-size: 2.8rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .topbar,
  .game-shell {
    width: 100%;
  }

  .game-shell {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 560px) {
  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    font-size: 24px;
    border-radius: 12px 12px 8px 8px;
  }

  .top-actions {
    gap: 6px;
  }

  .language-switch {
    grid-template-columns: repeat(2, 36px);
  }

  .lang-button {
    min-height: 34px;
    padding: 0;
  }

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

  .match-ribbon {
    border-radius: 8px;
    align-items: stretch;
  }

  .board-wrap {
    padding: 8px;
    border-width: 3px;
    border-radius: 16px;
  }

  .board-with-ranks {
    grid-template-columns: 14px 1fr 14px;
    gap: 4px;
  }

  .coordinates.files {
    padding: 0 18px;
  }

  .piece {
    font-size: clamp(1.65rem, 9vw, 3.5rem);
  }

  .setup-panel,
  .waiting-panel,
  .status-panel,
  .moves-panel {
    padding: 14px;
  }

  .choice-button {
    min-height: 92px;
  }

  .move-list li {
    grid-template-columns: 30px 58px 1fr;
  }
}
