/* Harbourfall — one stylesheet, no build step. */

:root {
  color-scheme: light dark;

  --bg: #f3efe6;
  --ink: #22201c;
  --muted: #6d675d;
  --card: #fffdf8;
  --line: #ddd6c8;
  --accent: #1c6b8c;
  --accent-ink: #ffffff;
  --danger: #b3352c;

  /* board */
  --sea: #a8cfe0;
  --tile-edge: rgba(0, 0, 0, .35);
  --token: #f2ead6;
  --token-edge: rgba(0, 0, 0, .35);
  --token-ink: #2a2721;
  --token-hot: #b3352c;
  --piece-edge: rgba(0, 0, 0, .55);
  --robber: #3a3730;
  --jetty: rgba(90, 70, 40, .6);
  --port-any: #f2ead6;
  --port-edge: rgba(0, 0, 0, .4);
  --port-ink: #2a2721;
  --pick: rgba(255, 255, 255, .55);
  --pick-on: #ffd34d;
  --pick-ring: #7a5b00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --ink: #e9e5dd;
    --muted: #9b958a;
    --card: #212528;
    --line: #343a3e;
    --accent: #4d9cc0;
    --accent-ink: #06222e;
    --danger: #e0655a;
    --sea: #24506a;
    --token: #e8e0cc;
    --pick: rgba(255, 255, 255, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.screen { min-height: 100dvh; }
/* Every card-based screen centres the same way. */
#welcome, #curtain, #local-setup, #online-home, #lobby {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; padding: 1.25rem;
}
#welcome[hidden], #curtain[hidden], #local-setup[hidden],
#online-home[hidden], #lobby[hidden] { display: none; }
[hidden] { display: none !important; }

h1 { font-size: 1.75rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.sub { color: var(--muted); margin: 0 0 1rem; }
.hint { color: var(--muted); font-size: .875rem; min-height: 1.4em; margin: .6rem 0 0; }
.version { color: var(--muted); font-size: .75rem; margin: 0; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: .9rem;
  padding: 1.25rem; width: min(30rem, 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
.card.center { text-align: center; }

fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0; margin-bottom: .5rem; }

.name-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; }
.swatch { width: 1.1rem; height: 1.1rem; border-radius: .3rem; border: 1px solid rgba(0,0,0,.35); flex: none; }
input[type="text"] {
  flex: 1; min-width: 0; font: inherit; padding: .55rem .7rem;
  border: 1px solid var(--line); border-radius: .5rem;
  background: var(--bg); color: var(--ink);
}
.row-actions { display: flex; gap: .5rem; }

.check { display: flex; align-items: center; gap: .55rem; margin-bottom: 1rem; }
.check input { width: 1.1rem; height: 1.1rem; }

.field { display: block; margin-bottom: .8rem; }
.field span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.field input { width: 100%; }

.divider {
  display: flex; align-items: center; gap: .7rem;
  color: var(--muted); font-size: .85rem; margin: 1.1rem 0;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* The code gets read aloud and typed by children — make it unmistakable. */
.room-code {
  font: 700 2.6rem/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .18em; text-align: center; margin: .2rem 0 .6rem;
  padding: .5rem; background: var(--bg); border-radius: .6rem;
}
.code-input {
  font: 700 1.4rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .2em; text-align: center; text-transform: uppercase;
}
.lobby-heading { margin: 1.2rem 0 .5rem; font-size: .95rem; color: var(--muted); }

.lobby-seat {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .1rem; border-bottom: 1px solid var(--line);
}
.lobby-seat:last-child { border-bottom: 0; }
.lobby-seat .who { flex: 1; }
.lobby-seat .tag { font-size: .78rem; color: var(--muted); }

.trouble {
  font-size: .8rem; color: var(--danger); font-weight: 600; white-space: nowrap;
}
.waiting { color: var(--muted); }

button {
  font: inherit; cursor: pointer; border-radius: .55rem; padding: .55rem .9rem;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.big { width: 100%; padding: .8rem; font-size: 1.05rem; }
button.ghost { background: transparent; }
button.small { padding: .35rem .6rem; font-size: .85rem; }
button.danger { border-color: var(--danger); color: var(--danger); background: transparent; font-weight: 600; }

/* --- game shell ---------------------------------------------------------- */

#game { display: flex; flex-direction: column; height: 100dvh; }

#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .55rem .8rem; border-bottom: 1px solid var(--line); background: var(--card);
  padding-top: max(.55rem, env(safe-area-inset-top));
}
.turn { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.turn #turn-note { color: var(--muted); font-size: .875rem; }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; font-weight: 600;
  padding: .2rem .55rem; border-radius: .45rem; white-space: nowrap;
}
.dice { font-size: 1.15rem; letter-spacing: .1em; }

main { flex: 1; display: flex; min-height: 0; }

/* The water fills the whole board area. The SVG keeps its aspect ratio, so
   without this the sea ends in hard bands wherever the panel is a different
   shape to the island. */
#board-wrap {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
  padding: 0; background: var(--sea);
}
#board { width: 100%; height: 100%; max-height: 100%; display: block; }
#board .target { cursor: pointer; }
#board .target:hover circle, #board .target:hover polygon { opacity: .85; }

#panel {
  width: min(23rem, 40vw); flex: none; border-left: 1px solid var(--line);
  background: var(--card); overflow-y: auto; padding: .75rem;
  display: flex; flex-direction: column; gap: .75rem;
  padding-bottom: max(.75rem, env(safe-area-inset-bottom));
}

@media (max-width: 800px) {
  main { flex-direction: column; }
  #board-wrap { flex: none; height: 46dvh; }
  #panel { width: auto; border-left: 0; border-top: 1px solid var(--line); flex: 1; }
}

/* --- players ------------------------------------------------------------- */

.player {
  display: flex; align-items: center; gap: .5rem; padding: .35rem .45rem;
  border-radius: .45rem; font-size: .9rem;
}
.player.is-turn { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.player .dot { width: .85rem; height: .85rem; border-radius: 50%; border: 1px solid rgba(0,0,0,.35); flex: none; }
.player .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .tally { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.player .pts { font-weight: 700; }
.badge {
  font-size: .7rem; padding: .05rem .3rem; border-radius: .3rem;
  border: 1px solid var(--line); color: var(--muted);
}

/* --- hand ---------------------------------------------------------------- */

#hand { border-top: 1px solid var(--line); padding-top: .6rem; }
.hand-title { font-size: .8rem; color: var(--muted); margin-bottom: .35rem; }
.cards { display: flex; flex-wrap: wrap; gap: .35rem; }
.res {
  display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .5rem;
  border: 1px solid var(--line); border-radius: .45rem; font-size: .85rem;
  font-variant-numeric: tabular-nums;
}
.res .pip { width: .7rem; height: .7rem; border-radius: .2rem; border: 1px solid rgba(0,0,0,.3); }
.res.zero { opacity: .35; }
.devcard {
  padding: .25rem .5rem; border: 1px dashed var(--line); border-radius: .45rem; font-size: .85rem;
}

/* --- prompt + actions ---------------------------------------------------- */

#prompt { font-size: .95rem; }
#prompt .ask { font-weight: 600; }
#prompt .why { color: var(--muted); font-size: .85rem; }

#actions { display: flex; flex-wrap: wrap; gap: .45rem; }
#actions button { flex: 1 1 auto; min-width: 7.5rem; }
#actions .confirm-row { display: flex; gap: .45rem; width: 100%; }
#actions .confirm-row button { flex: 1; }
/* Destructive controls never sit in the same run as ordinary ones. */
#actions .danger-zone {
  width: 100%; margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--line);
}

/* --- log ----------------------------------------------------------------- */

#log-box { border-top: 1px solid var(--line); padding-top: .5rem; }
#log-box summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
#log { margin: .5rem 0 0; padding-left: 1.2rem; font-size: .85rem; color: var(--muted); }
#log li { margin: .15rem 0; }
#log li.big { color: var(--ink); font-weight: 600; }

/* --- modal --------------------------------------------------------------- */

.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 20;
}
.modal-card {
  background: var(--card); border-radius: .9rem; padding: 1.1rem;
  width: min(28rem, 100%); max-height: 85dvh; overflow-y: auto;
}
.modal-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.modal-actions button { flex: 1; }
.modal-actions .danger-zone { width: 100%; }

.counter { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; }
.counter .label { flex: 1; display: flex; align-items: center; gap: .4rem; }
.counter .n { min-width: 2.5rem; text-align: center; font-variant-numeric: tabular-nums; }
.counter button { padding: .3rem .7rem; }

/* Final scores get their own layout: the detail line wraps onto its own row so
   it can never squeeze the player's name out of existence. */
.final-row { display: flex; gap: .55rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.final-row:last-child { border-bottom: 0; }
.final-row .dot { margin-top: .3rem; }
.final-row .who { font-weight: 600; }
.final-row .detail { color: var(--muted); font-size: .85rem; }
.final-row .col { min-width: 0; flex: 1; }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: .45rem; }
.choice-grid button { width: 100%; }
.pill-row { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }

/* --- toast --------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(1rem, env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: .6rem .9rem; border-radius: .5rem;
  font-size: .9rem; max-width: min(28rem, 92vw); z-index: 30; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
