:root {
  background: var(--sw-surface);
  color: var(--sw-on-surface);
  font-family: var(--sw-body);
  line-height: 1.4;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; min-height: 100dvh; overflow-x: hidden; }
[hidden] { display: none !important; }
a { color: inherit; text-underline-offset: .25em; }
button, input, select { font: inherit; }
button, input, select {
  min-height: 2.75rem;
  border: 1px solid var(--sw-border);
  border-radius: calc(var(--sw-radius) / 2);
}
button, .button {
  color: var(--sw-on-raised);
  background: var(--sw-raised);
  font-weight: 680;
  padding: .65rem 1rem;
}
button:not(:disabled):not([aria-disabled="true"]) { cursor: pointer; }
button:disabled { opacity: .64; }
button:not(:disabled):not([aria-disabled="true"]):hover { border-color: var(--sw-accent); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--sw-focus);
  outline-offset: 3px;
}
input {
  width: 100%;
  min-width: 0;
  padding: .55rem .7rem;
  background: var(--sw-surface);
  color: var(--sw-on-surface);
}
input::placeholder { color: var(--sw-muted); }
h1, h2, h3, p { margin: 0; }

.bar {
  display: flex;
  align-items: center;
  gap: clamp(.6rem, 2.5vw, 1.75rem);
  padding: .5rem max(clamp(.75rem, 2.5vw, 1.75rem), env(safe-area-inset-right)) .5rem max(clamp(.75rem, 2.5vw, 1.75rem), env(safe-area-inset-left));
  border-bottom: 1px solid color-mix(in srgb, var(--sw-border) 55%, transparent);
}
.launcher { font-weight: 800; letter-spacing: -.02em; text-decoration: none; font-size: .9rem; color: var(--sw-muted); }
.title { display: flex; align-items: baseline; gap: .75rem; min-width: 0; }
h1 { font: 800 clamp(1.35rem, 3.2vw, 1.9rem)/1.05 var(--sw-display); letter-spacing: -.035em; white-space: nowrap; }
.title p { color: var(--sw-muted); font-size: .9rem; white-space: nowrap; }
.bar-actions { display: flex; gap: .45rem; margin-inline-start: auto; }
.bar-actions button, .bar-actions .button { padding: .45rem .9rem; white-space: nowrap; }

.button { display: inline-grid; place-items: center; min-height: 2.75rem; border: 1px solid var(--sw-border); border-radius: calc(var(--sw-radius) / 2); text-decoration: none; }
.button:hover { border-color: var(--sw-accent); }
.primary { color: var(--sw-on-action); background: var(--sw-action); border-color: var(--sw-action); }
.primary:not(:disabled):hover { filter: brightness(1.08); border-color: var(--sw-focus); }

.table {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(.4rem, 1.4vh, 1rem);
  padding: clamp(.5rem, 1.6vh, 1.2rem) max(clamp(.75rem, 2.5vw, 1.75rem), env(safe-area-inset-right)) max(clamp(.5rem, 1.6vh, 1.25rem), env(safe-area-inset-bottom)) max(clamp(.75rem, 2.5vw, 1.75rem), env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 42%, var(--sw-raised), var(--sw-surface) 78%);
}
.table-header { display: flex; justify-content: space-between; align-items: center; gap: .4rem 1rem; flex-wrap: wrap; }
.table h2 { font: 700 clamp(1.05rem, 2.2vw, 1.35rem)/1.15 var(--sw-display); }
#match-status { margin-top: .1rem; color: var(--sw-muted); font-size: .94rem; min-height: 1.4em; }
.table[data-your-turn="true"] #match-status, .table[data-status="finished"] #match-status { color: var(--sw-accent); }

