/* Othello web UI — styled with Nitor brand tokens.
   Palette and type mirror nitor.com / the Nitor NDA template. */

:root {
  --white: #ffffff;
  --lightgrey: #f5f5f5;
  --grey: #e6e6e6;
  --black: #0b0b0b;
  --red: #f73928;
  --red-050: #fff2e5;
  --red-100: #fdd3b1;
  --red-200: #fba070;
  --grey-500: #5a5a5a;
  --grey-400: #868686;
  --line: #c9c9c9;
  --sans: Roobert, "Helvetica Neue", Arial, sans-serif;
  --mono: "Roobert Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--lightgrey);
  color: var(--black);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 500; letter-spacing: -0.02em; margin: 0; }

.mono {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---------- top bar ---------- */
.bar {
  background: var(--black);
  color: var(--lightgrey);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
}
.bar .mark { width: 20px; height: 20px; flex: none; }
.bar .mark svg { display: block; width: 100%; height: 100%; }
.bar .brand {
  display: flex;
  align-items: center;
  gap: 16px;
  color: inherit;
  text-decoration: none;
}
.bar .brand:hover .lab { color: var(--lightgrey); }
.bar .lab {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #b5b5b5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar .grow { flex: 1; }
.bar .count {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lightgrey);
  white-space: nowrap;
}
.bar .count b { color: var(--red); font-weight: 500; }
.bar .save {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--grey-400);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.bar .save span { width: 5px; height: 5px; border-radius: 50%; background: var(--grey-500); }
.bar .save.live span { background: var(--red); }
.bar .save.live { color: #b5b5b5; }
.bar .save.err span { background: var(--red); }

/* ---------- masthead ---------- */
/* Same grid as .wrap below, so the text under the logo lines up with the white
   board card. The card is padded (26px each side); the matcher pulls the text in
   by that much so its measure equals the board's inner white area. */
.masthead {
  max-width: 1320px;
  margin: 0 auto;
  padding: 40px 22px 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 30px;
}
@media (max-width: 900px) {
  .masthead { grid-template-columns: minmax(0, 1fr); }
}
.masthead-main { min-width: 0; padding: 0 26px; }
.masthead .wm-wrap { margin-bottom: 26px; }
.masthead .wm { display: block; width: 108px; }
.masthead .wm svg { display: block; width: 100%; height: auto; }
.masthead h1 { font-size: 30px; line-height: 1.12; }
.masthead .sub {
  font-size: 15px;
  color: var(--grey-500);
  margin: 14px 0 0;
}
.masthead .sub a { color: var(--red); text-decoration: underline; text-underline-offset: 2px; }
.masthead .sub a:hover { color: var(--black); }

@media (max-width: 900px) {
  /* Board and text are full width; align the text with the white card instead. */
  .masthead-main { padding: 0; }
}

/* ---------- intro text (below the board, above the footer) ---------- */
/* Mirrors the masthead grid so the measure lines up with the white board card. */
.intro {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 22px 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 30px;
}
@media (max-width: 900px) {
  .intro { grid-template-columns: minmax(0, 1fr); }
}
.intro-main { min-width: 0; padding: 0 26px; }
.intro .sub {
  font-size: 15px;
  color: var(--grey-500);
  margin: 0;
}
.intro .sub a { color: var(--red); text-decoration: underline; text-underline-offset: 2px; }
.intro .sub a:hover { color: var(--black); }

@media (max-width: 900px) {
  .intro-main { padding: 0; }
}

/* ---------- layout ---------- */
.wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 26px 22px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 30px;
  align-items: start;
}
@media (max-width: 900px) {
  .wrap { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- board ---------- */
.boardcard {
  background: var(--white);
  border: 1px solid var(--grey);
  padding: 26px;
}
/* The label rows and the board share one width and one 8-track grid, with the
   same 2px gap, so the letters line up under the columns and the numbers beside
   the rows by construction. Ranks sit in a fixed 20px column on either side. */
.boardcard { --rankcol: 20px; --gridgap: 2px; }

.coords-file {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--gridgap);
  margin: 6px 0;
}
.coords-file span {
  text-align: center;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--grey-400);
}
.boardrow {
  display: grid;
  grid-template-columns: var(--rankcol) minmax(0, 1fr) var(--rankcol);
  gap: 10px;
  width: min(100%, 460px);
  margin: 0 auto;
}
.boardrow.labels { align-items: center; }
.rankcol { width: var(--rankcol); }
.coords-rank {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  gap: var(--gridgap);
}
.coords-rank span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--grey-400);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--gridgap);
  background: var(--black);
  border: 2px solid var(--black);
  width: 100%;
  aspect-ratio: 1 / 1;
}
.cell {
  position: relative;
  perspective: 340px; /* so a disc turning over reads in 3D */
  background: #d2d2d2;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  padding: 0;
  font: inherit;
}
.cell.playable { cursor: pointer; }
.cell.playable:hover { background: #c4c4c4; }

.disc {
  position: absolute;
  width: 76%;
  height: 76%;
  border-radius: 50%;
}
/* Only brand-new discs animate in; flipped discs must not replay this. */
.disc.place { animation: place 200ms cubic-bezier(0.2, 0.7, 0.3, 1); }
.disc.B { background: radial-gradient(circle at 34% 30%, #414141, #0b0b0b 72%); box-shadow: 0 1px 2px rgba(0,0,0,.35); }
.disc.W {
  background: radial-gradient(circle at 34% 30%, #ffffff, #ededed 82%);
  box-shadow: 0 1px 2px rgba(0,0,0,.28), inset 0 0 0 1.5px #bdbdbd;
}
/* A flip: the disc turns a half turn. The colour is swapped at the midpoint,
   when the disc is edge-on and nearly invisible, so it looks like the reverse
   face coming round rather than a sudden recolour. */
.disc.flipping { animation: flip 440ms cubic-bezier(0.5, 0, 0.5, 1); }

.cell .hint-dot {
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--red);
  opacity: 0.9;
  animation: pop 160ms ease-out;
}
.cell.playable:hover .hint-dot { transform: scale(1.25); }
.cell.last::after {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2.5px var(--red);
  pointer-events: none;
}

@keyframes place {
  from { transform: scale(0.2); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 0.9; }
}
@keyframes flip {
  /* Turn from the reverse face to the front, ending at rest (0deg) so removing
     the class does not snap. Backface stays visible: the colour is swapped when
     the disc is edge-on at the midpoint, so the turn reads as one flip. */
  0% { transform: rotateY(-180deg); }
  100% { transform: rotateY(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .disc, .disc.place, .disc.flipping { animation: none; }
}

/* ---------- board status ---------- */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--grey);
}
.statusbar .turn { font-weight: 500; display: flex; align-items: center; gap: 9px; }
.statusbar .turn .pulse { display: flex; gap: 3px; }
.statusbar .turn .pulse i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--red);
  animation: blink 1s infinite ease-in-out;
}
.statusbar .turn .pulse i:nth-child(2) { animation-delay: 0.15s; }
.statusbar .turn .pulse i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.statusbar .score { font-family: var(--mono); font-size: 12px; letter-spacing: 0.06em; display: flex; align-items: center; gap: 10px; }
.statusbar .score b { font-weight: 600; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; vertical-align: -1px; }
.dot.B { background: #0b0b0b; }
.dot.W { background: #fff; box-shadow: inset 0 0 0 1px #c2c2c2; }

/* ---------- side cards ---------- */
.side { display: flex; flex-direction: column; gap: 24px; }
.card { background: var(--white); border: 1px solid var(--grey); padding: 20px; }
.card h2 {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 400;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--black);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.card h2 .phase { color: var(--red); font-weight: 500; }

.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--grey-500);
  margin-bottom: 7px;
}
.seg { display: flex; border: 1px solid var(--grey); }
.seg button {
  flex: 1;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: transparent;
  color: var(--black);
  border: none;
  padding: 9px 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button + button { border-left: 1px solid var(--grey); }
.seg button:hover { background: var(--lightgrey); }
.seg button.on { background: var(--black); color: var(--lightgrey); }

select {
  width: 100%;
  font-family: var(--sans);
  font-size: 14px;
  padding: 9px 10px;
  border: 1px solid var(--grey);
  background: var(--white);
  color: var(--black);
}

button.primary {
  width: 100%;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--red);
  color: var(--black);
  border: 1px solid var(--red);
  padding: 13px;
  cursor: pointer;
  transition: filter 0.15s;
}
button.primary:hover { filter: brightness(1.06); }
button.primary:disabled { opacity: 0.5; cursor: default; }

.hint { font-size: 12px; color: var(--grey-500); margin: 14px 0 0; line-height: 1.55; }

/* ---------- AI decision panel ---------- */
.ai-body.empty { font-size: 13px; color: var(--grey-400); }
.ai-verdict { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.ai-verdict .sq { font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.ai-verdict .move-by { font-family: var(--mono); font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--grey-500); }
.ai-meta {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--grey-500);
  margin-bottom: 14px;
}
.ai-meta .fallback { color: var(--red); }
.ai-features {
  font-size: 12px;
  color: var(--grey-500);
  background: var(--lightgrey);
  border-left: 2px solid var(--grey);
  padding: 8px 10px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 26px 1fr 42px; align-items: center; gap: 9px; }
.bar-row .lab { font-family: var(--mono); font-size: 10px; color: var(--black); }
.bar-row .track { display: block; height: 12px; background: var(--grey); }
.bar-row .fill { display: block; height: 100%; min-width: 2px; background: var(--black); transition: width 0.4s ease; }
.bar-row.chosen .fill { background: var(--red); }
.bar-row .pct { font-family: var(--mono); font-size: 10px; text-align: right; color: var(--grey-500); }
.bar-row.chosen .pct { color: var(--black); }

/* ---------- footer ---------- */
.foot {
  max-width: 1320px;
  margin: 0 auto;
  padding: 26px 22px 50px;
  border-top: 1px solid var(--grey);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}
.foot .lm { width: 26px; flex: none; }
.foot .lm svg { display: block; width: 100%; height: auto; }
.foot .addr {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--black);
  text-align: right;
  line-height: 1.9;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--black);
  color: var(--lightgrey);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 12px 18px;
  border-left: 3px solid var(--red);
  z-index: 50;
  max-width: 90vw;
}
.toast.err { border-left-color: var(--red); }

