:root {
  color-scheme: dark;
  --bg: #0c1710;
  --surface: #13231a;
  --surface-2: #183725;
  --line: #34513a;
  --text: #f6f2df;
  --muted: #b7c4b2;
  --gold: #d2a94b;
  --mint: #79d79b;
  --danger: #e16f5b;
  --light-square: #d9c188;
  --dark-square: #46734d;
  --selected: #f0cf63;
  --target: rgba(246, 242, 223, 0.5);
  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(12, 23, 16, 0.78), rgba(12, 23, 16, 0.96)),
    url("data:image/svg+xml,%3Csvg width='160' height='160' viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%2334513a' stroke-opacity='.32'%3E%3Cpath d='M0 80h160M80 0v160'/%3E%3Cpath d='M40 0v160M120 0v160M0 40h160M0 120h160' stroke-opacity='.16'/%3E%3C/g%3E%3C/svg%3E");
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #213629;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

button:hover:not(:disabled),
button:focus-visible:not(:disabled) {
  border-color: var(--gold);
  background: #2a4534;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

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

button.primary {
  border-color: #ebc969;
  background: var(--gold);
  color: #102012;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1c14;
  color: var(--text);
  padding: 0 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1320px;
  margin: 0 auto 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: #112419;
  color: var(--gold);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.room-pill,
.invite-url,
.turn-box {
  color: var(--muted);
}

.room-pill {
  max-width: 48vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(19, 35, 26, 0.76);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  gap: 18px;
  max-width: 1320px;
  margin: 0 auto;
}

.board-zone {
  display: grid;
  gap: 10px;
  align-content: start;
}

.board-wrap {
  width: min(92vw, 680px);
  max-width: 100%;
  justify-self: center;
  aspect-ratio: 1;
  border: 1px solid #628461;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  width: 100%;
  height: 100%;
}

.square {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  border: 0;
  border-radius: 0;
  color: #132015;
  font-size: clamp(1.6rem, 7vw, 4.6rem);
  line-height: 1;
  min-height: 0;
  user-select: none;
}

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

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

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

.square.target::after {
  content: "";
  width: 28%;
  height: 28%;
  border-radius: 999px;
  background: var(--target);
}

.square.capture::after {
  content: "";
  position: absolute;
  inset: 18%;
  border: 4px solid var(--target);
  border-radius: 999px;
}

.square.last-move {
  box-shadow: inset 0 0 0 999px rgba(240, 207, 99, 0.24);
}

.square.check {
  box-shadow: inset 0 0 0 999px rgba(225, 111, 91, 0.35);
}

.coord {
  position: absolute;
  left: 5px;
  bottom: 4px;
  color: rgba(12, 23, 16, 0.58);
  font-size: 0.68rem;
  font-weight: 900;
}

.player-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(19, 35, 26, 0.88);
  padding: 10px 12px;
  color: var(--text);
  font-weight: 800;
}

.player-strip small {
  color: var(--muted);
  font-weight: 700;
}

.control-zone {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(19, 35, 26, 0.92);
  padding: 14px;
}

.panel h1,
.panel h2 {
  margin: 0 0 12px;
  letter-spacing: 0;
}

.panel h1 {
  font-size: 1.45rem;
}

.panel h2 {
  font-size: 1rem;
}

.stack {
  display: grid;
  gap: 10px;
}

.button-row,
.status-line,
.chat-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.join-row {
  margin-top: 12px;
  grid-template-columns: 1fr auto;
  align-items: end;
}

.join-row button,
.chat-form button {
  min-width: 90px;
}

.status-line {
  align-items: center;
}

#game-status {
  font-weight: 900;
}

.invite-url,
.turn-box {
  margin-top: 10px;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.turn-box {
  border-left: 3px solid var(--gold);
  padding-left: 10px;
}

.chat-panel {
  min-height: 250px;
}

.chat-log,
.move-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chat-log li,
.move-list li {
  border-bottom: 1px solid rgba(52, 81, 58, 0.72);
  padding-bottom: 8px;
}

.chat-log strong {
  color: var(--mint);
}

.chat-log span {
  color: var(--muted);
}

.chat-form {
  margin-top: 10px;
}

.move-list {
  grid-template-columns: 1fr 1fr;
  max-height: 150px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101e16;
  color: var(--text);
  padding: 12px 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

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

@media (max-width: 920px) {
  .app-shell {
    padding: 12px;
  }

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

  .room-pill {
    max-width: 100%;
  }

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

  .board-wrap {
    width: min(96vw, 640px);
  }

  .control-zone {
    grid-row: 1;
  }
}

@media (max-width: 540px) {
  .button-row,
  .status-line,
  .join-row,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .square {
    font-size: clamp(1.35rem, 10vw, 3rem);
  }
}
