:root {
  /* Palette: #FFFD98 lime cream, #BDE4A7 / #B3D2B2 celadon, #9FBBCC / #8DACC9 powder blue, #7A9CC6 wisteria */
  --bg: #B3D2B2;
  --ink: #1d2b3a;
  --muted: #3c5068;
  --panel: rgba(255, 255, 250, 0.85);
  --line: rgba(29, 43, 58, 0.16);
  --surface: #fbfdf6;
  --accent: #2f5582;   /* wisteria, darkened for readable text */
  --p1: #2f5582;
  --p2: #3f6b3a;       /* celadon, darkened */
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;   /* the visible height: excludes mobile browser toolbars */
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "bar" "stage" "status";
}
.bar { grid-area: bar; }
#stage { grid-area: stage; }
.status { grid-area: status; }

/* isolation keeps the CSS2D labels' z-indexes below the overlay */
#stage { position: relative; min-height: 0; overflow: hidden; isolation: isolate; }
#stage canvas { display: block; touch-action: none; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}

h1 .back {
  color: var(--muted);
  text-decoration: none;
  font-weight: 400;
  margin-right: 2px;
}
h1 .back:hover { color: var(--accent); }

.scores { display: flex; gap: 8px; }

.score {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  border: 2px solid transparent;
  background: rgba(0, 0, 0, 0.04);
  transition: border-color 0.2s, background 0.2s;
}
.score .name { font-size: 13px; color: var(--muted); }
.score .name.editable {
  cursor: pointer;
  border-bottom: 1px dashed currentColor;
}
.score .name.editable::after { content: " ✎"; font-size: 11px; opacity: 0.7; }
.score .name.editable:has(input)::after { content: none; }
.score .name.editable:hover, .score .name.editable:focus-visible { color: var(--ink); outline: none; }
.name-input {
  font: inherit;
  font-size: 13px;
  width: 9.5em;
  padding: 1px 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}
.score .num { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.score.p1 .num { color: var(--p1); }
.score.p2 .num { color: var(--p2); }
.score.active.p1 { border-color: var(--p1); background: rgba(122, 156, 198, 0.22); }
.score.active.p2 { border-color: var(--p2); background: rgba(189, 228, 167, 0.5); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-left: auto;
}
.controls label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

select, button {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
}
button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
button.ghost:hover { filter: none; background: #eef5e6; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.status {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  z-index: 2;
}
#status { font-weight: 600; min-height: 1.4em; }

.help { font-size: 13px; color: var(--muted); max-width: 640px; }
.help summary { cursor: pointer; text-align: right; }
.help ul { margin: 6px 0 0; padding-left: 18px; }

/* Online invite panel, floating over the top of the board view */
.invite {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  width: min(480px, calc(100% - 32px));
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(29, 43, 58, 0.15);
}
.invite[hidden] { display: none; }
.invite-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.invite-row { display: flex; gap: 6px; }
.invite-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.rematch-wait {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: auto;
  max-width: calc(100% - 32px);
  font-weight: 600;
}
.rematch-wait[hidden] { display: none; }

/* Modal dialog (native <dialog>) */
.dialog {
  border: none;
  border-radius: 14px;
  padding: 22px 24px 18px;
  width: min(380px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(20, 30, 40, 0.3);
}
.dialog::backdrop { background: rgba(20, 30, 40, 0.4); }
.dialog h2 { margin: 0 0 6px; font-size: 20px; }
.dialog p { margin: 0 0 18px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button { padding: 7px 16px; }

/* Seed-count labels over each pit */
.pit-label {
  pointer-events: none;
  font: 700 13px/1 system-ui, sans-serif;
  color: #fff;
  background: rgba(29, 43, 58, 0.75);
  padding: 3px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  transition: transform 0.15s;
}
.pit-label.store { font-size: 16px; padding: 4px 10px; }
.pit-label.p1.store { background: var(--p1); }
.pit-label.p2.store { background: var(--p2); }
.pit-label.bump { transform: scale(1.25); }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 30, 40, 0.35);
  z-index: 5;
}
.overlay[hidden] { display: none; }
.card {
  background: var(--surface);
  border-radius: 14px;
  padding: 24px 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 32px);
}
.card h2 { margin: 0 0 6px; }
.card p { margin: 0 0 16px; color: var(--muted); }

@media (max-width: 640px) {
  /* Status right under the header on phones, so a floating browser toolbar
     at the bottom can never hide it. */
  #app {
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "bar" "status" "stage";
  }
  .bar {
    gap: 6px 10px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  h1 { font-size: 18px; }
  .score { padding: 3px 10px; }
  .score .num { font-size: 16px; }
  .controls { margin-left: 0; gap: 6px; width: 100%; }
  .controls .lbl { display: none; }       /* menus carry aria-labels */
  /* Menus keep their natural width and wrap to a second row when needed. */
  .controls label { flex: 1 1 auto; }
  .controls select { width: 100%; padding: 4px 6px; }
  /* iOS Safari zooms the whole page when a field under 16px is focused. */
  select, input, .name-input { font-size: 16px; }
  .status {
    padding: 6px 12px;
    border-top: none;
    border-bottom: 1px solid var(--line);
  }
  #status { font-size: 14px; }
  .help summary { text-align: left; }
  .invite { top: 8px; }
}
