:root {
  --paper: #f6efe3;
  --ink: #2b211a;
  --muted: #6d5f52;
  --wood: #8a5a32;
  --wood-dark: #5e3a1d;
  --pit: #4a2c14;
  --seed: #efe3c8;
  --line: #d9c9b0;
  --focus: #1f6feb;
  --card: #fffaf2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1d1914;
    --ink: #f2e8da;
    --muted: #b3a493;
    --line: #3d342b;
    --card: #27211b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font:
    16px/1.5 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

.top,
main,
footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  font-size: 1.6rem;
  margin: 18px 0 8px;
}

h2 {
  font-size: 1.15rem;
  margin: 12px 0;
}

nav {
  display: flex;
  gap: 16px;
}

a,
.link {
  color: inherit;
}

button {
  font: inherit;
  cursor: pointer;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
}

.primary {
  background: var(--wood-dark);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 22px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 12px;
}

legend {
  padding: 0;
  margin-bottom: 4px;
}

.panel h2 {
  margin-top: 0;
}

.panel .controls {
  margin: 8px 0 16px;
}

.players label {
  margin-right: 14px;
}

.seat {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}

/* drop-down menus drawn like the text boxes, the same in every browser */
select {
  font: inherit;
  color: var(--ink);
  appearance: none;
  padding: 5px 30px 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b5a4a' stroke-width='1.5'/%3E%3C/svg%3E")
    no-repeat right 10px center;
}

select:disabled {
  opacity: 0.5;
}

.problems {
  color: #b42318;
  margin: 8px 0;
}

.problems:empty {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 0.92rem;
}

/* Player cards */
.cards {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: 8px;
}

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.card.current {
  border-color: var(--colour);
}

.card.out {
  opacity: 0.45;
}

.card .name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card .meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.timer {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  margin-top: 6px;
  overflow: hidden;
}

.timer span {
  display: block;
  height: 100%;
  background: var(--colour);
  transform-origin: left;
}

/* The game, top to bottom: whose turn, the players, the board, the moves. */
.play:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
}

.info {
  display: contents;
}
#headline {
  order: 0;
  margin: 0;
}
.cards {
  order: 2;
  margin: 0;
}
.board-area {
  order: 3;
}
.moves {
  order: 4;
}

.board-area {
  display: flex;
  justify-content: center;
  padding: 22px 4px;
}

/* The board, after a real Ọpọ́n: two long, dark, matte planks rounded at both ends, joined along
   a seam with a small square piece where they meet at each end; six round wells in each plank;
   pale green seeds. It lies flat on wide screens and stands upright on phones (.upright). */
.board {
  width: min(100%, 760px);
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  filter: drop-shadow(0 12px 16px rgb(0 0 0 / 0.3));
}

.board::before,
.board::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 14px;
  aspect-ratio: 1;
  transform: translateY(-50%);
  background: linear-gradient(140deg, #6a5038, #3b2a1d);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.6);
  z-index: 2;
}

.board::before {
  left: 1.2%;
}

.board::after {
  right: 1.2%;
}

.plank {
  display: flex;
  gap: 1.6%;
  padding: 1.6% 3%;
  border-radius: 9999px;
  background: linear-gradient(
    180deg,
    #2e2723 0%,
    #221d1a 30%,
    #1a1613 70%,
    #241e1b 100%
  );
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.07),
    inset 0 -1px 0 rgb(0 0 0 / 0.4),
    inset 2px 0 3px rgb(255 255 255 / 0.05);
}

.pit {
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  padding: 0;
  position: relative;
  background: radial-gradient(
    circle at 50% 42%,
    #1b1714 0 52%,
    #151210 78%,
    #2a2420 100%
  );
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 -2px 2px rgb(255 255 255 / 0.07);
  color: #fff;
}

/* Whose pit: a dot just outside the board, in the owner's colour */
.pit::before {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--owner);
}

.plank.far .pit::before {
  left: 50%;
  top: -18px;
  transform: translateX(-50%);
}

.plank.near .pit::before {
  left: 50%;
  bottom: -18px;
  transform: translateX(-50%);
}

