:root {
  color-scheme: dark;
  --bg: #111111;
  --panel: rgba(26, 27, 26, 0.86);
  --panel-solid: #1a1b1a;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f7f2e8;
  --muted: #a9a296;
  --accent: #f2c94c;
  --accent-2: #00b894;
  --danger: #ff5a5f;
  --tile-dark: #2b2018;
  --tile-light: #b98043;
  --white-chip: #f7f2e8;
  --black-chip: #141414;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(242, 201, 76, 0.12), transparent 32rem),
    linear-gradient(135deg, rgba(0, 184, 148, 0.09), transparent 38rem),
    var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.screen {
  min-height: calc(100vh - clamp(24px, 4vw, 56px));
  min-height: calc(100dvh - 24px);
}

.menu {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: clamp(20px, 5vw, 72px);
  align-items: center;
  max-width: 1180px;
  margin: 0 auto;
}

.brand h1 {
  margin: 0;
  max-width: 760px;
  font-family: Kanit, Inter, sans-serif;
  font-size: clamp(3.4rem, 13vw, 9rem);
  line-height: 0.78;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand p {
  max-width: 680px;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.7;
}

.menu-panel,
.side-panel,
.chat-panel,
.modal {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(18px);
}

.menu-panel {
  border-radius: 8px;
  padding: 20px;
}

.actions {
  display: grid;
  gap: 12px;
}

.btn {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 16px;
  color: var(--text);
  background: #2a2b28;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, opacity 160ms ease;
}

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

.btn.primary {
  background: var(--accent);
  color: #111111;
}

.btn.green {
  background: var(--accent-2);
  color: #071713;
}

.btn.danger {
  background: var(--danger);
  color: #160304;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.08);
}

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

.join-form,
.room-card {
  display: none;
  margin-top: 16px;
  gap: 10px;
}

.join-form.active,
.room-card.active {
  display: grid;
}

.field {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  text-transform: uppercase;
}

.room-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(242, 201, 76, 0.1);
  border: 1px dashed rgba(242, 201, 76, 0.45);
}

.room-code strong {
  font-family: Kanit, Inter, sans-serif;
  font-size: 1.75rem;
  letter-spacing: 0.16em;
}

.status-line {
  margin: 12px 0 0;
  color: var(--muted);
  min-height: 24px;
}

.game {
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(0, 1fr) minmax(280px, 360px);
  gap: 18px;
  align-items: start;
}

.topbar {
  grid-column: 1 / -1;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.topbar h2 {
  margin: 0;
  font-family: Kanit, Inter, sans-serif;
  font-size: clamp(1.55rem, 4vw, 2.5rem);
  text-transform: uppercase;
}

.pill-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  min-height: 34px;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.dot.connected {
  background: var(--accent-2);
}

.side-panel,
.chat-panel {
  border-radius: 8px;
  padding: 16px;
}

.side-panel h3,
.chat-panel h3 {
  margin: 0 0 14px;
  font-size: 0.96rem;
  text-transform: uppercase;
  color: var(--muted);
}

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

.score {
  min-height: 86px;
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.07);
}

.score span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  font-weight: 800;
}

.score strong {
  display: block;
  margin-top: 8px;
  font-family: Kanit, Inter, sans-serif;
  font-size: 2rem;
}

.rules-note {
  color: var(--muted);
  line-height: 1.55;
  margin: 16px 0;
}

.capture-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.capture-item {
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: rgba(242, 201, 76, 0.1);
  border: 1px solid rgba(242, 201, 76, 0.22);
  font-size: 0.84rem;
}

.capture-item.forced {
  border-color: rgba(242, 201, 76, 0.75);
  background: rgba(242, 201, 76, 0.18);
  box-shadow: inset 4px 0 0 var(--accent);
  text-align: left;
}

.board-wrap {
  width: min(100%, calc(100vh - 128px));
  width: min(100%, calc(100dvh - 128px));
  max-width: 720px;
  min-width: min(280px, 100%);
  margin: 0 auto;
  aspect-ratio: 1;
  padding: clamp(8px, 1.6vw, 14px);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent),
    #17110d;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.45);
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border-radius: 6px;
  touch-action: manipulation;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  min-width: 0;
  aspect-ratio: 1;
  background: var(--tile-light);
  -webkit-tap-highlight-color: transparent;
}

.tile.dark {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 48%),
    var(--tile-dark);
}

.tile.light {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 52%),
    var(--tile-light);
}

.tile.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.tile.destination::after,
.tile.capture::after,
.tile.force-landing::after,
.tile.force-target::after,
.tile.last::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  pointer-events: none;
}

.tile.destination::after {
  background: rgba(0, 184, 148, 0.35);
  box-shadow: 0 0 24px rgba(0, 184, 148, 0.35);
}

.tile.capture::after {
  background: rgba(255, 90, 95, 0.34);
  box-shadow: 0 0 24px rgba(255, 90, 95, 0.35);
}

.tile.force-origin {
  outline: 4px solid rgba(242, 201, 76, 0.95);
  outline-offset: -5px;
  box-shadow: inset 0 0 0 2px rgba(17, 17, 17, 0.55);
}

.tile.force-black {
  outline-color: rgba(255, 90, 95, 0.98);
}

.tile.force-landing::after {
  inset: 22%;
  border: 3px solid rgba(242, 201, 76, 0.95);
  background: rgba(242, 201, 76, 0.2);
  box-shadow: 0 0 24px rgba(242, 201, 76, 0.45);
}

