/* Hexwords: Fine Hall, c. 1948 — a chalkboard masthead over a paper page,
 * with typewriter accents for the small print. Players stay blue/red;
 * the chrome (buttons, rules, headings) borrows the board's slate green. */
:root {
  --paper: #f7f3ea;        /* warm paper page */
  --card: #fbf8ef;         /* slightly lifted card stock */
  --ink: #26241e;          /* warm near-black */
  --slate: #2e463a;        /* chalkboard green */
  --slate-deep: #24382e;
  --chalk: #f2efe6;
  --rail: #a5825a;         /* the chalk tray */
  --blue: #5b8fc9;
  --blue-deep: #2a5e96;
  --red: #d05c5c;
  --red-deep: #a63232;
  --line: #cfc7b2;         /* hairlines on paper */
  --gray: #5a5648;         /* muted ink */
  --good: #1a7a2e;
  --bad: #c0392b;
  --serif: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --mono: "American Typewriter", "Courier New", Courier, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
}

/* ---- Header: the chalkboard ---- */
.masthead {
  background-color: var(--slate);
  /* Faint chalk dust: a tiled noise SVG, white speckle at low alpha. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0.1 0 0 0 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  border-bottom: 4px solid var(--rail);
  color: var(--chalk);
}
.masthead-inner {
  max-width: 780px;    /* the lobby's column, so the two left edges agree */
  margin: 0 auto;
  padding: 26px 16px 20px;
}
.masthead h1 {
  font-size: 34px;
  font-weight: 600;
  letter-spacing: .5px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.chalk-hex { width: 36px; height: 36px; flex: none; }
/* Both wrap at the column edge, like everything below the board. */
.standfirst {
  color: rgba(242, 239, 230, .82);
  margin: 8px 0 0;
}
.fine-hall {
  font-style: italic;
  font-size: 13.5px;
  color: rgba(242, 239, 230, .62);
  margin: 10px 0 0;
}
.fine-hall cite { font-style: normal; }   /* italic within italic reverts to roman */
/* During play the masthead becomes a slim band so the board gets the height,
 * and tracks the game screen's wider column instead of the lobby's. */
body.playing .masthead-inner { padding: 10px 16px; max-width: 1180px; }
body.playing .masthead h1 { font-size: 20px; gap: 8px; }
body.playing .chalk-hex { width: 20px; height: 20px; }
body.playing .standfirst, body.playing .fine-hall { display: none; }

/* ---- Lobby ---- */
#lobby {
  max-width: 780px;
  margin: 24px auto 0;
  padding: 0 16px 60px;
}
.resume-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 16px;
  padding: 10px 14px;
  background: #f6ead0;
  border: 1px solid #d8c592;
  border-radius: 3px;
}
.resume-bar .btn-row { flex: none; }
.modes {
  display: flex;
  gap: 16px;
  align-items: stretch;
}
.modes .card {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 18px 20px;
}
.card .hint { margin: 0 0 14px; }
.card button.primary { margin-top: auto; width: 100%; }
.card h2, .rules h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 600;
  margin: 0 0 8px;
}
.hint {
  color: var(--gray);
  font-family: var(--mono);
  font-size: 12.5px;
  margin: 4px 0 0;
}
.error { color: var(--bad); }

#phrase {
  width: 100%;
  font-family: var(--mono);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid #8a8371;
  border-radius: 2px;
  background: #fffdf7;
  color: var(--ink);
  margin: 0 0 10px;
}
#phrase.shake { outline: 2px solid var(--bad); animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

