/* y3 — deep dark navy + icy blue → cyan gradient. White text everywhere
   except the playing fields, which keep their own colours. */
:root {
  --navy: #050d1f;
  --navy-2: #0a1730;
  --navy-3: #10234a;
  --ice: #7dd3fc;
  --cyan: #22d3ee;
  --cyan-deep: #0891b2;
  --white: #ffffff;
  --muted: #b8c7e0;
  --grad: linear-gradient(135deg, #7dd3fc 0%, #22d3ee 55%, #06b6d4 100%);
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--navy);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100dvh; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ---- Top scoreboard bar ---- */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--navy-2);
  border-bottom: 2px solid rgba(125, 211, 252, .35);
  flex: 0 0 auto; z-index: 5;
}
#menuBtn {
  background: var(--grad); color: #04202e; border: none;
  font-size: 22px; font-weight: 800; line-height: 1;
  width: 44px; height: 44px; border-radius: 10px; flex: 0 0 auto;
}
.score-block { flex: 1; text-align: center; min-width: 0; }
.score-label {
  font-size: 11px; letter-spacing: .25em; color: var(--ice); font-weight: 700;
}
.score-digits {
  font-size: clamp(30px, 7vw, 44px); font-weight: 900; line-height: 1.05;
  font-variant-numeric: tabular-nums;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--cyan);
  text-shadow: 0 0 24px rgba(34, 211, 238, .25);
}
.top-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.mini-btn {
  width: 44px; height: 44px; border-radius: 10px; font-size: 18px;
  background: var(--navy-3); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .5);
}

/* ---- Field ---- */
#fieldWrap {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--navy); padding: 6px;
}
#game {
  width: 100%; height: 100%;
  border-radius: 12px; touch-action: none; user-select: none;
  box-shadow: 0 0 0 2px rgba(125, 211, 252, .25), 0 12px 40px rgba(0,0,0,.5);
  display: block;
}
#fieldHint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(5, 13, 31, .8); color: var(--muted);
  font-size: 12px; padding: 6px 12px; border-radius: 20px;
  pointer-events: none; white-space: nowrap; max-width: 94vw;
  overflow: hidden; text-overflow: ellipsis;
}
#toast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--grad); color: #04202e; font-weight: 800;
  padding: 10px 18px; border-radius: 24px; font-size: 15px;
  opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 8;
  max-width: 92vw; text-align: center;
}
#toast.show { opacity: 1; }
#loadingOverlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: rgba(5, 13, 31, .75); z-index: 7; border-radius: 12px;
}
#loadingOverlay.hidden { display: none; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid rgba(125, 211, 252, .25); border-top-color: var(--cyan);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingText { color: var(--white); font-weight: 600; }

/* ---- Drawer pull handle: slim full-height grip strip on the left edge.
   Always visible but only ~12px wide; drag it right to pull the menu out. ---- */
#drawerHandle {
  position: fixed; top: 0; left: 0; width: 12px; height: 100dvh; z-index: 45;
  cursor: ew-resize; touch-action: none;
  background:
    radial-gradient(circle at 6px 33%, rgba(125,211,252,.9) 1.6px, transparent 1.7px),
    radial-gradient(circle at 6px 50%, rgba(125,211,252,.9) 1.6px, transparent 1.7px),
    radial-gradient(circle at 6px 67%, rgba(125,211,252,.9) 1.6px, transparent 1.7px),
    linear-gradient(90deg, rgba(34,211,238,.6), rgba(34,211,238,.18) 70%, transparent);
}
#drawerHandle .grip-chev {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: #e0f7ff; font-size: 22px; font-weight: 900; line-height: 1;
  text-shadow: 0 0 8px rgba(34,211,238,.9); pointer-events: none;
}
#drawer {
  position: fixed; top: 0; left: 0; height: 100dvh; width: min(320px, 86vw);
  background: var(--navy-2); z-index: 40;
  transform: translateX(-105%); transition: transform .28s ease;
  display: flex; flex-direction: column; padding: 16px;
  border-right: 2px solid rgba(125, 211, 252, .4);
  box-shadow: 8px 0 40px rgba(0,0,0,.5); overflow-y: auto;
}
#drawer.dragging { transition: none; }
#drawer.open { transform: translateX(0); }
#drawerScrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 35;
  opacity: 0; pointer-events: none; transition: opacity .28s;
}
#drawerScrim.show { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; }
.drawer-logo { width: 150px; height: 150px; object-fit: cover; border-radius: 16px; display: block; }
#drawerClose {
  background: var(--navy-3); color: var(--white); border: 1px solid rgba(125,211,252,.5);
  width: 36px; height: 36px; border-radius: 9px; font-size: 15px;
}
.drawer-player, .drawer-section { margin-top: 16px; }
.drawer-player label, .drawer-section label, .start-card label {
  display: block; font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ice); font-weight: 700; margin-bottom: 6px;
}
.drawer-player input, .start-card input {
  width: 100%; padding: 11px 12px; border-radius: 10px; font-size: 16px;
  background: var(--navy); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .5); outline: none;
}
.drawer-player input:focus, .start-card input:focus { border-color: var(--cyan); }