/* Upright on phones */
.board.upright {
  --plank: min(112px, 27vw);
  width: auto;
  flex-direction: row;
}

.board.upright::before,
.board.upright::after {
  top: auto;
  left: 50%;
  right: auto;
  width: calc(var(--plank) * 0.14);
  transform: translateX(-50%);
}

.board.upright::before {
  top: calc(var(--plank) * 0.05);
}

.board.upright::after {
  bottom: calc(var(--plank) * 0.05);
}

.board.upright .plank {
  width: var(--plank);
  flex-direction: column;
  gap: calc(var(--plank) * 0.07);
  padding: calc(var(--plank) * 0.1) calc(var(--plank) * 0.07);
  background: linear-gradient(
    90deg,
    #2e2723 0%,
    #221d1a 30%,
    #1a1613 70%,
    #241e1b 100%
  );
}

.board.upright .pit {
  flex: none;
  width: 100%;
}

.plank.left .pit::before {
  top: 50%;
  left: calc(var(--plank) * -0.07 - 17px);
  transform: translateY(-50%);
}

.plank.right .pit::before {
  top: 50%;
  right: calc(var(--plank) * -0.07 - 17px);
  transform: translateY(-50%);
}

.pit:disabled {
  cursor: default;
}

.pit.legal {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 2px rgb(255 236 190 / 0.45),
    0 0 10px rgb(255 236 190 / 0.25);
}

.pit.legal:hover,
.pit.legal:focus-visible {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 2px rgb(255 236 190 / 0.9),
    0 0 14px rgb(255 236 190 / 0.45);
}

.pit.active {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 2px #ffd27a;
}

.pit.taken {
  box-shadow:
    inset 0 5px 8px rgb(0 0 0 / 0.7),
    inset 0 0 0 3px var(--taker),
    0 0 12px var(--taker);
}

.seed {
  position: absolute;
  aspect-ratio: 1 / 0.86;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background-image: radial-gradient(
    circle at 35% 30%,
    rgb(255 255 255 / 0.5),
    transparent 48%
  );
  box-shadow:
    inset -1px -2px 2px rgb(0 0 0 / 0.22),
    0 1px 2px rgb(0 0 0 / 0.65);
}

.pit .count {
  position: absolute;
  inset: auto 0 2%;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  text-shadow: 0 1px 2px #000;
}

.moves {
  margin: 14px 0;
}

#log {
  max-height: 220px;
  overflow-y: auto;
  padding-left: 22px;
  color: var(--muted);
}

footer {
  color: var(--muted);
  font-size: 0.9rem;
  padding-block: 24px;
}

/* Setup: names and the agreed time per move */
.seat input[type="text"] {
  font: inherit;
  width: min(14em, 100%);
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}