.scores { display: flex; flex-wrap: wrap; gap: .45rem; }
.score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  border: 2px solid var(--sw-border);
  padding: .2rem .6rem;
  border-radius: calc(var(--sw-radius) / 2);
  color: var(--sw-on-raised);
  background: var(--sw-raised);
  font-size: .85rem;
}
.score[data-side="0"] { border-color: var(--sw-side-0-edge); border-style: var(--sw-side-0-border); }
.score[data-side="1"] { border-color: var(--sw-side-1-edge); border-style: var(--sw-side-1-border); }
.score[data-current-turn="true"] { color: var(--sw-accent); background: color-mix(in srgb, var(--sw-raised) 80%, var(--sw-accent)); }
.score-name { min-width: 0; overflow-wrap: anywhere; unicode-bidi: isolate; }
.score-value { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* The board is the largest rectangle of its shape that fits the space the table leaves it. A wide space lays the
   stores at the ends. A tall one puts them above and below, so a phone held upright still gets large pits. */
.well {
  flex: 1;
  min-height: 9rem;
  display: grid;
  place-items: center;
  container-type: size;
}
.board {
  --across: 8.7;
  --down: 2.6;
  --gap: clamp(.25rem, 1.2cqmin, .8rem);
  width: min(100cqw, calc(100cqh * var(--across) / var(--down)), 70rem);
  aspect-ratio: var(--across) / var(--down);
  display: grid;
  grid-template-columns: 1.35fr repeat(6, 1fr) 1.35fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "os t0 t1 t2 t3 t4 t5 ms"
    "os b0 b1 b2 b3 b4 b5 ms";
  gap: var(--gap);
  padding: var(--gap);
  border-radius: calc(var(--sw-radius) * 1.6);
  border: 1px solid var(--sw-border);
  background: var(--sw-board-inert);
}
/* Upright, the board is turned a quarter: your pits run down the left, your store is at the bottom, and the
   opponent's pits run up the right, so it fills the height of a phone. */
.board[data-layout="tall"] {
  width: min(100cqw, 34rem);
  height: min(100cqh, 175cqw);
  aspect-ratio: auto;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: .8fr repeat(6, 1fr) .8fr;
  grid-template-areas:
    "os os"
    "b0 t0" "b1 t1" "b2 t2" "b3 t3" "b4 t4" "b5 t5"
    "ms ms";
}
.board[data-seat="1"] { --bottom-side: 0; --top-side: 1; }
.board[data-seat="2"] { --bottom-side: 1; --top-side: 0; }

.pit {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  padding: 0;
  container-type: size;
  border-radius: 50%;
  border: 2px solid var(--sw-border);
  color: var(--sw-on-raised);
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--sw-board-cell) 82%, var(--sw-surface)), var(--sw-board-cell) 70%);
  box-shadow: inset 0 .25rem .6rem color-mix(in srgb, var(--sw-surface) 55%, transparent);
  transition: transform var(--sw-quick), box-shadow var(--sw-quick), background-color var(--sw-quick);
}
.board[data-layout="tall"] .pit { border-radius: 2.2rem; }
.pit[data-row="bottom"] { border-color: var(--bottom-edge); }
.pit[data-row="top"] { border-color: var(--top-edge); }
.board[data-seat="1"] { --bottom-edge: var(--sw-side-0-edge); --top-edge: var(--sw-side-1-plate); }
.board[data-seat="2"] { --bottom-edge: var(--sw-side-1-plate); --top-edge: var(--sw-side-0-edge); }
.board[data-seat="1"] .pit[data-row="bottom"], .board[data-seat="2"] .pit[data-row="top"] { border-style: var(--sw-side-0-border); }
.board[data-seat="1"] .pit[data-row="top"], .board[data-seat="2"] .pit[data-row="bottom"] { border-style: var(--sw-side-1-border); }
.pit[data-own="true"][data-legal="true"] {
  background-color: var(--sw-board-cell-active);
  outline: 3px solid var(--sw-board-cell-target);
  outline-offset: -3px;
}
@media (hover: hover) {
  .pit[data-legal="true"]:hover { transform: translateY(-3%); background: var(--sw-board-cell-active); }
}
.pit[data-selected="true"][data-own="true"] { box-shadow: 0 0 0 3px var(--sw-accent), inset 0 .25rem .6rem color-mix(in srgb, var(--sw-surface) 55%, transparent); }
.pit[data-trail="true"] { box-shadow: inset 0 0 0 3px var(--sw-board-trail); }
.pit[data-taken="true"] { box-shadow: inset 0 0 0 4px var(--sw-board-taken); }
.pit[data-drop="true"] { transform: scale(1.07); box-shadow: 0 0 0 4px var(--sw-board-trail); background: var(--sw-board-cell-active); }
.pit[aria-disabled="true"][data-own="true"]:not([data-count="0"]):not([data-selected="true"]) { opacity: .9; }
.pit[data-count="0"] .count { opacity: .55; }