/* ---- Custom difficulty dropdown: button + caret + option list ---- */
.dd { position: relative; }
.dd-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 11px 12px; border-radius: 10px; font-size: 16px; font-weight: 700;
  background: var(--navy); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .5); outline: none; text-align: left;
}
.dd-btn:focus { border-color: var(--cyan); }
.dd-caret { color: var(--ice); font-size: 18px; line-height: 1; flex: 0 0 auto; }
.dd-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 80;
  background: var(--navy-2); border: 1px solid rgba(125, 211, 252, .6);
  border-radius: 12px; overflow: hidden; max-height: 240px; overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0,0,0,.6);
}
.dd-option {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  font-size: 16px; font-weight: 600; background: transparent; color: var(--white);
  border: none; border-bottom: 1px solid rgba(125, 211, 252, .15);
}
.dd-option:last-child { border-bottom: none; }
.dd-option:hover { background: var(--navy-3); }
.dd-option.selected { background: var(--grad); color: #04202e; font-weight: 800; }
.empty-state { text-align: center; padding: 20px 8px; color: var(--muted); font-size: 15px; }
.drawer-btn {
  display: block; width: 100%; text-align: left; margin-top: 10px;
  padding: 13px 14px; border-radius: 12px; font-size: 16px; font-weight: 700;
  background: var(--navy-3); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .45);
}
.drawer-btn:hover { border-color: var(--cyan); }
.drawer-btn.primary {
  background: var(--grad); color: #04202e; border: none; text-align: center;
}
.drawer-foot { margin-top: auto; padding-top: 18px; color: var(--muted); font-size: 13px; }

/* ---- Popups (centred) ---- */
#popupOverlay {
  position: fixed; inset: 0; z-index: 60; display: flex;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(2, 6, 18, .72);
}
#popupOverlay.hidden { display: none; }
.popup {
  position: relative; width: min(480px, 94vw); max-height: 86dvh; overflow-y: auto;
  background: var(--navy-2); border: 2px solid rgba(125, 211, 252, .5);
  border-radius: 18px; padding: 24px 20px 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
#popupClose {
  position: absolute; top: 10px; right: 10px; width: 34px; height: 34px;
  border-radius: 9px; background: var(--navy-3); color: var(--white);
  border: 1px solid rgba(125,211,252,.5); font-size: 14px;
}
#popupContent h2 {
  font-size: 22px; margin-bottom: 10px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