button {
  font-family: var(--mono);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 9px 14px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
button:hover:not(:disabled) { background: #efe9da; }
button.primary {
  background: var(--slate);
  border-color: var(--slate);
  color: var(--chalk);
}
button.primary:hover:not(:disabled) { background: var(--slate-deep); }
button:disabled {
  background: #eee9dc;
  border-color: var(--line);
  color: #a49c88;
  cursor: default;
}
button.small { font-size: 11px; padding: 3px 10px; }
/* A two-step button that has been tapped once and is asking to be sure. */
button.confirming {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

.settings { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 18px; }
.settings label { font-family: var(--mono); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.settings label.check input { margin: 0; accent-color: var(--slate); }
.bot-level { display: flex; gap: 6px; align-items: center; margin: 0 0 10px; }
.settings select, .card select {
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 24px 4px 8px;
  border: 1px solid #8a8371;
  border-radius: 2px;
  color: var(--ink);
  /* Native chrome clashes with the paper theme; a plain box + chevron. */
  appearance: none;
  -webkit-appearance: none;
  background: #fffdf7 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%2326241e'/%3E%3C/svg%3E") no-repeat right 8px center;
}


.rules { margin-top: 28px; }
.rules h2 { margin-top: 26px; }
.rules h2:first-child { margin-top: 0; }
.rules ol { padding-left: 20px; margin: 8px 0 0; }
.rules li { margin-bottom: 8px; }

.example-strip { display: flex; gap: 18px; margin: 12px 0 0; }
.example-strip figure { flex: 1 1 0; margin: 0; }
.example-strip svg, .example-full svg { width: 100%; height: auto; display: block; }
.example-strip figcaption, .example-full figcaption {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--gray);
  margin-top: 4px;
}
.example-full { margin: 12px 0 0; }
.static .hex polygon { cursor: default; }
.static .hex:hover polygon { fill: #fff; }

/* ---- Chips & dots ---- */
.chip {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .04em;
  padding: 0 6px 1px;
  color: #fff;
  border-radius: 3px;
}
.chip.c1 { background: var(--blue-deep); }
.chip.c2 { background: var(--red-deep); }
.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 8px; flex: none;
}
.dot.c1 { background: var(--blue); }
.dot.c2 { background: var(--red); }

/* ---- Game screen ---- */
#game { max-width: 1180px; margin: 16px auto 0; padding: 0 16px 40px; }
#banner {
  background: #f6ead0;
  border: 1px solid #d8c592;
  border-radius: 3px;
  padding: 8px 12px;
  margin: 0 0 12px;
}

.game-layout { display: flex; gap: 24px; align-items: flex-start; }
.board-wrap { flex: 1 1 auto; min-width: 0; position: relative; }
#drag-lens {
  position: absolute;
  transform: translate(-50%, -100%);   /* sits above the finger */
  background: var(--card);
  border: 1px solid var(--ink);
  border-radius: 3px;
  padding: 2px 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  z-index: 5;
}
#btn-fit {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
}
#board {
  width: 100%; height: auto; display: block;
  touch-action: none;       /* a touch on the board spells; the page scrolls from elsewhere */
  user-select: none;
  -webkit-user-select: none;
}

.sidebar {
  flex: 0 0 280px;
  position: sticky; top: 12px;
}
.sidebar p { margin: 0 0 8px; }
/* Whose turn on the left, the clock on the right: one glance, one line. */
.turn-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.side-bottom {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#timer-line {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;   /* digits keep their width, so no jitter */
}
#timer-line.low { color: var(--bad); }
.sidebar h3 {
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin: 20px 0 8px;
}

.tray {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 10px 12px 12px;
}
#word {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 2px;
  min-height: 32px;
  overflow-wrap: anywhere;
  display: flex;
  align-items: center;
}
#word.empty {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--gray);
}
#word-status { font-family: var(--mono); font-size: 12.5px; min-height: 20px; margin: 0 0 8px; }
.muted { color: var(--gray); }
.good { color: var(--good); }
.warn { color: #8a5a00; font-weight: 500; }
.btn-row { display: flex; gap: 6px; }
.btn-row button { flex: 1 1 0; padding: 8px 4px; white-space: nowrap; }
.btn-row.center { margin-top: 4px; }

#invite { margin-top: 10px; }
#btn-reconnect { margin-top: 10px; }
.offer {
  margin-top: 8px;
  padding: 8px 10px;
  background: #f6ead0;
  border: 1px solid #d8c592;
  border-radius: 3px;
  font-size: 14px;
}
.offer .btn-row { margin-top: 6px; }

#log {
  list-style: none; margin: 0; padding: 0;
  max-height: clamp(200px, 45vh, 520px); overflow-y: auto;
  font-family: var(--mono);
  font-size: 13px;
}
#log li {
  display: flex; align-items: center;
  padding: 3px 0;
  border-bottom: 1px dotted #b8b09c;
}
.mv-word { font-weight: 600; }
a.mv-word {
  color: inherit;
  text-decoration: underline dotted 1px;
  text-underline-offset: 2px;
}
a.mv-word:hover { text-decoration-style: solid; }
.mv-len { margin-left: auto; color: var(--gray); font-size: 11px; }

