:root {
  /* company brand */
  --red: #e32553;
  --yellow: #fac31c;
  --blue: #119dae;

  /* pale tints for the pastel theme */
  --red-pale: #fdeaef;
  --yellow-pale: #fef6dc;
  --blue-pale: #e4f4f6;

  --bg: #fbfbf9;
  --panel: #ffffff;
  --ink: #26303a;
  --muted: #7a8791;
  --line: #e6ebee;

  /* chess board: blue + orange squares, red arrows */
  --sq-light: #cfe9ec;   /* pale tint of company blue */
  --sq-dark: #f6c948;    /* company orange, lightly muted */
  --glyph: #20262b;      /* dark, legible on both squares */
  --arrow: #e32553;      /* company red */

  --accent: var(--blue);
  --bad: var(--red);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

code { background: var(--blue-pale); padding: 1px 5px; border-radius: 4px; font-size: 90%; }
h1, h2, h3 { line-height: 1.2; }
a { color: var(--blue); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 3px solid var(--blue);
  box-shadow: 0 1px 6px rgba(0,0,0,.05);
}
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; text-decoration: none; color: var(--ink); font-size: 20px; }
.brand .logo { display: inline-flex; }
.brand-text { margin: 0; font-size: inherit; font-weight: 700; display: inline-flex; align-items: baseline; gap: 8px; }
.brand-name { color: var(--ink); }
.brand-sep { color: #cdd6db; font-weight: 300; }
.brand-sub { color: var(--muted); font-weight: 400; }
.mark { display: block; width: 28px; height: auto; }
.brand .mark { width: 30px; }
.auth-brand .mark { width: 30px; }

.auth { display: flex; align-items: center; gap: 10px; }
.auth .who { font-weight: 600; }
.auth .who .u { color: var(--blue); }

/* ---------- buttons ---------- */
button, select {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); font: inherit; cursor: pointer; color: var(--ink);
}
button:hover, select:hover { border-color: var(--muted); }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.07); }
button.primary:disabled { background: #cdd5da; border-color: #cdd5da; cursor: not-allowed; filter: none; }
button.ghost { background: transparent; }
input[type=number], input[type=text], input[type=email], input[type=password], input[type=tel] {
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--ink);
}
input[type=number] { width: 60px; }

/* ---------- layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 24px; }
section { margin-bottom: 34px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 12px; }

/* ---------- views / router ---------- */
.view { display: none; }
.view.active { display: block; }
.view-auth.active { display: flex; }
body[data-view="auth"] .topbar { display: none; }

/* editorial serif for headlines (Anthropic-ish warmth; system fonts, no webfont) */
.hero-title, .strip-title, .ch-head h1, .auth-box h2, .nf-code, .nf h2, #about h2 {
  font-family: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  font-weight: 600; letter-spacing: -0.01em;
}

