/* style.css - how the page looks. */

/* Colours are kept in one place as "custom properties" so they are easy to change. */
:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --text: #1f2421;
  --muted: #6b716d;
  --line: #d9d4c7;
  --light-sq: #ece3cf;
  --dark-sq: #5b7a5e;
  --black-piece: #1f2421;
  --white-piece: #fbf8f2;
  --select: #e3b23c;
  --target: rgba(227, 178, 60, 0.55);
  --last: rgba(255, 255, 255, 0.18);
  --accent: #2f5d50;
}

* { box-sizing: border-box; }

/* Make sure anything marked hidden in the HTML really is hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* Stops the page bouncing or zooming when tapping quickly on phones. */
  touch-action: manipulation;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px;
}
.top h1 { font-size: 1.3rem; margin: 0; letter-spacing: 0.02em; }

.link-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
}

/* On phones the board and scoreboard stack; on wider screens they sit side by side. */
.layout {
  display: grid;
  gap: 16px;
  max-width: 980px;
  margin: 0 auto;
  padding: 0 16px 24px;
}
@media (min-width: 820px) {
  .layout { grid-template-columns: 1fr 300px; align-items: start; }
}

.status {
  min-height: 1.5em;
  margin-bottom: 8px;
  font-weight: 600;
}

/* The board is always square, never wider than the screen
   and never taller than most of it. */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(100%, 72vh, 600px);
  aspect-ratio: 1 / 1;
  border: 6px solid #3e3a32;
  border-radius: 4px;
  user-select: none;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--light-sq);
}
.sq.dark { background: var(--dark-sq); cursor: pointer; }
.sq.last::before { content: ""; position: absolute; inset: 0; background: var(--last); }
.sq.target::after {
  content: "";
  position: absolute;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: var(--target);
}

.piece {
  position: relative;
  width: 78%;
  height: 78%;
  border-radius: 50%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), 0 2px 3px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(12px, 4.5vw, 26px);
  line-height: 1;
}
.piece.b { background: var(--black-piece); color: var(--select); }
.piece.w { background: var(--white-piece); color: #9a7414; border: 1px solid #c9c1ad; }
.piece.selected { outline: 3px solid var(--select); outline-offset: 2px; }
.piece.king::after { content: "\265B"; } /* a crown symbol */

.players {
  display: flex;
  justify-content: space-between;
  width: min(100%, 72vh, 600px);
  margin-top: 8px;
  font-size: 0.95rem;
}
.player { display: flex; align-items: center; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.dot-b { background: var(--black-piece); }
.dot-w { background: var(--white-piece); border: 1px solid #c9c1ad; }
.count { color: var(--muted); }

.scores {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.scores h2 { font-size: 1rem; margin: 0 0 8px; }
.scores table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.scores th, .scores td {
  text-align: right;
  padding: 5px 4px;
  border-bottom: 1px solid var(--line);
}
.scores th:first-child, .scores td:first-child { text-align: left; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

dialog {
  border: none;
  border-radius: 10px;
  padding: 20px;
  width: min(92vw, 360px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin-top: 0; }
.choice {
  border: none;
  padding: 0;
  margin: 0 0 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}
.choice legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.choice label { display: flex; align-items: center; gap: 6px; min-height: 32px; }
.field { display: block; font-weight: 600; margin-bottom: 14px; }
.field input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px;
  font-size: 16px; /* 16px or more stops iPhones zooming in on the box */
  border: 1px solid var(--line);
  border-radius: 6px;
}
.primary {
  width: 100%;
  padding: 12px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

/* ---------- Course 4: room for the ratings table ---------- */
@media (min-width: 820px) {
  .layout { grid-template-rows: auto 1fr; }
  .game { grid-row: span 2; }
  .scores { align-self: start; }
}
