/* Dots and Boxes — "the pad on the desk": a sheet of cream graph paper, a little askew, on a deep
   ink-navy desk. Round ink dots; lines are fountain-pen strokes in tangerine (seat a) and cobalt
   (seat b). A closed box gets its owner's initial in a handwritten hand and a light wash, so the
   two never rely on colour alone. Layout and button basics come from cb-arcade.css. */
/* the dialog lives in the top layer, outside .db-page, so it gets the same tokens */
.db-page, .db-dlg {
  --ink: #e9ecf5; --ink-hi: #fff8ea; --ink-2: #aab3cc; --ink-3: #7d87a3;
  --desk-1: #2b3550; --desk-2: #1a2135; --desk-3: #10152a;
  --paper: #f8f1df; --paper-hi: #fffdf6; --grid: rgba(70, 120, 200, .13); --rule: rgba(220, 90, 90, .35); --pencil: #6a7286;
  --ta: #e8711a; --ta-hi: #ffb46a; --ta-dk: #9a4507; --ta-wash: rgba(232, 113, 26, .18);
  --co: #3d6fe6; --co-hi: #a9c3ff; --co-dk: #1c3fa8; --co-wash: rgba(61, 111, 230, .2);
  --dot: #1c1f28;
  --hand: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
}
.db-page [hidden], .db-dlg [hidden] { display: none !important; }

