:root {
  --comic: "Comic Sans MS", "Comic Sans", "Chalkboard SE", "Comic Neue", cursive;
  --purple: #542c82;
  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --hidden-king: #7dd3fc;
  --selected: #f6e05e;
  --move-light: #c7efb4;
  --move-dark: #a3d98b;
  --capture-light: #f8c4c4;
  --capture-dark: #eba0a0;
  --muted: #555555;
  --line: #222222;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: #ffffff;
  color: #000000;
  font-family: var(--comic);
  font-size: 16px;
}

button {
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
}

button:hover:not(:disabled) { background: #eeeeee; }
button:disabled { cursor: default; opacity: 0.55; }
button:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; }

.big-button {
  font-size: 1.6rem;
  font-weight: bold;
  padding: 6px 22px;
  border-radius: 14px;
}

.big-button.small { font-size: 1.2rem; }

.link-button {
  border: none;
  background: none;
  padding: 4px 2px;
  text-decoration: underline;
}

.link-button:hover:not(:disabled) { background: none; color: var(--purple); }

/* Lobby: title, controls, and past games on the left; leaderboard down the right. */
.lobby {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr);
  grid-template-rows: auto auto minmax(260px, 1fr) auto;
  column-gap: 48px;
  max-width: 1100px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 24px 16px;
}

.lobby-title {
  grid-area: 1 / 1;
  margin: 12px 0 8px;
  font-size: clamp(2.8rem, 9vw, 4.5rem);
  font-weight: bold;
}

.controls { grid-area: 2 / 1; padding: 0 0 20px 32px; }
.control-links { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 6px; }
.lobby-status { margin: 8px 0 0; color: var(--muted); max-width: 32rem; min-height: 1.4em; }

.panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  min-height: 0;
}

.panel h2 {
  margin: 0;
  padding: 8px;
  font-size: 1.4rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.history-panel { grid-area: 3 / 1; }
.leaderboard-panel { grid-area: 1 / 2 / 5 / 3; margin: 8px 0 12px; }

.table-scroll { overflow: auto; flex: 1; padding: 6px 8px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 5px 6px; text-align: center; }
th { font-size: 1.05rem; border-bottom: 1px solid #dddddd; }
td.empty { color: var(--muted); padding: 18px 6px; }

.player-name {
  grid-area: 4 / 1;
  margin: 14px 0 0;
  font-size: 1.5rem;
  font-weight: bold;
  text-align: center;
}

/* Game screen */
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px 20px;
  text-align: center;
}

.game p { margin: 2px 0; }
.game-title { color: var(--purple); font-size: 2rem; margin: 6px 0 2px; }
.players-line { font-weight: bold; white-space: pre-wrap; }
.hint { color: var(--purple); font-size: 0.9rem; max-width: 34rem; }
.game-status { color: var(--purple); min-height: 1.4em; margin: 6px 0 !important; }

.board {
  --square: min(56px, calc((100vw - 64px) / 9));
  display: grid;
  --edge: calc(var(--square) / 2);
  grid-template-columns: var(--edge) repeat(8, var(--square)) var(--edge);
  grid-template-rows: var(--edge) repeat(8, var(--square)) var(--edge);
  border: 2px solid var(--line);
  margin: 4px 0 10px;
}

.board > .coord {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: bold;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--square);
  height: var(--square);
  padding: 0;
  border: none;
  border-radius: 0;
  line-height: 1;
  position: relative;
}

.square img {
  position: relative;
  width: 90%;
  height: 90%;
  pointer-events: none;
  user-select: none;
}

.square img.moving { z-index: 2; }
.square img.captured { position: absolute; inset: 0; margin: auto; z-index: 1; }

.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square.hidden-king { background: var(--hidden-king); }
.square.selected { background: var(--selected); }
.square.hidden-king.selected { background: var(--hidden-king); box-shadow: inset 0 0 0 4px var(--selected); }
.square:hover:not(:disabled) { filter: brightness(1.08); }
.square:disabled { opacity: 1; cursor: default; }

.square.light.move-target { background: var(--move-light); }
.square.dark.move-target { background: var(--move-dark); }
.square.light.capture-target { background: var(--capture-light); }
.square.dark.capture-target { background: var(--capture-dark); }

.game-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.resign { color: #a61b1b; }

/* Sign-in dialog */
dialog {
  width: min(92vw, 400px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin: 0 0 12px; }

dialog label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-weight: bold;
}

dialog input {
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  padding: 8px;
  border: 1px solid #888888;
  border-radius: 6px;
}

.field-help { margin: -4px 0 10px; font-size: 0.85rem; color: var(--muted); }
.auth-error { color: #a61b1b; min-height: 1.2em; margin: 4px 0; }
.auth-error[data-kind="info"] { color: var(--purple); }
.dialog-buttons { display: flex; gap: 10px; align-items: center; }
.auth-switch { display: flex; flex-direction: column; align-items: flex-start; margin: 12px 0 0; font-size: 0.9rem; }

@media (max-width: 720px) {
  .lobby {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    padding: 8px 16px 16px;
  }

  .lobby > * { grid-area: auto !important; }
  .lobby-title { text-align: center; }
  .controls { padding: 0 0 16px; text-align: center; }
  .control-links { justify-content: center; }
  .lobby-status { margin-inline: auto; }
  .history-panel, .leaderboard-panel { min-height: 200px; margin: 0 0 16px; }
  .player-name { order: -1; margin: 0 0 12px; }
  .lobby-title { order: -2; }
}