.tile.force-target::after {
  inset: 18%;
  border: 3px solid rgba(255, 90, 95, 0.95);
  background: rgba(255, 90, 95, 0.16);
  box-shadow: 0 0 24px rgba(255, 90, 95, 0.5);
}

.tile.last::after {
  border: 2px solid rgba(255, 255, 255, 0.42);
}

.force-badge {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 5%;
  transform: translateX(-50%);
  max-width: 90%;
  border-radius: 999px;
  padding: 2px 6px;
  color: #111111;
  background: var(--accent);
  font-size: clamp(0.52rem, 1.7vw, 0.7rem);
  font-weight: 900;
  line-height: 1.1;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.36);
}

@keyframes forcePulse {
  0%,
  100% {
    transform: translateY(0) scale(1);
    box-shadow:
      inset 0 7px 10px rgba(255, 255, 255, 0.18),
      inset 0 -10px 16px rgba(0, 0, 0, 0.28),
      0 10px 18px rgba(0, 0, 0, 0.45),
      0 0 0 0 rgba(242, 201, 76, 0.7);
  }

  50% {
    transform: translateY(-2px) scale(1.05);
    box-shadow:
      inset 0 7px 10px rgba(255, 255, 255, 0.18),
      inset 0 -10px 16px rgba(0, 0, 0, 0.28),
      0 10px 18px rgba(0, 0, 0, 0.45),
      0 0 0 8px rgba(242, 201, 76, 0);
  }
}

@keyframes forcePulseBlack {
  0%,
  100% {
    transform: translateY(0) scale(1);
    box-shadow:
      inset 0 7px 10px rgba(255, 255, 255, 0.18),
      inset 0 -10px 16px rgba(0, 0, 0, 0.28),
      0 10px 18px rgba(0, 0, 0, 0.45),
      0 0 0 0 rgba(255, 90, 95, 0.78);
  }

  50% {
    transform: translateY(-2px) scale(1.05);
    box-shadow:
      inset 0 7px 10px rgba(255, 255, 255, 0.18),
      inset 0 -10px 16px rgba(0, 0, 0, 0.28),
      0 10px 18px rgba(0, 0, 0, 0.45),
      0 0 0 9px rgba(255, 90, 95, 0);
  }
}

.piece {
  position: relative;
  z-index: 2;
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: transform 180ms ease;
  box-shadow:
    inset 0 7px 10px rgba(255, 255, 255, 0.18),
    inset 0 -10px 16px rgba(0, 0, 0, 0.28),
    0 10px 18px rgba(0, 0, 0, 0.45);
}

.piece.white {
  background: radial-gradient(circle at 35% 25%, #ffffff, var(--white-chip) 48%, #b7afa2);
  border: 3px solid rgba(255, 255, 255, 0.58);
}

.piece.black {
  background: radial-gradient(circle at 35% 25%, #4a4a4a, var(--black-chip) 55%, #050505);
  border: 3px solid rgba(255, 255, 255, 0.14);
}

.piece.king::before {
  content: "D";
  width: 48%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #111111;
  background: var(--accent);
  font-family: Kanit, Inter, sans-serif;
  font-size: clamp(0.8rem, 2.4vw, 1.35rem);
  box-shadow: 0 0 18px rgba(242, 201, 76, 0.55);
}

.piece.black.king::before {
  color: #fff7d7;
  background: #8d1117;
}

.tile.force-origin .piece {
  animation: forcePulse 1.15s ease-in-out infinite;
}

.tile.force-black .piece {
  animation-name: forcePulseBlack;
}

.tile.force-black .force-badge {
  color: #fff7d7;
  background: #b91622;
}

.tile:hover .piece {
  transform: translateY(-2px);
}

.chat-log {
  height: min(48vh, 420px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.chat-msg {
  align-self: flex-start;
  max-width: 92%;
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  overflow-wrap: anywhere;
}

.chat-msg.mine {
  align-self: flex-end;
  background: rgba(0, 184, 148, 0.2);
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.chat-form .field {
  text-transform: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.62);
}

.overlay.active {
  display: grid;
}

.modal {
  width: min(100%, 420px);
  border-radius: 8px;
  padding: 20px;
}

.modal h2 {
  margin: 0 0 8px;
  font-family: Kanit, Inter, sans-serif;
  font-size: 2.1rem;
}

.modal p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.55;
}

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

.hidden {
  display: none !important;
}

@media (max-width: 1060px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .side-panel,
  .chat-panel {
    order: 3;
  }

  .side-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

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

@media (max-width: 760px) {
  .app {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .menu {
    grid-template-columns: 1fr;
    align-content: center;
  }

  .brand h1 {
    font-size: clamp(3.2rem, 21vw, 5.4rem);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

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

  .board-wrap {
    width: min(100%, calc(100dvw - 20px));
    padding: 8px;
  }

  .chat-log {
    height: 190px;
  }
}

@media (max-width: 520px) {
  .brand p {
    margin-top: 16px;
    line-height: 1.55;
  }

  .menu-panel,
  .side-panel,
  .chat-panel {
    padding: 14px;
  }

  .topbar > .pill-row {
    width: 100%;
  }

  .topbar > .pill-row .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    padding: 0 10px;
  }

  .pill {
    max-width: 100%;
    font-size: 0.8rem;
  }

  .piece {
    width: 76%;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }

  .room-code {
    align-items: stretch;
    flex-direction: column;
  }
}