#popupContent p { color: var(--white); line-height: 1.55; margin-bottom: 10px; }
#popupContent .muted { color: var(--muted); font-size: 14px; }
#popupContent input[type=text], #popupContent input:not([type]) {
  width: 100%; padding: 12px; border-radius: 10px; font-size: 17px;
  background: var(--navy); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .5); margin: 8px 0;
}
.popup-btn {
  display: block; width: 100%; margin-top: 12px; padding: 13px;
  border-radius: 12px; border: none; font-size: 17px; font-weight: 800;
  background: var(--grad); color: #04202e; text-align: center;
}
.popup-btn.ghost {
  background: var(--navy-3); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .45);
}
.quiz-option {
  display: block; width: 100%; text-align: left; margin-top: 10px;
  padding: 14px; border-radius: 12px; font-size: 16px; font-weight: 600;
  background: var(--navy-3); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .45);
}
.quiz-option:hover { border-color: var(--cyan); }
.quiz-option.correct { background: #065f46; border-color: #34d399; }
.quiz-option.wrong { background: #7f1d1d; border-color: #f87171; }
.code-big {
  font-size: 34px; font-weight: 900; letter-spacing: .3em; text-align: center;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; padding: 12px 0;
}
.score-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.score-tab {
  flex: 1; padding: 10px 4px; border-radius: 10px; font-weight: 800; font-size: 14px;
  background: var(--navy-3); color: var(--white);
  border: 1px solid rgba(125, 211, 252, .4);
}
.score-tab.active { background: var(--grad); color: #04202e; border: none; }
.accordion { border: 1px solid rgba(125,211,252,.35); border-radius: 10px; margin-bottom: 8px; overflow: hidden; }
.accordion-head {
  width: 100%; text-align: left; padding: 12px 14px; font-size: 16px; font-weight: 800;
  background: var(--navy-3); color: var(--white); border: none;
  display: flex; justify-content: space-between; gap: 8px;
}
.accordion-body { padding: 10px 14px; background: var(--navy); }
.accordion-body .row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(125,211,252,.15); }
.accordion-body .row:last-child { border-bottom: none; }
.accordion-body .row b { font-weight: 900; }
.not-played { color: var(--muted); font-style: italic; }

/* ---- Start overlay ---- */
#startOverlay {
  position: fixed; inset: 0; z-index: 50; display: flex;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(2, 6, 18, .82);
}
#startOverlay.hidden { display: none; }
.start-card {
  width: min(420px, 94vw); background: var(--navy-2);
  border: 2px solid rgba(125, 211, 252, .5); border-radius: 20px;
  padding: 26px 22px; box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.start-card h1 {
  font-size: 52px; font-weight: 900; letter-spacing: .04em; text-align: center;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.start-card .tagline { text-align: center; color: var(--muted); margin: 6px 0 18px; line-height: 1.5; }
.start-card label { margin-top: 12px; }
.start-games { display: flex; gap: 10px; margin-top: 18px; }
.big-btn {
  flex: 1; padding: 15px 8px; border-radius: 13px; border: none;
  font-size: 17px; font-weight: 800; color: #04202e; background: var(--grad);
}
.big-btn.pool-btn { background: linear-gradient(135deg, #fca5a5, #7f1d1d); color: #fff; }
.start-links { display: flex; gap: 10px; margin-top: 12px; }
.big-btn.ghost-btn { background: var(--navy-3); color: var(--white); border: 1px solid rgba(125, 211, 252, .45); font-size: 15px; }
.start-note { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; }

@media (max-width: 480px) {
  .score-digits { font-size: 30px; }
  #fieldHint { font-size: 11px; }
  .drawer-logo { width: 120px; height: 120px; }
}

/* ---- Start popup: the "Play as" dropdown straddles the popup's bottom
   border — half inside the popup, half outside, like a floating selector
   pill. Only the start popup's dropdown moves; the drawer's is untouched.
   Geometry: .dd-btn is ~43px tall; .popup has 20px bottom padding + 2px
   border, so a -44px bottom margin on the wrapper pulls the border up to
   the button's middle (the border sits 22px above the button's bottom
   edge, i.e. across its centre). Overflow must be visible or the half
   outside the popup would be clipped. */
.popup.start-form { overflow: visible; }
.popup.start-form .start-playas { margin-bottom: -44px; }

/* ---- Start popup X close: bigger, bolder, unmissable (start popup only).
   The generic #popupClose already exists and is shown for this popup; the
   start form gets a larger, high-contrast close button so it can't be
   missed. Other popups keep the standard 34px X. The title gets right
   padding so it never runs under the bigger X. */
.popup.start-form #popupClose {
  width: 44px; height: 44px; font-size: 20px; font-weight: 900;
  background: var(--cyan); color: #04202e; border: 2px solid var(--cyan);
  z-index: 5;
}
.popup.start-form #popupContent h2 { padding-right: 52px; }