.seeds {
  position: absolute;
  inset: 12% 14% 30%;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 4cqmin;
  pointer-events: none;
}
.seed {
  width: 19cqmin;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--sw-on-raised), color-mix(in srgb, var(--sw-on-raised) 55%, var(--sw-accent)) 75%);
  box-shadow: 0 .06rem .12rem color-mix(in srgb, var(--sw-surface) 70%, transparent);
}
.seed:nth-child(3n) { background: radial-gradient(circle at 35% 30%, var(--sw-caution), color-mix(in srgb, var(--sw-caution) 55%, var(--sw-accent)) 75%); }
.seed:nth-child(5n) { background: radial-gradient(circle at 35% 30%, var(--sw-on-raised), color-mix(in srgb, var(--sw-on-raised) 45%, var(--sw-danger)) 80%); }
.seeds[data-many="true"] { gap: 2.5cqmin; inset: 8% 10% 28%; }
.seeds[data-many="true"] .seed { width: 12.5cqmin; }
.pit .count {
  position: absolute;
  inset: auto 0 5%;
  margin-inline: auto;
  width: fit-content;
  min-width: 1.5em;
  padding: 0 .35em;
  border-radius: 1em;
  text-align: center;
  font-weight: 800;
  font-size: clamp(.8rem, 24cqmin, 1.7rem);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  color: var(--sw-on-surface);
  background: color-mix(in srgb, var(--sw-surface) 72%, transparent);
}
.board[data-layout="tall"] .pit .seeds { inset: 6% 30% 6% 7%; gap: 3px; }
.board[data-layout="tall"] .pit .seed { width: 21cqh; }
.board[data-layout="tall"] .pit .seeds[data-many="true"] .seed { width: 14cqh; }
.board[data-layout="tall"] .pit .count { inset: 50% 6% auto auto; margin: 0; transform: translateY(-50%); font-size: clamp(.9rem, 40cqh, 1.6rem); }

