/* Tidewords. Palette and marks borrowed from nautical charts: shallow-water blue,
   paper-white tiles, navy ink outlines, depth contours and soundings. */
:root {
  --shallows: #bfdce6;
  --shoal: #a8cddb;
  --paper: #f8fbf9;
  --ink: #12263f;
  --ink-soft: #3f556f;
  --sunfish: #f4b23c;
  --sunfish-pale: #fbe6b8;
  --urchin: #6a3d9a;
  --urchin-pale: #dccbee;
  --water: #8dbdd0;
  --water-pale: #dcebf1;
  --kraken: #0e1726;
  --line: rgba(18, 38, 63, 0.2);
  --display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --text: 'Barlow Semi Condensed', 'Avenir Next Condensed', 'Helvetica Neue', Arial, sans-serif;
  --glyph-eye: var(--paper);
  --radius: 10px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--shallows);
  color: var(--ink);
  font: 500 1.0625rem/1.45 var(--text);
}
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--urchin); outline-offset: 2px; }

/* ---------- the sea ---------- */
.sea { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.sea .shoal ellipse { fill: var(--shoal); fill-opacity: 0.22; stroke: var(--ink); stroke-opacity: 0.16; stroke-width: 1.2; }
.sea .soundings text { font: italic 400 15px var(--display); fill: var(--ink); fill-opacity: 0.17; }

/* ---------- shared controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 2.75rem; padding: 0.5rem 1.15rem;
  border: 1.5px solid var(--ink); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
  font-weight: 600; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }
.btn-primary { background: var(--ink); color: var(--paper); box-shadow: 0 3px 0 #000a1a; }
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 0 #000a1a; }
.btn-small { min-height: 2.1rem; padding: 0.2rem 0.75rem; font-size: 0.95rem; box-shadow: 0 2px 0 var(--ink); }
.btn-plain { border-color: transparent; background: none; box-shadow: none; text-decoration: underline; text-underline-offset: 0.2em; }
.btn-plain:hover:not(:disabled), .btn-plain:active:not(:disabled) { transform: none; box-shadow: none; }

.field {
  min-height: 2.75rem; padding: 0.5rem 0.8rem; width: 100%;
  border: 1.5px solid var(--ink); border-radius: var(--radius);
  background: var(--paper);
}
.field::placeholder { color: var(--ink-soft); opacity: 0.75; }
label.over { display: block; font-weight: 600; margin-bottom: 0.3rem; }

.wordmark {
  font-family: var(--display); font-style: italic; font-weight: 600;
  letter-spacing: -0.03em; line-height: 0.95;
  text-decoration: underline wavy var(--urchin); text-decoration-thickness: 0.045em; text-underline-offset: 0.14em;
  text-decoration-skip-ink: none;
}

.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translate(-50%, 1rem); opacity: 0; visibility: hidden;
  max-width: min(32rem, calc(100vw - 2rem)); padding: 0.7rem 1.1rem;
  background: var(--ink); color: var(--paper); border-radius: var(--radius);
  font-weight: 500; text-align: center;
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s; z-index: 10;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

/* ---------- home ---------- */
.home { max-width: 68rem; margin: 0 auto; padding: clamp(1.5rem, 6vw, 5rem) clamp(1rem, 4vw, 2.5rem) 3rem; }
.home .wordmark { font-size: clamp(3.6rem, 15vw, 9.5rem); display: inline-block; padding-bottom: 0.18em; }
.home-lede { max-width: 34rem; margin-top: 1.25rem; font-size: clamp(1.15rem, 2.4vw, 1.4rem); line-height: 1.4; }
.home-grid { display: grid; gap: 2.5rem; margin-top: 2.5rem; align-items: start; }
@media (min-width: 52rem) { .home-grid { grid-template-columns: minmax(0, 22rem) minmax(0, 1fr); gap: 4rem; } }

.entry { display: grid; gap: 1rem; }
.entry .btn { width: 100%; }
.entry-join { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.6rem; align-items: end; padding-top: 1rem; border-top: 1.5px dashed var(--line); }
.entry-join .field { text-transform: uppercase; letter-spacing: 0.25em; font-weight: 700; }
.entry-join .btn { width: auto; }
.entry-error { color: #8a1c2b; font-weight: 600; }

.legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
@media (min-width: 30rem) { .legend { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.legend li { display: grid; gap: 0.6rem; align-content: start; }
.legend .tile { aspect-ratio: 5 / 4; cursor: default; container-type: inline-size; }
.legend p { font-size: 0.98rem; line-height: 1.35; color: var(--ink-soft); }
.legend p strong { color: var(--ink); font-weight: 700; display: block; }
.howto { margin-top: 2rem; max-width: 40rem; display: grid; gap: 0.5rem; counter-reset: step; }
.howto li { display: grid; grid-template-columns: 1.6rem 1fr; gap: 0.4rem; }
.howto li::before { counter-increment: step; content: counter(step) '.'; font-family: var(--display); font-style: italic; font-weight: 600; }

/* ---------- game shell ---------- */
.game { max-width: 82rem; margin: 0 auto; padding: 0.9rem clamp(0.75rem, 2.5vw, 2rem) 3rem; display: grid; gap: 1rem; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; }
.bar .wordmark { font-size: 1.9rem; padding-bottom: 0.15em; margin-right: auto; color: inherit; }
.bar-code { display: flex; align-items: baseline; gap: 0.5rem; }
.bar-code b { font-size: 1.45rem; font-weight: 700; letter-spacing: 0.2em; }
.offline { padding: 0.5rem 0.9rem; border-radius: var(--radius); background: var(--ink); color: var(--paper); font-weight: 600; }

.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem;
  padding: 0.9rem 1.2rem; border: 1.5px solid var(--ink); border-radius: var(--radius);
  background: var(--paper); border-left-width: 14px;
}
.status.t-sunfish { border-left-color: var(--sunfish); }
.status.t-urchin { border-left-color: var(--urchin); }
.status-main { flex: 1 1 16rem; min-width: 0; }
.status h2 { font-family: var(--display); font-style: italic; font-weight: 600; font-size: clamp(1.5rem, 4.5vw, 2.3rem); line-height: 1.1; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.status h2 .count { font-style: normal; font-family: var(--text); font-weight: 700; display: inline-block; min-width: 1.5em; padding: 0 0.35em; margin-left: 0.3em; text-align: center; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 0.8em; }
.status p { color: var(--ink-soft); margin-top: 0.2rem; }
.tally { display: flex; gap: 0.5rem; }
.tally span { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.7rem 0.25rem 0.5rem; border: 1.5px solid var(--ink); border-radius: 999px; font-weight: 700; white-space: nowrap; }
.tally svg { width: 1.2rem; height: 1.2rem; }
.tally .t-sunfish { background: var(--sunfish); }
.tally .t-urchin { background: var(--urchin); color: #fff; --glyph-eye: var(--urchin); }

.controls:empty { display: none; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; }
.controls p { color: var(--ink-soft); }
.clue-form { display: grid; grid-template-columns: minmax(0, 1fr) 5.2rem auto; gap: 0.6rem; width: 100%; max-width: 34rem; align-items: end; }
.clue-form label { font-weight: 600; font-size: 0.95rem; display: grid; gap: 0.2rem; }

.table { display: grid; gap: 1.25rem; align-items: start; }
@media (min-width: 62rem) { .table { grid-template-columns: minmax(0, 1fr) 19rem; } }
.phase-lobby .table { grid-template-columns: minmax(0, 1fr); max-width: 46rem; }
.phase-lobby #board, .phase-lobby #log { display: none; }
.side { display: grid; gap: 1.25rem; }

/* ---------- the chart ---------- */
.chart {
  --gap: clamp(4px, 1.1vw, 10px);
  display: grid; grid-template-columns: 1.1rem minmax(0, 1fr); grid-template-rows: 1.2rem auto; gap: 2px var(--gap);
}
.chart-cols, .chart-rows { font: italic 500 0.85rem var(--display); color: var(--ink-soft); display: grid; gap: var(--gap); text-align: center; }
.chart-cols { grid-column: 2; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.chart-rows { grid-row: 2; grid-template-rows: repeat(5, minmax(0, 1fr)); align-items: center; }
.tiles { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--gap); container-type: inline-size; }

.tile {
  position: relative; display: grid; place-items: center; align-content: center; gap: 4%;
  aspect-ratio: 1 / 1; min-width: 0; padding: 4% 2%;
  border: 1.5px solid var(--ink); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
@media (min-width: 40rem) { .tile { aspect-ratio: 4 / 3; } }
.tile .word { font-weight: 700; font-size: clamp(0.66rem, 3.25cqi, 1.3rem); letter-spacing: 0.01em; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: clip; white-space: nowrap; }
.legend .tile .word { font-size: clamp(0.8rem, 13cqi, 1.15rem); }
.tile .glyph { width: 34%; max-width: 3rem; aspect-ratio: 1; display: none; }
.tile[class*='k-'] .glyph { display: block; }
button.tile:not(:disabled) { cursor: pointer; }
button.tile:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--ink); background: #fff; }
button.tile:not(:disabled):active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }

/* What a navigator sees before a tile is turned over: a pale wash and a small mark. */
.tile.k-sunfish { background: var(--sunfish-pale); --glyph-eye: var(--sunfish-pale); }
.tile.k-urchin { background: var(--urchin-pale); color: #3a1c5c; --glyph-eye: var(--urchin-pale); }
.tile.k-water { background: var(--water-pale); }
.tile.k-water .glyph { color: #5c93a8; }
.tile.k-kraken { background: #3b4658; color: #fff; --glyph-eye: #3b4658; }

/* Turned over: full colour, sunk into the chart. */
.tile.is-revealed { box-shadow: none; transform: translateY(3px); }
.tile.is-revealed .word { font-weight: 500; opacity: 0.8; }
.tile.is-revealed.k-sunfish { background: var(--sunfish); --glyph-eye: var(--sunfish); }
.tile.is-revealed.k-urchin { background: var(--urchin); color: #fff; --glyph-eye: var(--urchin); }
.tile.is-revealed.k-water { background: var(--water); }
.tile.is-revealed.k-water .glyph { color: var(--ink); opacity: 0.6; }
.tile.is-revealed.k-kraken { background: var(--kraken); color: #fff; --glyph-eye: var(--kraken); }
.tile.is-revealed.k-kraken .glyph { color: #e8505b; }
.tile.is-new { animation: turn 0.55s cubic-bezier(0.3, 1.4, 0.5, 1) both; }
@keyframes turn {
  0% { transform: translateY(-6px) rotateX(88deg); }
  100% { transform: translateY(3px) rotateX(0); }
}
/* Once the game ends, tiles nobody turned over show their colour but stay raised. */
.phase-over .tile:not(.is-revealed) { opacity: 0.78; }

/* ---------- crews ---------- */
.crews { display: grid; gap: 0.9rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 62rem) { .phase-playing .crews, .phase-over .crews { grid-template-columns: minmax(0, 1fr); } }
.crew { border: 1.5px solid var(--ink); border-radius: var(--radius); background: var(--paper); overflow: hidden; }
.crew h3 { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.8rem; font-size: 1.2rem; font-weight: 700; border-bottom: 1.5px solid var(--ink); }
.crew h3 svg { width: 1.5rem; height: 1.5rem; flex: none; }
.crew-sunfish h3 { background: var(--sunfish); --glyph-eye: var(--sunfish); }
.crew-urchin h3 { background: var(--urchin); color: #fff; --glyph-eye: var(--urchin); }
.crew dl { padding: 0.7rem 0.8rem 0.85rem; display: grid; gap: 0.7rem; }
.crew dt { font-size: 0.92rem; font-weight: 600; color: var(--ink-soft); }
.crew dd { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.6rem; min-height: 2.1rem; }
.who { font-weight: 600; overflow-wrap: anywhere; }
.who.me::after { content: ' (you)'; font-weight: 500; color: var(--ink-soft); }
.who.away { opacity: 0.5; }
.who.away::after { content: ' (away)'; font-weight: 500; }
.nobody { color: var(--ink-soft); font-style: italic; }
.watching { grid-column: 1 / -1; color: var(--ink-soft); }

/* ---------- log ---------- */
.log { border: 1.5px solid var(--ink); border-radius: var(--radius); background: var(--paper); }
.log h3 { padding: 0.5rem 0.8rem; font-size: 1.05rem; font-weight: 700; border-bottom: 1.5px solid var(--line); }
.log ol { max-height: 19rem; overflow-y: auto; padding: 0.3rem 0; }
.log li { padding: 0.3rem 0.8rem 0.3rem 0.65rem; border-left: 5px solid transparent; line-height: 1.3; font-size: 1rem; }
.log li.t-sunfish { border-left-color: var(--sunfish); }
.log li.t-urchin { border-left-color: var(--urchin); }
.log li.is-clue { margin-top: 0.3rem; font-weight: 600; }
.log q { font-family: var(--display); font-style: italic; font-weight: 600; quotes: none; font-size: 1.08em; }
.log .empty { color: var(--ink-soft); font-style: italic; border: 0; padding-left: 0.8rem; }

@media (max-width: 30rem) {
  .crews { grid-template-columns: minmax(0, 1fr); }
  .clue-form { grid-template-columns: minmax(0, 1fr) 4.6rem; }
  .clue-form .btn { grid-column: 1 / -1; }
  .status { padding: 0.75rem 0.9rem; border-left-width: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- two-player co-op ---------- */
.aside { margin-top: 1.25rem; max-width: 40rem; padding-top: 1rem; border-top: 1.5px dashed var(--line); }
.deal-form { display: flex; flex-wrap: wrap; align-items: end; gap: 0.6rem; }
.deal-form label { font-weight: 600; font-size: 0.95rem; display: grid; gap: 0.2rem; }
.deal-form .field { width: auto; min-width: 11rem; }
.tally .t-find { background: var(--paper); padding-left: 0.7rem; }
.tally .t-turns { background: var(--ink); color: var(--paper); padding-left: 0.7rem; }
.tally .t-turns.is-low { background: #b3261e; border-color: #b3261e; }
.crew-left { margin-left: auto; font-size: 0.95rem; font-weight: 600; }
.chart-note { margin: 0.8rem 0 0 1.1rem; padding-left: var(--gap, 0.5rem); max-width: 44rem; color: var(--ink-soft); font-size: 0.98rem; line-height: 1.35; }
/* A tile this player tried that was open water on the partner's chart. */
.tile.is-missed { box-shadow: none; transform: translateY(3px); }
.tile.is-missed .word { text-decoration: line-through; text-decoration-thickness: 2px; opacity: 0.6; }
.tile.is-missed::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: repeating-linear-gradient(135deg, transparent 0 7px, rgba(18, 38, 63, 0.13) 7px 9px);
}