/* ---- Hexes ---- */
.hex polygon {
  fill: #fff;
  stroke: #999;
  stroke-width: 1;
  cursor: pointer;
  transition: fill .18s ease-out, stroke .18s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .hex polygon { transition: none; }
}
.hex text {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 15px;
  fill: #111;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}
.hex:hover polygon { fill: #f0f0f0; }
.hex.p1 polygon, .hex.p1:hover polygon { fill: var(--blue); stroke: var(--blue-deep); cursor: default; }
.hex.p2 polygon, .hex.p2:hover polygon { fill: var(--red); stroke: var(--red-deep); cursor: default; }
.hex.p1 text, .hex.p2 text { fill: #fff; }
/* Colour-vision aid: Red hexagons are hatched, so the two sides differ in
 * texture as well as hue. The pattern lives in each board's own <defs>. */
body.cv #board .hex.p2 polygon, body.cv #board .hex.p2:hover polygon { fill: url(#hatch-board); }
body.cv #ex1 .hex.p2 polygon { fill: url(#hatch-ex1); }
body.cv #ex2 .hex.p2 polygon { fill: url(#hatch-ex2); }
body.cv #ex3 .hex.p2 polygon { fill: url(#hatch-ex3); }
body.cv #ex-full .hex.p2 polygon { fill: url(#hatch-ex-full); }
.hex.sel1 polygon, .hex.sel1:hover polygon {
  fill: #bdd3ea;
  stroke: var(--blue-deep);
  stroke-width: 1.5;
}
.hex.sel2 polygon, .hex.sel2:hover polygon {
  fill: #f0c4c4;
  stroke: var(--red-deep);
  stroke-width: 1.5;
}
.hex:focus { outline: none; }
.hex:focus-visible polygon { stroke: #111; stroke-width: 2.2; }
.hex.last polygon { stroke-width: 2.2; }
.hex.last.p1 polygon { stroke: #1c3f66; }
.hex.last.p2 polygon { stroke: #7c2424; }

.borders path {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.border-blue { stroke: var(--blue); }
.border-red { stroke: var(--red); }

/* ---- Pause ---- */
#pause-overlay {
  position: fixed; inset: 0;
  /* Opaque on purpose: nothing of the board shows through. */
  background: var(--slate);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0.1 0 0 0 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--chalk);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
  padding: 24px;
}
.pause-card { max-width: 480px; text-align: center; }
.pause-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .18em;
  font-family: var(--mono);
  color: rgba(242, 239, 230, .7);
  margin: 0 0 6px;
}
.pause-clock {
  font-family: var(--mono);
  font-size: 44px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin: 0 0 22px;
}
.pause-fact {
  font-style: italic;
  font-size: 16px;
  line-height: 1.55;
  color: rgba(242, 239, 230, .85);
  margin: 0 0 26px;
}
.pause-fact cite { font-style: normal; }
#pause-overlay button.primary {
  background: var(--chalk);
  border-color: var(--chalk);
  color: var(--slate);
  padding: 10px 28px;
}
#pause-overlay button.primary:hover:not(:disabled) { background: #fff; }
#pause-note { color: rgba(242, 239, 230, .55); margin-top: 14px; }

/* ---- Overlay ---- */
#overlay {
  position: fixed; inset: 0;
  background: rgba(38, 36, 30, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.overlay-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  text-align: center;
  padding: 28px 44px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .25);
}
.overlay-card h2 { font-size: 36px; margin: 0 0 4px; }
.overlay-card h2.t1 { color: var(--blue-deep); }
.overlay-card h2.t2 { color: var(--red-deep); }
.overlay-card p { color: var(--gray); margin: 0 0 16px; }
#overlay-score { font-family: var(--mono); font-size: 14px; color: var(--ink); margin: -6px 0 6px; }
#overlay-stats { font-family: var(--mono); font-size: 12px; margin: 0 0 16px; }
#overlay-score:empty, #overlay-stats:empty { display: none; }

/* ---- Small screens ---- */
/* Three mode cards need more room than two did; stack them a little earlier. */
@media (max-width: 760px) {
  .modes { flex-direction: column; }
}
@media (max-width: 640px) {
  .example-strip { flex-direction: column; }
}
@media (max-width: 820px) {
  .game-layout { flex-direction: column; align-items: stretch; }
  .sidebar { position: static; flex: none; }
}