.store {
  position: relative;
  min-width: 0;
  min-height: 0;
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1rem;
  padding: 3%;
  border-radius: calc(var(--sw-radius) * 1.3);
  border: 2px solid var(--sw-border);
  background: color-mix(in srgb, var(--sw-board-inert) 70%, var(--sw-surface));
  box-shadow: inset 0 .3rem .8rem color-mix(in srgb, var(--sw-surface) 65%, transparent);
  overflow: hidden;
}
.store[data-side="0"] { border-color: var(--sw-side-0-edge); border-style: var(--sw-side-0-border); color: var(--sw-side-0-color); background: var(--sw-side-0-plate); }
.store[data-side="1"] { border-color: var(--sw-side-1-edge); border-style: var(--sw-side-1-border); color: var(--sw-side-1-color); background: var(--sw-side-1-plate); }
.store[data-drop="true"] { box-shadow: 0 0 0 4px var(--sw-board-trail); }
.store-name { flex: none; font-size: clamp(.62rem, 9cqmin, .85rem); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; opacity: .85; text-align: center; max-width: 100%; overflow-wrap: anywhere; line-height: 1.15; }
.store .count { flex: none; font: 800 clamp(1.2rem, 22cqmin, 2.4rem)/1 var(--sw-display); font-variant-numeric: tabular-nums; }
.store .seeds { position: static; inset: auto; display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 3px; flex: 0 1 auto; min-height: 0; max-height: 40%; overflow: hidden; }
.store .seed { width: clamp(6px, 6.5cqmin, 12px); }
.store[data-side="0"] .seed { background: var(--sw-side-0-color); box-shadow: none; }
.store[data-side="1"] .seed { background: var(--sw-side-1-color); box-shadow: none; }
/* Above and below the pits, a store is a bar that reads across. */
.board[data-layout="tall"] .store { flex-direction: row; justify-content: center; align-items: center; gap: .6rem; padding: 0 .6rem; }
.board[data-layout="tall"] .store .seeds { max-height: 100%; max-width: 20%; gap: 2px; align-content: center; }
.board[data-layout="tall"] .store .count { font-size: clamp(1.3rem, 62cqh, 2.2rem); }
.board[data-layout="tall"] .store-name { flex: 0 1 auto; min-width: 0; max-width: 66%; font-size: clamp(.62rem, 30cqh, .85rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board[data-layout="tall"] .store .seed { width: clamp(5px, 17cqh, 8px); }
.board[data-sowing="true"] .pit { transition-duration: 60ms; }

.invite { width: min(34rem, 100%); align-self: center; }
.invite label { display: block; margin-bottom: .3rem; font-weight: 720; font-size: .9rem; }
.join-controls { display: flex; gap: .35rem; }
.join-controls button { flex: 0 0 auto; }
/* Over the table, so a message never changes the size of the board. */
.activity {
  position: fixed;
  inset: auto 0 max(.5rem, env(safe-area-inset-bottom));
  z-index: 4;
  width: fit-content;
  max-width: calc(100vw - 1.5rem);
  margin-inline: auto;
  padding: .4rem .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  border: 1px solid var(--sw-border);
  border-radius: calc(var(--sw-radius) / 2);
  background: var(--sw-raised);
  color: var(--sw-accent);
  font-size: .9rem;
}
.activity:has(p:empty):has(button[hidden] + button[hidden]) { display: none; }

#result { position: fixed; inset: auto 0 max(1.25rem, env(safe-area-inset-bottom)); margin-inline: auto; z-index: 6; width: min(24rem, calc(100vw - 1.5rem)); text-align: center; box-shadow: 0 .5rem 2rem color-mix(in srgb, var(--sw-surface) 70%, transparent); }
#result h2 { margin-bottom: .25rem; color: var(--sw-accent); }
#result .actions { margin: .9rem 0 0; }
#result-reason { margin-top: .4rem; }
@media (max-height: 30rem) {
  #result { inset: auto auto max(.5rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left)); margin: 0; width: min(21rem, 42vw); padding: .7rem; }
  #result h2 { font-size: 1.1rem; }
  #result .hint { font-size: .8rem; }
}

dialog {
  width: min(34rem, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: clamp(1rem, 3vw, 1.5rem);
  color: var(--sw-on-raised);
  background: var(--sw-raised);
  border: 1px solid var(--sw-border);
  border-radius: var(--sw-radius);
  overflow: auto;
}
dialog::backdrop { background: color-mix(in srgb, var(--sw-surface) 72%, transparent); }
dialog header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; }
dialog h2 { font: 700 1.5rem/1.1 var(--sw-display); }
dialog h3 { font: 700 1.1rem/1.1 var(--sw-display); margin-block: 1.1rem .5rem; }
.close { min-width: 2.75rem; padding: 0; }
.hint { color: var(--sw-muted); font-size: .9rem; }
.options { border: 0; padding: 0; margin: 0 0 1rem; display: grid; gap: .4rem; min-width: 0; }
.options legend { padding: 0; margin-bottom: .4rem; font-weight: 720; font-size: .9rem; }
.options label { position: relative; display: block; cursor: pointer; }
.options input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; opacity: 0; cursor: pointer; }
.options span { display: block; border: 2px solid color-mix(in srgb, var(--sw-border) 60%, transparent); border-radius: calc(var(--sw-radius) / 2); padding: .5rem .75rem; }
.options small { display: block; color: var(--sw-muted); font-size: .84rem; }
.options input:checked + span { border-color: var(--sw-accent); }
.options input:checked + span strong { color: var(--sw-accent); }
.options input:focus-visible + span { outline: 3px solid var(--sw-focus); outline-offset: 2px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .6rem; }
.computer-play { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.computer-play select { padding-inline: .6rem; background: var(--sw-raised); color: var(--sw-on-raised); }
.open-games { display: grid; gap: .45rem; padding-bottom: .9rem; margin-bottom: .9rem; border-bottom: 1px solid var(--sw-border); }
.open-games-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
dialog .open-games h3, .start-heading { margin: 0; }
.start-heading { margin-bottom: .6rem; }
#open-status { color: var(--sw-muted); font-size: .9rem; }
#open-status:empty, #open-list:empty, #open-note:empty { display: none; }
#open-note { color: var(--sw-caution); font-size: .9rem; }
#open-list { list-style: none; padding: .2rem; margin: -.2rem; display: grid; gap: .35rem; max-height: 12rem; overflow: auto; }
#open-list button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .75rem; text-align: start; }
#open-list button span:first-child { min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
#open-list button span:last-child { flex: none; color: var(--sw-accent); }
.menu-tools { display: flex; flex-wrap: wrap; gap: .5rem; }
.menu-tools .button { padding-inline: 1rem; }
#history-status:empty, #match-list:empty { display: none; }
#match-list { list-style: none; padding: 3px; margin: 0; display: grid; gap: .35rem; max-height: 14rem; overflow: auto; }
#match-list button { width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .15rem .5rem; text-align: left; padding: .45rem .65rem; }
#match-list button[aria-current="true"] { border-color: var(--sw-accent); }
#match-list button span { color: var(--sw-muted); font-size: .8rem; font-weight: 500; }
.realm { display: flex; margin-top: 1rem; font-size: .84rem; }
.realm a { color: var(--sw-muted); padding: .45rem .6rem; text-decoration: none; }
.realm a[aria-current] { color: var(--sw-on-raised); font-weight: 720; text-decoration: underline; }

@media (max-width: 40rem) {
  .title p { display: none; }
  .bar { gap: .55rem; }
  .launcher { font-size: .78rem; }
  .bar-actions { gap: .3rem; }
  .bar-actions button, .bar-actions .button { padding-inline: .6rem; font-size: .9rem; }
  h1 { font-size: 1.2rem; }
  .table-header { align-items: start; }
}
@media (max-width: 26rem) {
  .launcher { display: none; }
}
@media (max-width: 24rem) {
  .join-controls { flex-wrap: wrap; }
  .launcher { display: none; }
  h1 { font-size: 1.05rem; }
  .bar-actions button, .bar-actions .button { padding-inline: .45rem; font-size: .85rem; }
}
@media (max-height: 30rem) {
  .bar { padding-block: .25rem; }
  .bar button, .bar .button { min-height: 2.25rem; }
  .table { padding-block: .35rem; gap: .25rem; }
  .table-header { flex-wrap: nowrap; }
  .well { min-height: 7rem; }
  .title p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pit { transition: none; }
}