/* ---------- home / landing ---------- */
.view-home { max-width: 1080px; margin: 0 auto; padding: 8px 24px; }
.hero { padding: 72px 6px 44px; max-width: 760px; }
.hero-title { font-size: clamp(38px, 6vw, 64px); line-height: 1.05; margin: 0 0 22px; }
.hero-lead { font-size: 19px; line-height: 1.6; color: #4a555f; max-width: 560px; margin: 0 0 30px; }
/* the three core-value words look/feel like links but go nowhere */
.value-link { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.value-link:hover { color: #0c6f7b; }
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }
.btn-lg { padding: 13px 24px; font-size: 16px; border-radius: 10px; font-weight: 600; }
.home-challenges { padding: 34px 6px 80px; border-top: 1px solid var(--line); }
.strip-title { font-size: 24px; margin: 0 0 20px; }
.strip-note { color: var(--muted); font-size: 14px; margin-top: 18px; }

/* ---------- challenge cards ---------- */
.challenge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.challenge-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 22px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.challenge-card[data-nav] { cursor: pointer; }
.challenge-card[data-nav]:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(31,36,43,.14); border-color: #d4dbe0; }
.challenge-card .ch-card-top { display: flex; align-items: center; justify-content: space-between; min-height: 26px; margin-bottom: 14px; }
.challenge-card .ch-mark { width: 26px; }
.challenge-card .ch-glyph { font-size: 30px; line-height: 1; color: var(--ink); }
.challenge-card h3 { font-size: 19px; margin: 0 0 8px; }
.challenge-card p { color: #56616b; font-size: 14.5px; line-height: 1.55; margin: 0 0 16px; }
.challenge-card .ch-cta { font-weight: 700; color: var(--blue); font-size: 14px; }
.challenge-card.soon { opacity: .65; }
.ch-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; }

/* ---------- challenges view ---------- */
.view-challenges { max-width: 1080px; margin: 0 auto; padding: 40px 24px 80px; }
.ch-head { margin-bottom: 26px; }
.ch-head h1 { font-size: 40px; margin: 0 0 6px; }
.ch-head .sub { color: var(--muted); font-size: 16px; margin: 0; }

/* ---------- chess view wrapper ---------- */
.view-chess .back-link { display: inline-block; margin: 18px 0 -10px 24px; color: var(--blue); text-decoration: none; font-weight: 600; font-size: 14px; }
.view-chess .back-link:hover { text-decoration: underline; }

/* ---------- auth (sokraites-style split) ---------- */
.view-auth { min-height: 100vh; align-items: stretch; }
.auth-panel { flex: 1 1 46%; display: flex; align-items: center; justify-content: center; padding: 40px 28px; background: var(--bg); }
.auth-form-wrap { width: 100%; max-width: 380px; }
.auth-brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 18px; margin-bottom: 34px; }
.auth-box { display: none; }
.view-auth[data-mode="login"] .auth-box[data-box="login"] { display: block; }
.view-auth[data-mode="register"] .auth-box[data-box="register"] { display: block; }
.auth-box h2 { font-size: 28px; margin: 0 0 6px; }
.auth-box .sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.auth-box form { display: flex; flex-direction: column; gap: 13px; }
.auth-box label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.auth-box input { width: 100%; }
.auth-box .rules-box { background: var(--yellow-pale); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: #7a6410; }
.auth-box .err { color: var(--red); font-size: 13px; min-height: 18px; }
/* register: phone prefix + digits-only box, and the student/employed toggle */
.tel-row { display: flex; gap: 8px; flex-wrap: wrap; }   /* wraps once the custom-code box shows */
.tel-prefix { flex: 0 0 auto; max-width: 165px; }
/* basis 120px, not auto: `.auth-box input { width: 100% }` would otherwise make the
   number box wide enough to wrap the row onto two lines as soon as a third box appears */
.tel-row input { flex: 1 1 120px; min-width: 0; }
.tel-row input.tel-custom { flex: 0 0 74px; }   /* needs `.tel-row input` specificity to win */

/* country-code listbox: a <details> styled to pass for the <select> it replaces */
.dial { position: relative; flex: 0 0 auto; }
.dial > summary {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; gap: 8px; list-style: none;
}
.dial > summary::-webkit-details-marker { display: none; }   /* Safari's triangle */
.dial > summary::after { content: '⌄'; margin-left: auto; color: var(--muted); line-height: 0; }
.dial > summary:hover { border-color: var(--muted); }
.dial-panel {
  position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; width: 232px;
  max-height: 264px; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(38, 48, 58, .14);
}
.dial-panel button {
  display: block; width: 100%; text-align: left; padding: 7px 10px;
  border: 0; border-radius: 0; background: none; font-size: 14px;
}
.dial-panel button:hover, .dial-panel button:focus { background: var(--blue-pale); outline: none; }
.dial-panel button[aria-selected="true"] { font-weight: 600; }
/* the point of the whole widget: stays on screen for all 245 countries below it */
.dial-panel .dial-custom {
  position: sticky; top: 0; background: var(--panel);
  border-bottom: 1px solid var(--line); font-weight: 600; color: var(--blue);
}
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.req { color: var(--red); margin-left: 2px; }   /* required-field asterisk */
.req-note { font-size: 12px; color: var(--muted); margin: -4px 0 0; }   /* the asterisk's key */
.radio-row { display: flex; gap: 20px; flex-wrap: wrap; }   /* "Prefer not to say" wraps on phones */
.auth-box label.radio { flex-direction: row; align-items: center; gap: 7px; font-size: 14px; color: var(--ink); }
.auth-box label.radio input { width: auto; }
.auth-box label.occ-field { display: none; }   /* beats `.auth-box label { display:flex }` */
#registerForm[data-occ="student"] .occ-field[data-for="student"] { display: flex; }
#registerForm[data-occ="employed"] .occ-field[data-for="employed"] { display: flex; }
button.block { width: 100%; padding: 11px; font-size: 15px; margin-top: 4px; }
.auth-switch { font-size: 14px; color: var(--muted); margin-top: 18px; }
.auth-switch a { color: var(--blue); font-weight: 600; cursor: pointer; }

.auth-art { flex: 1 1 54%; position: relative; overflow: hidden; background: linear-gradient(160deg, #eef4f4, #f7eef0); }
.tess, .tess-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tess-svg { opacity: .5; }
/* Blocks spin in place; JS (startSpinning) triggers each rotation on a Poisson timer. */
.cube { transform-box: fill-box; transform-origin: center; transition: transform 4s ease-in-out; }
@media (prefers-reduced-motion: reduce) { .cube { transition: none; } }

/* ---------- 404 ---------- */
.view-404 { max-width: 640px; margin: 0 auto; padding: 90px 24px; text-align: center; }
.nf-code { font-size: 90px; line-height: 1; color: var(--blue); margin-bottom: 6px; }
.nf h2 { font-size: 28px; margin: 0 0 8px; }
.nf p { color: var(--muted); margin: 0 0 22px; }

/* ---------- about / problem description ---------- */
#about h2 { margin-top: 0; font-size: 22px; }
.rules { margin: 8px 0 14px; padding-left: 20px; }
.rules li { margin: 3px 0; }
.about-grid { display: flex; flex-wrap: wrap; gap: 24px; }
.about-grid > div { flex: 1 1 320px; }
table.pieces { border-collapse: collapse; width: 100%; font-size: 14px; }
table.pieces th, table.pieces td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.pieces th { color: var(--muted); font-weight: 600; }
table.pieces .glyph { font-size: 20px; }
.scoring { background: var(--blue-pale); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.scoring ul { margin: 6px 0 0; padding-left: 18px; }
.pill {
  display: inline-block; font-weight: 700; color: #fff; background: var(--blue);
  border-radius: 999px; padding: 1px 9px; font-size: 12px; margin: 0 2px;
}
.warn-note { color: var(--red); font-weight: 600; }
.dl-btn {
  display: inline-block; margin-top: 14px; padding: 8px 14px; font-size: 14px; font-weight: 600;
  color: var(--blue); background: var(--blue-pale); border: 1px solid var(--blue);
  border-radius: 8px; text-decoration: none;
}
.dl-btn:hover { filter: brightness(1.04); }

/* ---------- builder ---------- */
.builder-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.builder-tools label { color: var(--muted); font-size: 13px; }
.layout { display: flex; flex-wrap: wrap; gap: 22px; align-items: flex-start; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; width: 300px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }

/* board */
#board { display: grid; width: fit-content; border: 2px solid var(--sq-dark); border-radius: 4px; overflow: hidden; user-select: none; }
.cell {
  position: relative;
  width: var(--cell, 52px); height: var(--cell, 52px);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell, 52px) * .69);
  cursor: pointer; line-height: 1; touch-action: none; color: var(--glyph);
}
.cell .val {
  position: absolute; right: 2px; bottom: 1px;
  font-size: max(9px, calc(var(--cell, 52px) * .21));
  font-weight: 700; line-height: 1; color: var(--ink);
  text-shadow: 0 1px 2px rgba(255,255,255,.85);
  pointer-events: none;
}
.cell.light { background: var(--sq-light); }
.cell.dark { background: var(--sq-dark); }
.cell:hover { box-shadow: inset 0 0 0 3px rgba(17,157,174,.65); }
.cell.drop { box-shadow: inset 0 0 0 4px var(--blue); }
.cell.dragsrc { color: rgba(32,38,43,.28); }
.drag-ghost { position: fixed; transform: translate(-50%,-50%); font-size: 36px; line-height: 1; pointer-events: none; opacity: .85; z-index: 60; color: var(--glyph); }
#boardwrap { position: relative; width: fit-content; }
#arrows { position: absolute; top: 2px; left: 2px; pointer-events: none; }

/* palette */
.palette { display: flex; gap: 6px; margin-bottom: 14px; }
.palette button { font-size: 26px; width: 44px; height: 44px; padding: 0; line-height: 1; border-radius: 8px; }
.palette button.sel { background: var(--blue); color: #fff; border-color: var(--blue); }

/* boards sidebar */
#sidebar { width: fit-content; max-width: 100%; padding: 12px 14px; }
.sidebar-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sidebar-head h3 { margin: 0; }
.sidebar-actions { display: flex; gap: 8px; width: 100%; }
.sidebar-actions label, .sidebar-actions button {
  flex: 1; text-align: center; font-size: 14px; font-weight: 600; padding: 8px 10px;
  border: 1px solid var(--blue); border-radius: 8px; background: var(--blue); cursor: pointer; color: #fff;
}
.sidebar-actions label:hover, .sidebar-actions button:hover { filter: brightness(1.08); }
#loadBoards { display: none; }
.total-score { font-size: 13px; color: var(--muted); margin: 6px 0 6px; }
.total-score b { color: var(--ink); font-size: 16px; }
.dup-warning {
  display: none; background: var(--red-pale); color: var(--red); border: 1px solid var(--red);
  border-radius: 8px; padding: 7px 9px; font-size: 12px; font-weight: 600; margin-bottom: 8px;
}
.dup-warning.show { display: block; }
/* board size map (dashboard-style matrix) */
.matrix-wrap { overflow-x: auto; }
.matrix {
  --tile: 22px;
  display: grid; grid-template-columns: 20px repeat(18, var(--tile)); /* sizes 3..20 */
  grid-auto-rows: var(--tile); gap: 3px; width: max-content; margin-top: 8px;
}
.matrix .axis { display: grid; place-items: center; color: var(--muted); font-size: 9px; font-weight: 700; }
.matrix .axis.corner { font-size: 8px; }
.size-cell {
  display: grid; place-items: center; padding: 0;
  border: 1px solid rgba(38,48,58,.14); border-radius: 5px; background: #eef1f4;
  font-size: 8px; font-weight: 700; line-height: 1; color: rgba(24,30,37,.85);
  font-variant-numeric: tabular-nums; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.size-cell:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(31,36,43,.22); }
.size-cell.selected { border-color: #111827; box-shadow: 0 0 0 2px #111827; z-index: 2; }
.size-cell.invalid { color: var(--red); font-size: 10px; background: var(--red-pale); }

/* status + score panel */
.pvals { display: flex; flex-direction: column; gap: 4px; }
.pvals .pv { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.pvals .pv .g { font-size: 20px; width: 22px; text-align: center; }
.pvals .pv .n { color: var(--muted); flex: 1; }
.pvals .pv .v { font-weight: 700; }
.status { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; color: #fff; min-width: 34px; text-align: center; }
.badge.ok { background: var(--blue); }
.badge.no { background: var(--red); }
#score { font-size: 26px; font-weight: 700; margin-top: 4px; }
#scoreDetail { color: var(--muted); font-size: 13px; }

/* ---------- submit ---------- */
.submit-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }
#submitResult { margin-top: 12px; font-size: 14px; }
#submitResult.ok { color: var(--ink); }
#submitResult.err { color: var(--red); }
#submitResult .big { font-size: 20px; font-weight: 700; color: var(--blue); }

/* ---------- leaderboard ---------- */
.lb-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
table.lb { border-collapse: collapse; width: 100%; margin-top: 12px; font-variant-numeric: tabular-nums; }
table.lb th, table.lb td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.lb th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
table.lb tr:hover td { background: var(--blue-pale); }
table.lb .rank { font-weight: 700; color: var(--blue); }
table.lb tr.composite td { background: var(--yellow-pale); font-weight: 700; }
table.lb tr.composite:hover td { background: var(--yellow-pale); }
table.lb tr.composite .rank { color: var(--yellow); }
table.lb td.num, table.lb th.num { text-align: right; }
.lb-empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

/* ---------- phones / narrow screens ---------- */
@media (max-width: 720px) {
  main { padding: 14px; }
  section { margin-bottom: 24px; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px 12px; }
  .card { padding: 15px 16px; }
  #about h2 { font-size: 20px; }
  .about-grid { gap: 16px; }

  /* stack the builder; panels and the board column go full width */
  .layout { gap: 16px; }
  .panel, #sidebar { width: 100%; }

  /* lead with the board + its status, push the size map to the bottom */
  .layout > div:not(.panel) { order: 1; }   /* board column */
  .layout > .panel:last-child { order: 2; }  /* status / score panel */
  #sidebar { order: 3; }

  /* large boards scroll horizontally instead of overflowing the page */
  #boardwrap { max-width: 100%; overflow-x: auto; overflow-y: hidden; }

  /* let wide tables scroll rather than break the layout */
  #leaderboardWrap { overflow-x: auto; }
  table.lb { min-width: 480px; }

  /* new views: tighter padding, stacked auth split with the art as a top banner */
  .view-home, .view-challenges { padding: 8px 16px; }
  .hero { padding: 40px 4px 30px; }
  .home-challenges { padding: 28px 4px 48px; }
  .view-challenges { padding-bottom: 48px; }
  .ch-head h1 { font-size: 30px; }
  .view-auth { flex-direction: column; }
  .auth-art { order: -1; flex: 0 0 150px; }
  .auth-panel { flex: 1 1 auto; padding: 30px 20px 48px; }
}
