:root {
  --ink: #15171c;
  --muted: #5b6270;
  --bg: #f4f1ea;
  --card: #fff;
  --accent: #2f6f4e;
  --line: #d9d4c8;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; color: var(--ink); text-decoration: none; }

nav { display: flex; gap: 0.75rem; }

nav a { color: var(--muted); text-decoration: none; padding: 0.2rem 0.6rem; border-radius: 999px; }

nav a[aria-current="page"] { color: #fff; background: var(--ink); }

.who { margin-left: auto; color: var(--muted); font-size: 0.9rem; }

.tag { color: var(--muted); font-size: 0.85rem; }

.help {
  width: 1.8rem;
  height: 1.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

@media (max-width: 40rem) { .top { flex-wrap: wrap; row-gap: 0.2rem; } .tag { order: 5; flex-basis: 100%; font-size: 0.8rem; } }

.again { font: inherit; font-size: 0.85rem; padding: 0.2rem 0.6rem; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }

main { position: relative; flex: 1; min-height: 0; }

canvas#view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: #9cc3df;
  outline: none;
}

canvas#view:focus-visible { box-shadow: inset 0 0 0 3px #f0b94a; }

.toast {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(90vw, 32rem);
  padding: 0.4rem 0.8rem;
  border-radius: 0.5rem;
  background: rgba(21, 23, 28, 0.85);
  color: #fff;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  text-align: center;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  background: #9cc3df;
  z-index: 1;
}

.code {
  position: absolute;
  top: 3rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  background: #f0b94a;
  color: var(--ink);
  font: 700 1.4rem/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.3em;
}

.sign {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  max-width: min(18rem, 60vw);
  padding: 0.6rem 0.8rem;
  border-radius: 0.5rem;
  background: #f4e9cf;
  color: var(--ink);
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.sign ul { margin: 0.3rem 0 0; padding-left: 1.1rem; }

.say, .keypad {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  display: flex;
  gap: 0.4rem;
  max-width: calc(100% - 9rem);
}

.keypad { bottom: 3.6rem; align-items: center; color: #fff; }

.say input, .keypad input {
  font: inherit;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  min-width: 0;
  width: 14rem;
}

.keypad input { width: 5.5rem; font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.3em; }

.count { align-self: center; color: var(--muted); font-size: 0.75rem; }

.heard {
  position: absolute;
  left: 0.75rem;
  bottom: 3.6rem;
  margin: 0;
  padding: 0.3rem 0.6rem;
  list-style: none;
  max-width: 22rem;
  font-size: 0.8rem;
  line-height: 1.35;
  color: #fff;
  background: rgba(21, 23, 28, 0.55);
  border-radius: 0.5rem;
  pointer-events: none;
}

.note-btn { background: #8a6a3a; }

.emotes {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  display: flex;
  gap: 0.3rem;
}

.chart:not([hidden]) ~ .emotes { display: none; }

.emotes button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.7rem;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  touch-action: manipulation;
}

@media (max-width: 40rem) {
  .emotes { left: 0.75rem; right: auto; bottom: auto; top: 0.75rem; transform: none; }
  .emotes button { font-size: 0.75rem; padding: 0.3rem 0.5rem; }
}

.say button, .keypad button {
  font: inherit;
  padding: 0.45rem 0.9rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
}

.pad {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: grid;
  grid-template-columns: repeat(3, 2.75rem);
  grid-template-areas: ". up ." "left . right" ". down .";
  gap: 0.25rem;
}

.pad button {
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.85);
  font-size: 1rem;
  touch-action: none;
}

.pad button:nth-child(1) { grid-area: up; }
.pad button:nth-child(2) { grid-area: left; }
.pad button:nth-child(3) { grid-area: right; }
.pad button:nth-child(4) { grid-area: down; }

@media (min-width: 60rem) { .pad { display: none; } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

body.page { display: block; min-height: 100%; }

.prose { max-width: 40rem; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

.prose h1 { font-size: 1.8rem; line-height: 1.2; }

.prose a { color: var(--accent); }

.prose code { background: #eee9de; padding: 0.1em 0.3em; border-radius: 0.25rem; font-size: 0.9em; }

.status {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.4rem 0.7rem;
  border-radius: 0.5rem;
  background: rgba(21, 23, 28, 0.85);
  color: #fff;
  font-size: 0.85rem;
}

.status .crew { display: flex; flex-wrap: wrap; gap: 0.25rem 0.4rem; margin-top: 0.3rem; }

.status .crew span { padding: 0.05rem 0.45rem; border-radius: 999px; background: rgba(255, 255, 255, 0.16); }

.status .crew span.idle { background: #b8432f; }

.status .crew span.me { outline: 1px solid #ffe08a; }

.status.warn { background: rgba(140, 30, 20, 0.9); }

.status.hurt { background: rgba(130, 85, 20, 0.9); }

.hint {
  position: absolute;
  top: 3.2rem;
  left: 0.75rem;
  max-width: 22rem;
  padding: 0.5rem 0.85rem;
  border-radius: 0.5rem;
  background: #f4e9cf;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chart {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  background: rgba(20, 16, 10, 0.75);
}

.chart canvas { max-width: 96%; max-height: 86%; width: auto; height: auto; border: 6px solid #5c4a2a; border-radius: 4px; background: #e9dcbf; }

.chart-note { margin: 0.4rem 0 0.8rem; color: #f4e9cf; font-size: 0.9rem; }

.actions {
  position: absolute;
  right: 10rem;
  bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.act, .leave, .note-btn {
  font: inherit;
  padding: 0.6rem 1rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  touch-action: none;
}

.leave { background: #5b6270; }

.actions .gone { visibility: hidden; }

.act.down { background: #f0b94a; color: var(--ink); }

@media (min-width: 60rem) { .actions { right: 0.75rem; bottom: 3.5rem; } }

@media (max-width: 40rem) {
  .toast { top: 3rem; }
  .status { top: auto; bottom: 7.6rem; left: 0.75rem; right: auto; max-width: calc(100% - 11rem); font-size: 0.78rem; }
  .hint { top: auto; bottom: 10.4rem; left: 0.75rem; right: auto; max-width: calc(100% - 11rem); }
  .actions { right: 0.75rem; bottom: 10.6rem; }
  .heard { max-width: calc(100% - 11rem); font-size: 0.75rem; }
}

@media (min-width: 60rem) { .toast { top: auto; bottom: 3.6rem; left: 50%; transform: translateX(-50%); max-width: 36rem; width: fit-content; } }

.board {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 19rem;
  max-width: calc(100% - 1.5rem);
  max-height: 42vh;
  display: flex;
  flex-direction: column;
  border-radius: 0.5rem;
  background: rgba(244, 233, 207, 0.94);
  color: var(--ink);
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.board-toggle { display: none; }

.board-body { padding: 0.5rem 0.7rem 0.6rem; overflow: auto; }

.board h2 { margin: 0 0 0.3rem; font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase; color: #5c4a2a; }

.furthest { margin: 0 0 0.4rem; font-weight: 600; }

.log { margin: 0; padding-left: 0; list-style: none; }

.log li { margin: 0.15rem 0; }

.log li.wreck { color: #7a1a1a; }

.log li.day { margin-top: 0.35rem; font-size: 0.7rem; letter-spacing: 0.04em; text-transform: uppercase; color: #8a7a5a; }

@media (max-width: 40rem) {
  .board { width: auto; max-height: none; background: transparent; box-shadow: none; }
  .board-toggle { display: block; margin-left: auto; font: inherit; font-size: 0.8rem; padding: 0.3rem 0.6rem; border: 0; border-radius: 999px; background: rgba(244, 233, 207, 0.94); color: var(--ink); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
  .board-body { display: none; margin-top: 0.3rem; max-height: 40vh; border-radius: 0.5rem; background: rgba(244, 233, 207, 0.96); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
  .board.open .board-body { display: block; }
}

.intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(20, 16, 10, 0.6);
  z-index: 2;
}

.intro-card {
  width: min(30rem, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 1.2rem 1.4rem 1.3rem;
  border-radius: 0.75rem;
  background: var(--card);
  color: var(--ink);
  line-height: 1.45;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.intro-card h2 { margin: 0 0 0.5rem; font-size: 1.5rem; }

.intro-card p { margin: 0 0 0.6rem; }

.intro-card .keys { color: var(--muted); font-size: 0.85rem; }

.name-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.8rem; }

.name-form label { flex-basis: 100%; font-weight: 600; }

.name-form input { flex: 1; min-width: 8rem; font: inherit; padding: 0.45rem 0.7rem; border: 1px solid var(--line); border-radius: 0.5rem; }

.name-form button { font: inherit; padding: 0.45rem 1rem; border: 0; border-radius: 0.5rem; background: var(--accent); color: #fff; }