/* ---------- who to play ---------- */
.db-tabs { display: flex; gap: 4px; margin: 0 0 10px; padding: 4px; border-radius: 15px;
  background: linear-gradient(180deg, var(--desk-1), var(--desk-2)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 6px 16px -8px rgba(16, 21, 42, .6); }
.db-tabs button { flex: 1; border: 0; background: transparent; padding: 10px 4px; border-radius: 11px; font: 900 14px var(--cbx-body); color: var(--ink-2); cursor: pointer; min-height: 44px; transition: color .2s; }
.db-tabs button:hover { color: var(--ink-hi); }
.db-tabs button[aria-selected="true"] { color: #2b1503; background: linear-gradient(180deg, var(--ta-hi), var(--ta)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 2px 0 var(--ta-dk); }

/* ---------- the desk ---------- */
.cbx-card.db-card { --cbx-full-pad: 12px; padding: 14px 14px 16px; color: var(--ink); overflow: visible; isolation: isolate;
  background: radial-gradient(100% 50% at 50% 0%, var(--desk-1), var(--desk-2) 60%, var(--desk-3));
  border: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 34px 70px -28px rgba(16, 21, 42, .8), 0 10px 24px -12px rgba(16, 21, 42, .5); }
.cbx-card.db-card p { color: inherit; }
.db-card .cb-rv-slot { color: initial; margin-top: 8px; }

/* ---------- player chips: name, an ink-stroke swatch, the box count ---------- */
.db-players { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 12px; min-height: 40px; }
.db-players .vs { font: italic 800 15px 'Fraunces', Georgia, serif; color: var(--ink-3); }
.db-chip { display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: 46%; padding: 6px 14px 6px 8px; border-radius: 999px; font: 900 14px var(--cbx-body); color: var(--ink-2);
  border: 1px solid rgba(255, 255, 255, .12); background: rgba(255, 255, 255, .05); transition: border-color .3s, box-shadow .3s, color .3s, background .3s; }
.db-chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-chip .sc { flex: none; font-weight: 900; }
.db-chip.turn { color: var(--ink-hi); }
.db-chip.turn.a { border-color: rgba(244, 136, 42, .85); background: rgba(244, 136, 42, .14); box-shadow: 0 8px 22px -8px rgba(244, 136, 42, .7); }
.db-chip.turn.b { border-color: rgba(100, 140, 245, .85); background: rgba(61, 111, 230, .16); box-shadow: 0 8px 22px -8px rgba(61, 111, 230, .75); }
.db-chip.won { color: var(--ink-hi); border-color: rgba(255, 210, 94, .8); background: rgba(255, 210, 94, .14); }
/* the short ink stroke: chips and dialog choices */
.ink { display: inline-block; flex: none; width: 18px; height: 4px; border-radius: 2px; background: var(--ta); }
.ink.b { background: var(--co); }
.ink.r { background: linear-gradient(90deg, var(--ta) 0 50%, var(--co) 50%); }

/* ---------- the pad ---------- */
.db-paper { position: relative; width: min(100%, 440px); margin: 0 auto 16px; padding: 34px 8px 8px; border-radius: 6px; transform: rotate(-1.2deg);
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 15px 15px; background-position: 10px 10px;
  box-shadow: 0 1px 0 var(--paper-hi) inset, 0 30px 50px -22px rgba(0, 0, 0, .8), 0 6px 14px -6px rgba(0, 0, 0, .6);
  animation: db-settle .7s cubic-bezier(.2, .9, .25, 1) backwards; }
@keyframes db-settle { from { transform: rotate(-4deg) translateY(18px); opacity: 0; } }
.db-pad, .cbx-card.db-card .db-pad { position: absolute; left: 0; right: 0; top: 0; height: 28px; margin: 0; padding: 0 12px; display: flex; align-items: center;
  border-bottom: 2px solid var(--rule); font: 700 19px/1 var(--hand); color: var(--pencil); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.db-board { position: relative; outline: none; border-radius: 4px; user-select: none; -webkit-user-select: none; touch-action: manipulation; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.db-board:focus-visible { box-shadow: 0 0 0 3px rgba(232, 113, 26, .55); }
.db-board.locked, .db-board.over { cursor: default; }
.db-board svg { display: block; width: 100%; height: auto; aspect-ratio: 1; overflow: visible; }

.db-dot { fill: url(#dbDot); filter: drop-shadow(0 1px .6px rgba(0, 0, 0, .35)); }
.db-line { fill: none; stroke-width: 5.2; stroke-linecap: round; stroke: var(--ta); }
.db-line.b { stroke: var(--co); }
.db-line.glow.a { filter: url(#dbGlowA); stroke-width: 5.8; }
.db-line.glow.b { filter: url(#dbGlowB); stroke-width: 5.8; }
/* a quick pen stroke from one dot to the next */
.db-line.draw { stroke-dasharray: 1 1; stroke-dashoffset: 1; animation: db-pen .24s cubic-bezier(.4, .1, .3, 1) forwards; }
@keyframes db-pen { to { stroke-dashoffset: 0; } }
.db-ghost { fill: none; stroke-width: 5; stroke-linecap: butt; stroke: rgba(232, 113, 26, .6); stroke-dasharray: 7 5; pointer-events: none; }
.db-ghost.b { stroke: rgba(61, 111, 230, .6); }
.db-ghost.kb { stroke-width: 6; }
.db-box rect { fill: var(--ta-wash); }
.db-box.b rect { fill: var(--co-wash); }
.db-box text { font: 700 38px var(--hand); fill: var(--ta); }
.db-box text.two { font-size: 28px; }
.db-box.b text { fill: var(--co); }
.db-box.pop { transform-box: fill-box; transform-origin: center; animation: db-pop .38s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes db-pop { from { transform: scale(.4); opacity: 0; } }

/* invalid tap: the pad nudges */
.db-paper.flash { animation: db-shake .4s; }
@keyframes db-shake { 20% { transform: rotate(-1.2deg) translateX(-5px); } 40% { transform: rotate(-1.2deg) translateX(5px); } 60% { transform: rotate(-1.2deg) translateX(-3px); } 80% { transform: rotate(-1.2deg) translateX(2px); } }
/* load-in: the dots ink in, corner to corner */
.db-paper.intro .db-dot { animation: db-dot .4s ease-out backwards; animation-delay: calc(var(--i) * 35ms + .2s); transform-box: fill-box; transform-origin: center; }
@keyframes db-dot { from { transform: scale(0); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .db-paper, .db-paper.intro .db-dot, .db-line.draw, .db-box.pop, .db-paper.flash, .db-send .cbx-btn { animation: none; }
  .db-line.draw { stroke-dasharray: none; stroke-dashoffset: 0; }
}

/* ---------- what's happening ---------- */
.db-note { margin: 0 0 12px; padding: 10px 14px; border-radius: 14px; font: 800 14px/1.45 var(--cbx-body); color: var(--ink-hi);
  background: linear-gradient(135deg, rgba(244, 136, 42, .22), rgba(244, 136, 42, .06)); border: 1px solid rgba(244, 136, 42, .4); }
.db-banner, .cbx-card.db-card .db-banner { margin: 0 0 4px; font: 800 14px/1.45 var(--cbx-body); color: var(--ink-hi); }
.db-banner b { color: #ffd7b0; }
.db-banner .ink-a, .db-note .ink-a { color: #ffbf7f; }
.db-banner .ink-b, .db-note .ink-b { color: var(--co-hi); }
.db-status, .cbx-card.db-card .db-status { margin: 0; min-height: 21px; font: 900 15px/1.4 var(--cbx-body); color: var(--ink-hi); }
.cbx-card.db-card .db-status.a { color: #ffc690; } .cbx-card.db-card .db-status.b { color: var(--co-hi); }
.cbx-card.db-card .db-status.good { color: #ffd25e; } .cbx-card.db-card .db-status.bad { color: #ffb3a8; }
.cbx-card.db-card .db-status.good.a { color: #ffc690; } .cbx-card.db-card .db-status.good.b { color: var(--co-hi); }
.db-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; }

/* ---------- buttons ---------- */
.db-card .cbx-btn { border-radius: 14px; font-weight: 900; }
.db-card .cbx-btn.alt { background: rgba(255, 255, 255, .08); color: var(--ink-2); border: 1px solid rgba(255, 255, 255, .1); box-shadow: none; font-weight: 800; }
.db-card .cbx-btn:not(.alt) { background: linear-gradient(180deg, var(--ta-hi), var(--ta)); color: #2b1503; border: 0; box-shadow: 0 3px 0 var(--ta-dk); }
.db-card .cbx-btn:active:not(:disabled) { transform: translateY(2px); }
.db-card .cbx-btn:not(.alt):active:not(:disabled) { box-shadow: 0 1px 0 var(--ta-dk); }
.db-card .cbx-btn:disabled { opacity: .45; }
.db-send { display: flex; gap: 10px; margin: 0 0 4px; }
.db-send .cbx-btn { min-height: 50px; padding: 10px 14px; font-size: 16px; }
.db-send #undoLine { flex: 1; }
.db-send #sendGo { flex: 2; min-width: 0; }
.db-send #sendGo:not(:disabled) { animation: db-sendglow 2.4s ease-in-out infinite; }
@keyframes db-sendglow { 50% { box-shadow: 0 3px 0 var(--ta-dk), 0 0 26px rgba(255, 180, 106, .55); } }
.db-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.db-actions:not(:has(button:not([hidden]))) { display: none; }
.db-actions .cbx-btn { min-height: 46px; padding: 10px 18px; font-size: 16px; }

.db-opts { display: grid; gap: 8px; justify-items: center; margin-top: 10px; }
.db-pills { display: flex; gap: 4px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 4px; border-radius: 999px;
  background: rgba(0, 0, 0, .25); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .35), 0 1px 0 rgba(255, 255, 255, .06); }
.db-pills span { padding: 0 6px 0 10px; font: 900 13px var(--cbx-body); color: var(--ink-3); }
.db-pills button { border: 0; min-height: 40px; padding: 8px 16px; border-radius: 999px; background: transparent; font: 900 14px var(--cbx-body); color: var(--ink-2); cursor: pointer; }
.db-pills button:hover { color: var(--ink-hi); }
.db-pills button[aria-pressed="true"] { color: #2b1503; background: linear-gradient(180deg, var(--ta-hi), var(--ta)); box-shadow: 0 2px 0 var(--ta-dk); }
.db-stats, .cbx-card.db-card .db-stats { margin: 10px 0 0; text-align: center; font: 800 14px var(--cbx-body); color: var(--ink-3); }
.db-stats b { color: #ffc690; }

/* ---------- the result: a cream sheet under the pad ---------- */
.db-result { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 0 0 14px; padding: 22px 20px 16px; border-radius: 28px; text-align: center;
  background: #fffaf0; color: #1d1f24; box-shadow: 0 -10px 50px rgba(0, 0, 0, .35); animation: db-up .45s cubic-bezier(.2, 1.2, .35, 1) both; }
@keyframes db-up { from { transform: translateY(24px); opacity: 0; } }
.cbx-card.db-card .db-r-kick { margin: 0; font: 700 24px/1.1 var(--hand); color: var(--co); transform: rotate(-2deg); }
.cbx-card.db-card .db-r-kick.a { color: var(--ta); }
.db-card .db-r-head { margin: 0; font: 900 30px/1.1 'Fraunces', Georgia, serif; color: #1d1f24; }
.db-r-bar { display: flex; width: 100%; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; }
.db-r-bar i { display: block; min-width: 3px; transition: flex .6s ease; }
.db-r-bar .a { background: var(--ta); } .db-r-bar .b { background: var(--co); }
.db-r-legend { display: flex; justify-content: space-between; gap: 8px; width: 100%; font: 800 14px var(--cbx-body); }
.db-r-legend .a { color: var(--ta-dk); } .db-r-legend .b { color: var(--co-dk); text-align: right; }
.cbx-card.db-card .db-r-tip { margin: 0; font: 800 13px/1.45 var(--cbx-body); color: #4a4d55; }
.db-r-btns { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.db-r-go, .db-r-alt { min-height: 52px; border: 0; border-radius: 14px; cursor: pointer; font: 900 17px var(--cbx-body); background: #1d1f24; color: #fffaf0; }
.db-r-alt { min-height: 48px; background: #ebe5d8; color: #1d1f24; font-weight: 800; font-size: 16px; }
.db-r-go:active, .db-r-alt:active { transform: translateY(2px); }
.cbx .db-r-more { min-height: 40px; display: flex; align-items: center; justify-content: center; font: 700 15px var(--cbx-body); color: #4a4d55; }
@media (prefers-reduced-motion: reduce) { .db-result { animation: none; } }

/* ---------- the friend dialog: a sheet of the same paper ---------- */
.db-dlg { border: 0; padding: 0; border-radius: 22px; width: min(420px, calc(100vw - 32px)); color: #26303f;
  background-color: #fffaf0; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); }
.db-dlg::backdrop { background: rgba(16, 21, 42, .62); backdrop-filter: blur(3px); }
.db-dlg-card { padding: 20px; }
.db-dlg h2 { margin: 0 0 6px; font: 900 22px 'Fraunces', Georgia, serif; color: #1d1f24; }
.db-dlg p { margin: 0 0 12px; font: 800 15px/1.45 'Nunito', system-ui, sans-serif; color: #5d6474; }
.db-field { display: grid; gap: 4px; margin: 0 0 10px; font: 900 13px 'Nunito', system-ui, sans-serif; color: #3a4252; }
.db-field input { font: 800 17px 'Nunito', system-ui, sans-serif; padding: 11px 12px; border: 2px solid #e2dccd; border-radius: 12px; background: #fff; color: #1d1f24; }
.db-field input:focus { outline: none; border-color: var(--ta); box-shadow: 0 0 0 3px rgba(232, 113, 26, .25); }
.db-choice { display: flex; gap: 8px; margin: 4px 0 10px; }
.db-choice label { flex: 1; display: grid; place-items: center; gap: 8px; padding: 12px 6px; border-radius: 14px; border: 2px solid #e2dccd; background: #fff;
  font: 900 13px 'Nunito', system-ui, sans-serif; cursor: pointer; text-align: center; transition: border-color .2s, background .2s; }
.db-choice input { position: absolute; opacity: 0; pointer-events: none; }
.db-choice label:has(input:checked) { border-color: var(--ta); background: #fff1e3; box-shadow: 0 0 0 3px rgba(232, 113, 26, .2); }
.db-choice label:has(input:focus-visible) { outline: 3px solid var(--ta); outline-offset: 2px; }
.db-choice .ink { width: 28px; height: 5px; border-radius: 3px; }
.db-dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.db-dlg .cbx-btn { border-radius: 14px; }
.db-dlg .cbx-btn:not(.alt) { background: #1d1f24; color: #fffaf0; box-shadow: 0 3px 0 #000; }
.db-dlg .cbx-btn.alt { background: #ebe5d8; color: #1d1f24; box-shadow: none; }
.db-mine { margin-top: 14px; border-top: 2px solid #e2dccd; padding-top: 10px; }
.db-mine h3 { margin: 0 0 6px; font: 900 14px 'Nunito', system-ui, sans-serif; }
.db-mine ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.db-mine a { display: block; padding: 10px 12px; border-radius: 10px; background: #fff; box-shadow: inset 0 0 0 1.5px #e2dccd; font: 800 14px 'Nunito', system-ui, sans-serif; color: #1d1f24; text-decoration: none; }

/* phones: the desk runs edge to edge and the header tightens so the pad and its note fit */
@media (max-width: 560px) {
  .cbx-card.db-card { --cbx-full-pad: 16px; padding-top: 12px; padding-bottom: 16px; }
  .db-paper { padding: 32px 6px 6px; margin-bottom: 14px; }
  .db-page .cbx-hero { margin: 0 0 10px; }
  .db-page .cbx-kicker { font-size: 11px; }
  .db-page .cbx-sub { font-size: 14px; line-height: 1.35; }
  .db-tabs { margin-bottom: 8px; }
  .db-tabs button { min-height: 44px; padding: 8px 4px; }
  .db-players { margin-bottom: 10px; }
}
@media (max-width: 560px) and (max-height: 740px) {
  .db-page .cbx-sub { display: none; }
}
@media (max-width: 400px) {
  .db-tabs button { font-size: 13px; }
  .db-chip { padding: 5px 12px 5px 7px; font-size: 13px; }
  .db-card .db-r-head { font-size: 27px; }
}