/* ---------- badge share page ---------- */
.badge-page .bar a.count {
  color: var(--lightgrey);
  text-decoration: none;
  border-bottom: 1px solid var(--red);
  padding-bottom: 1px;
}
.badge-page .bar a.count:hover { color: var(--red); }
.badge-wrap { max-width: 900px; margin: 0 auto; padding: 40px 22px 60px; }
.badge-headline { font-size: 30px; line-height: 1.1; margin: 0 0 24px; max-width: 22ch; }
.badge-img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--grey);
  background: var(--white);
}
.badge-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 22px 0 28px;
}
@media (min-width: 820px) {
  /* Wide enough for every action on a single row. */
  .badge-actions { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}
.badge-actions .badge-btn { text-align: center; }
.badge-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 44px;
  line-height: 1.25;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--white);
  color: var(--black);
  border: 1px solid var(--black);
  padding: 12px 16px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.badge-btn:hover { background: var(--lightgrey); }
.badge-btn.primary { background: var(--red); border-color: var(--red); color: var(--black); }
.badge-btn.primary:hover { filter: brightness(1.06); }
.badge-card { background: var(--white); border: 1px solid var(--grey); padding: 22px; }
.badge-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--black);
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.badge-row .red { color: var(--red); font-weight: 600; }
.badge-score {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge-score .badge-you { margin-left: auto; color: var(--grey-500); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; }
.badge-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid var(--grey);
}
.badge-foot .badge-wm { width: 90px; height: auto; display: block; }
.badge-foot span { font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--grey-500); }
.badge-miss { color: var(--grey-500); }

/* ---------- share panel (game over) ---------- */
.share { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--grey); }
.share-head { margin-bottom: 12px; }
.share-head .mono { color: var(--red); }
.share-lead { font-size: 14px; color: var(--grey-500); margin: 0 0 14px; }
.share-img { display: block; width: 100%; height: auto; border: 1px solid var(--grey); }
.share-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  margin: 16px 0 4px;
}
.share-actions .badge-btn { text-align: center; }