:root {
    --bg: #0f1117;
    --panel: #181b24;
    --panel-2: #20242f;
    --text: #e6e8ee;
    --muted: #8b90a0;
    --line: #2c313d;
    --p1: #4f9dff;
    --p1-fill: rgba(79,157,255,0.30);
    --p2: #ff6b6b;
    --p2-fill: rgba(255,107,107,0.30);
  }
  * { box-sizing: border-box; }
  html, body {
    margin: 0; height: 100%; overflow: hidden;
    background: var(--bg); color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  }
  /* Space reserved (vertically) for everything around the canvas so the square
     board always fits inside the viewport height. */
  :root { --chrome: 250px; }
  .wrap {
    display: flex; gap: 20px; padding: 16px 20px;
    max-width: 1100px; margin: 0 auto; align-items: flex-start;
    height: 100vh; overflow: auto;
  }
  .view { display: none; }
  .view.active { display: flex; }
  .landing {
    flex-direction: column; gap: 18px;
  }
  .landing-head {
    max-width: 760px; padding-top: 4vh;
  }
  .landing-head h1 { font-size: 34px; margin-bottom: 8px; }
  .landing-head .sub { font-size: 15px; max-width: 680px; }
  .landing-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px; width: 100%;
  }
  .preset-card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 8px; padding: 16px;
  }
  .preset-card h2 { font-size: 15px; margin: 0 0 6px; }
  .preset-card p { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 0 0 14px; }
  .nav-row { display: flex; gap: 10px; margin-bottom: 12px; }
  .nav-row button { width: auto; }
  h1 { font-size: 18px; margin: 0 0 2px; letter-spacing: 0.3px; }
  .sub { color: var(--muted); font-size: 12px; margin: 0 0 12px; line-height: 1.4; }
  .board-col {
    flex: 1 1 auto; min-width: 0; width: 100%;
    display: flex; flex-direction: column; align-items: stretch;
  }
  .side { flex: 0 0 240px; min-width: 220px; }
  .card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 14px; padding: 16px;
  }
  canvas {
    display: block; margin: 0 auto;
    width: auto; height: auto;
    max-width: 100%;
    max-height: calc(100vh - var(--chrome));
    aspect-ratio: 1 / 1;
    border-radius: 12px; border: 2px solid transparent;
    cursor: crosshair; background: transparent;
    touch-action: none;
  }
  .scores { display: flex; gap: 12px; margin-top: 16px; }
  .score {
    flex: 1; background: var(--panel-2); border: 1px solid var(--line);
    border-radius: 12px; padding: 12px 14px; position: relative; overflow: hidden;
  }
  .score.active { box-shadow: inset 0 0 0 2px currentColor; }
  .score .name { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
  .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
  .score .pct { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
  .score .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .p1 { color: var(--p1); }
  .p2 { color: var(--p2); }

  .diff {
    margin-top: 10px; text-align: center; font-size: 13px; font-weight: 600;
    color: var(--muted); min-height: 1.2em;
  }

  label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }
  .row { margin-bottom: 16px; }
  .range-row { display: flex; align-items: center; gap: 12px; }
  input[type=range] { flex: 1; accent-color: var(--p1); }
  .strength-spend-control {
    --min-stop: 0%;
    --max-stop: 100%;
    position: relative; flex: 1; height: 22px;
  }
  .strength-spend-control::before {
    content: ''; position: absolute; left: 0; right: 0; top: 8px; height: 6px;
    border-radius: 999px;
    background: linear-gradient(to right,
      #555b68 0 var(--min-stop),
      var(--p1) var(--min-stop) var(--max-stop),
      #555b68 var(--max-stop) 100%);
  }
  #strengthSpend {
    position: absolute; top: 0; bottom: 0;
    left: calc(var(--min-stop) - 9px);
    width: calc(var(--max-stop) - var(--min-stop) + 18px);
    margin: 0;
    appearance: none; -webkit-appearance: none; background: transparent;
  }
  #strengthSpend::-webkit-slider-runnable-track {
    height: 6px; border-radius: 999px; background: transparent;
  }
  #strengthSpend::-moz-range-track {
    height: 6px; border-radius: 999px; background: transparent;
  }
  #strengthSpend::-webkit-slider-thumb {
    appearance: none; -webkit-appearance: none; width: 18px; height: 18px;
    margin-top: -6px; border: 2px solid #fff; border-radius: 50%;
    background: var(--p1); box-shadow: 0 1px 4px rgba(0,0,0,.45);
  }
  #strengthSpend::-moz-range-thumb {
    width: 14px; height: 14px; border: 2px solid #fff; border-radius: 50%;
    background: var(--p1); box-shadow: 0 1px 4px rgba(0,0,0,.45);
  }
  .strength-limit-tick {
    position: absolute; z-index: 2; top: 3px; width: 2px; height: 16px;
    border-radius: 1px; background: #fff; pointer-events: none;
    transform: translateX(-1px); box-shadow: 0 0 2px rgba(0,0,0,.8);
  }
  .strength-limit-tick.min { left: var(--min-stop); }
  .strength-limit-tick.max { left: var(--max-stop); }
  .checkbox-row {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 0; cursor: pointer;
  }
  .checkbox-row input[type=checkbox] { accent-color: var(--p1); width: 15px; height: 15px; }
  .scan-row { display: none; }
  .scan-row.visible { display: block; }
  .strength-panel { display: none; }
  .strength-panel.visible { display: block; }
  .turn-strength-panel { display: none; margin-bottom: 16px; }
  .turn-strength-panel.visible { display: block; }
  .strength-readout {
    font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.35;
  }
  .modal-backdrop {
    position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
    background: transparent; padding: 18px; border: 0; margin: 0;
    width: 100%; height: 100%; max-width: none; max-height: none; color: var(--text);
  }
  .modal-backdrop[open] { display: flex; }
  .modal-backdrop::backdrop { background: rgba(0,0,0,0.62); }
  :focus-visible { outline: 2px solid var(--p1); outline-offset: 3px; }
  .modal {
    width: min(560px, 100%); max-height: calc(100vh - 36px); overflow: auto;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: 16px;
  }
  .modal-head {
    display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
    margin-bottom: 14px;
  }
  .modal-head h2 { font-size: 18px; margin: 0 0 4px; }
  .modal-head button { width: auto; }
  .setup-section {
    border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px;
  }
  .setup-section:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
  .setup-title {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    margin-bottom: 10px;
  }
  .setup-title h3 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: 0.08em; color: #cbd1dd; }
  .setup-title span { font-size: 12px; color: var(--muted); }
  .setup-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px;
  }
  .preset-options {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px;
  }
  .preset-option {
    text-align: left; min-height: 108px; border-radius: 8px; background: #1d222d;
    display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
  }
  .preset-option strong { font-size: 13px; color: var(--text); }
  .preset-option span { font-size: 12px; color: var(--muted); line-height: 1.35; font-weight: 500; }
  .preset-option.active {
    border-color: var(--p1); box-shadow: inset 0 0 0 1px var(--p1);
    background: rgba(79,157,255,0.12);
  }
  .setup-confirm {
    background: rgba(255,255,255,0.04); border: 1px solid var(--line);
    border-radius: 8px; padding: 12px; font-size: 12px; color: var(--muted);
    line-height: 1.45;
  }
  .setup-confirm strong { color: var(--text); }
  .modal-actions { display: flex; gap: 10px; margin-top: 12px; }
  .count-badge {
    font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px;
    min-width: 28px; text-align: center;
  }
  button {
    width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--panel-2); color: var(--text); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background .12s, border-color .12s;
  }
  button:hover { background: #2a2f3c; border-color: #3a4150; }
  button.primary { background: var(--p1); border-color: var(--p1); color: #08131f; }
  button.primary:hover { background: #6aabff; }
  button.secondary { background: transparent; }
  button:disabled { opacity: 0.45; cursor: not-allowed; }
  button:disabled:hover { background: var(--panel-2); border-color: var(--line); }
  .turn {
    font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--panel-2);
    border: 1px solid var(--line); text-align: center; font-weight: 600; margin-bottom: 16px;
  }
  .winner {
    margin-top: 16px; padding: 14px; border-radius: 12px; text-align: center;
    background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; font-size: 16px;
    display: none;
  }
  .hint { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.5; }
  select {
    width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--panel-2); color: var(--text); font-size: 14px;
  }
  /* Streamlined product shell */
  :root { --chrome: 170px; --panel: #151821; --panel-2: #1c202b; --line: #292f3c; }
  body { background: radial-gradient(circle at 50% -20%, #202838 0, var(--bg) 42%); }
  .landing { justify-content: safe center; max-width: 880px; }
  .landing-head { padding: 0; text-align: center; margin: 0 auto; }
  .brand-mark { display:block; width:64px; height:64px; margin:0 auto 18px; }
  .landing-head h1 { font-size: clamp(2.5rem, 9vw, 5rem); letter-spacing:-.065em; line-height:.92; margin:0; }
  .landing-head .sub { margin:16px auto 0; max-width:440px; font-size:14px; }
  .mode-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:12px; width:100%; max-width:720px; margin:30px auto 0; }
  .mode-button { min-height:132px; padding:22px; text-align:left; display:flex; flex-direction:column; justify-content:space-between; border-radius:20px; }
  .mode-button .symbol { font-size:24px; font-weight:400; }
  .mode-button strong { font-size:15px; }
  .join-box { display:none; gap:9px; grid-template-columns:1fr auto; width:min(430px,100%); margin:14px auto 0; padding:10px; border:1px solid var(--line); border-radius:16px; background:var(--panel); }
  .join-box.visible { display:grid; }
  .join-box input { min-width:0; border:0; background:transparent; color:var(--text); font-size:20px; font-weight:800; letter-spacing:.24em; text-transform:uppercase; outline:0; padding:8px 10px; }
  .join-box button { width:auto; }
  .join-error { min-height:1.3em; margin:8px 0 0; color:var(--p2); font-size:12px; text-align:center; }
  .online-choice { display:none; grid-template-columns:1fr 1.4fr; gap:9px; width:min(560px,100%); margin:14px auto 0; }
  .online-choice.visible { display:grid; }
  .online-choice > button { width:auto; }
  .online-choice .join-box { display:grid; width:100%; margin:0; padding:7px; }
  .quiet-link { width:auto; margin:14px auto 0; border:0; background:transparent; color:var(--muted); font-size:12px; }
  .game-topbar { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:10px; }
  #copyRoom { visibility:hidden; }
  .icon-row { display:flex; gap:7px; }
  .icon-button { display:grid; place-items:center; width:40px; height:40px; padding:0; border-radius:12px; font-size:18px; }
  .exit-button { color:var(--p2); border-color:rgba(255,107,107,.42); background:rgba(255,107,107,.08); }
  .exit-button:hover { color:#fff; border-color:var(--p2); background:var(--p2); }
  .exit-button svg { width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:2; stroke-linecap:round; stroke-linejoin:round; }
  .room-bar { display:none; align-items:center; justify-content:space-between; gap:12px; margin-bottom:10px; padding:9px 12px; border:1px solid var(--line); border-radius:13px; background:var(--panel); }
  .room-bar.visible { display:flex; }
  .room-code { font-weight:850; letter-spacing:.18em; }
  .room-status { color:var(--muted); font-size:12px; }
  .gameView-title { display:none; }
  .board-col > .card { padding:10px; }
  .side .card { display:grid; gap:9px; padding:10px; }
  .side .row { margin:0 !important; }
  .side .hint, #gameView .solved { display:none; }
  .turn { margin-bottom:9px; border:0; background:transparent; }
  .scores { margin-top:10px; gap:8px; }
  .score { padding:9px 11px; border-radius:10px; }
  .score .pct { font-size:21px; }
  .score .meta { font-size:10px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  @media (max-width: 720px) {
    .mode-grid { grid-template-columns:1fr; max-width:430px; }
    .mode-button { min-height:78px; flex-direction:row; align-items:center; }
    .online-choice { grid-template-columns:1fr; max-width:430px; }
    .wrap { padding:12px; gap:10px; }
    #gameView.active { flex-direction:column; }
    #gameView .side { width:100%; flex:0 0 auto; }
    #gameView .side .card { grid-template-columns:1fr 1fr; }
    canvas { max-height:calc(100vh - 290px); }
  }

  [hidden] { display:none !important; }
  .board-col:has(.scores.multiplayer) { --chrome:340px; }
  .scores.multiplayer { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); }
  .scores.multiplayer .score { min-width:0; }
  .room-status { text-align:right; }
  @media (max-width:720px) {
    .scores.multiplayer { grid-template-columns:repeat(2,minmax(0,1fr)); }
    .board-col:has(.scores.multiplayer) canvas { max-height:calc(100vh - 420px); min-height:160px; }
  }