.time {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

/* Pause, restart and the time rule, under whose turn it is */
.controls {
  order: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: -6px;
}

.controls button {
  font: inherit;
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.controls button[aria-pressed="true"] {
  background: var(--wood-dark);
  border-color: var(--wood-dark);
  color: #fff;
}

.continue {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.continue h3 {
  margin: 0 0 4px;
}

.continue p {
  margin: 0 0 10px;
  color: var(--muted);
}

.continue button:not(.primary) {
  font: inherit;
  margin-left: 8px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.standings {
  margin: 4px 0 0;
  padding-left: 1.4em;
}

.time-rule {
  color: var(--muted);
  font-size: 0.9rem;
  margin-left: 4px;
}

.play.paused .board {
  opacity: 0.55;
  filter: grayscale(0.4) drop-shadow(0 12px 16px rgb(0 0 0 / 0.3));
}

/* The rules: a floating card over the dimmed page, one topic per page */
.rules-card {
  width: min(460px, calc(100vw - 32px));
  border: 0;
  border-radius: 18px;
  padding: 18px 22px 16px;
  background: var(--card);
  color: var(--ink);
  box-shadow:
    0 24px 60px rgb(0 0 0 / 0.35),
    0 2px 8px rgb(0 0 0 / 0.2);
}

.rules-card::backdrop {
  background: rgb(20 14 10 / 0.55);
  backdrop-filter: blur(2px);
}

.rules-card[open] {
  animation: card-in 0.18s ease-out;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rules-card[open] {
    animation: none;
  }
}

.rules-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rules-step {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.rules-card .close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 6px;
}

.rules-card h2 {
  margin: 6px 0 8px;
  font-size: 1.3rem;
}

.rules-body {
  min-height: 9.5em;
}

.rules-body p {
  margin: 0 0 10px;
}

.rules-card footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  color: inherit;
  font-size: 1rem;
}

.rules-card footer button {
  font: inherit;
  padding: 6px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

.rules-card footer .primary {
  background: var(--wood-dark);
  border-color: var(--wood-dark);
  color: #fff;
}

.rules-card footer button:disabled {
  opacity: 0.4;
  cursor: default;
}

.dots {
  display: flex;
  gap: 6px;
}

.rules-card footer .dot {
  width: 9px;
  height: 9px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--line);
}

.rules-card footer .dot.on {
  background: var(--wood-dark);
  transform: scale(1.25);
}

.rules-more {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Players' pictures: a photo, or initials on the player's colour */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  flex: none;
  overflow: hidden;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-pick {
  cursor: pointer;
  border-radius: 50%;
}

.photo-pick .avatar {
  width: 40px;
  height: 40px;
  font-size: 0.9rem;
  box-shadow:
    0 0 0 2px var(--card),
    0 0 0 3px var(--line);
}

.photo-pick:hover .avatar,
.photo-pick:focus-within .avatar {
  box-shadow:
    0 0 0 2px var(--card),
    0 0 0 3px var(--focus);
}

.card .name .avatar {
  width: 30px;
  height: 30px;
}

/* The picture card: avatars, a photo, or initials */
.photo-pick {
  border: 0;
  padding: 0;
  background: none;
}

.picker h2 {
  margin: 0;
  font-size: 1.15rem;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.picker-option {
  border: 0;
  padding: 3px;
  border-radius: 50%;
  background: none;
  justify-self: center;
}

.picker-option .avatar {
  width: 56px;
  height: 56px;
  font-size: 0.9rem;
}

.picker-option.selected,
.picker-option:hover,
.picker-option:focus-visible {
  box-shadow: 0 0 0 3px var(--wood-dark);
}

.picker-photo {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  background: var(--wood-dark);
  color: #fff;
  cursor: pointer;
}

.picker-photo:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.picker-group {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.picker .picker-grid {
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding: 4px;
}

/* The header: the name with a seed on the left, the menu as a toolbar on the right */
.top {
  padding-top: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  white-space: nowrap;
}

.brand img {
  border-radius: 8px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1;
  white-space: nowrap;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.tool:hover {
  border-color: var(--wood);
  background: color-mix(in srgb, var(--card), var(--wood) 8%);
}

.tool svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool .when-off,
.tool.off .when-on {
  display: none;
}

.tool.off .when-off {
  display: block;
}

.tool.off {
  color: var(--muted);
}

@media (max-width: 640px) {
  .top {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .brand {
    font-size: 1.35rem;
  }
  .toolbar {
    width: 100%;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
  }
  .tool {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 7px 4px;
    border-radius: 12px;
    font-size: 0.75rem;
  }
  .tool[hidden] {
    display: none;
  }
}

/* Online: the room panel on the setup, joining, and the lobby */
.online {
  margin: 12px 0;
  padding: 12px 0 4px;
  border-top: 1px solid var(--line);
}

.online h3,
#lobby h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.online button,
.controls button:disabled {
  font: inherit;
}

.online button {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--wood-dark);
  background: var(--card);
  color: var(--ink);
}

.controls button:disabled {
  opacity: 0.45;
  cursor: default;
}

.invite,
.join-name {
  display: grid;
  gap: 6px;
  margin: 8px 0;
}

.invite input,
.join-name input {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.members {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  display: grid;
  gap: 8px;
}

.members li {
  display: flex;
  align-items: center;
  gap: 10px;
}

#lobby-guest[hidden] + *,
#lobby-host[hidden] ~ #start-online {
  display: none;
}
