
/* Solve view specific, non-invasive fixes */

/* Keep canvas as stacking context and ensure background is always visible */
.solve-canvas { position: relative; overflow: hidden; box-sizing: border-box; }
.solve-canvas .solver-controls { z-index: 1000 !important; }

/* ==== Solve: inline app loader (no animation, only over app area) ==== */
.solve-app-host{ position: relative; }
#solve-root{ min-height: clamp(480px, 72vh, 900px); }
@supports (height: 100lvh) {
  #solve-root{ min-height: clamp(480px, 72lvh, 900px); }
}
@supports (height: 100dvh) and (not (height: 100lvh)) {
  #solve-root{ min-height: clamp(480px, 72dvh, 900px); }
}

#solve-app-loader{
  position: absolute;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.86));
  border-radius: 14px;
  transition: opacity .18s ease;
}
html[data-theme="dark"] #solve-app-loader{
  background: linear-gradient(180deg, rgba(18, 18, 20, 0.86), rgba(18, 18, 20, 0.86));
}
#solve-app-loader.is-hiding{ opacity: 0; pointer-events: none; visibility: hidden; }
#solve-app-loader .loader-card{ display: grid; place-items: center; gap: 8px; }
#solve-app-loader .loader-logo{ display:block; height: clamp(80px, 22vh, 180px); width: auto; }
#solve-app-loader .loader-text{ font-weight: 600; opacity: .75; }

/* Standard puzzle: stable background that doesn't bleed below */
.solve-canvas[data-ptype="standard"]{
  /* Lock canvas box to a predictable height window, relaxed to allow zooming tall puzzles */
  height: clamp(480px, 82vh, 1200px) !important;
  min-height: 480px;
  width: 100%;
  display: block;
  isolation: isolate; /* keep stacking context, avoid clipping parent */
  /* Own background (disable SFC pseudo-element to avoid cuts/duplication) */
  background-color: #ffffff !important;
  background-image:
    radial-gradient(1200px 800px at 15% 0%, rgba(255, 230, 165, 0.20), rgba(255,255,255,0) 60%),
    radial-gradient(900px 700px at 85% 100%, rgba(189, 163, 255, 0.12), rgba(255,255,255,0) 60%),
    radial-gradient(circle at 1px 1px, rgba(123,63,163,0.055) 1px, transparent 1.4px);
  background-position: center top;
  background-repeat: no-repeat;
  background-size: 100% 100%, 100% 100%, 18px 18px;
}
/* Prefer large/dynamic viewport units to avoid soft-keyboard shrink */
@supports (height: 100lvh) {
  .solve-canvas[data-ptype="standard"]{ height: clamp(480px, 82lvh, 1200px) !important; }
}
@supports (height: 100dvh) and (not (height: 100lvh)) {
  .solve-canvas[data-ptype="standard"]{ height: clamp(480px, 82dvh, 1200px) !important; }
}
/* Apply keyboard-safe height to all puzzle types (non-fullscreen) */
@supports (height: 100lvh) {
  body[data-page="solve"] .solve-canvas{ height: clamp(480px, 72lvh, 900px) !important; }
}
@supports (height: 100dvh) and (not (height: 100lvh)) {
  body[data-page="solve"] .solve-canvas{ height: clamp(480px, 72dvh, 900px) !important; }
}
/* Also drive the pseudo-element background used by SFC to avoid flicker/cuts */
.solve-canvas[data-ptype="standard"]::before{
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1200px 800px at 15% 0%, rgba(255, 230, 165, 0.20), rgba(255,255,255,0) 60%),
    radial-gradient(900px 700px at 85% 100%, rgba(189, 163, 255, 0.12), rgba(255,255,255,0) 60%),
    radial-gradient(circle at 1px 1px, rgba(123,63,163,0.055) 1px, transparent 1.4px);
  background-size: 100% 100%, 100% 100%, 18px 18px;
  background-repeat: no-repeat;
  background-position: center top;
  /* Disable animation for standard to avoid perceived jumps during grid mount */
  animation: none;
}
html[data-theme="dark"] .solve-canvas[data-ptype="standard"]{
  background-color: #111111 !important;
  background-image:
    radial-gradient(1200px 800px at 15% 0%, rgba(123,63,163, 0.20), rgba(0,0,0,0) 60%),
    radial-gradient(900px 700px at 85% 100%, rgba(255, 193, 7, 0.10), rgba(0,0,0,0) 60%),
    radial-gradient(circle at 1px 1px, rgba(189,163,255,0.06) 1px, transparent 1.4px);
  background-position: center top;
  background-repeat: no-repeat;
  background-size: 100% 100%, 100% 100%, 18px 18px;
}
html[data-theme="dark"] .solve-canvas[data-ptype="standard"]::before{
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(1200px 800px at 15% 0%, rgba(123,63,163, 0.20), rgba(0,0,0,0) 60%),
    radial-gradient(900px 700px at 85% 100%, rgba(255, 193, 7, 0.10), rgba(0,0,0,0) 60%),
    radial-gradient(circle at 1px 1px, rgba(189,163,255,0.06) 1px, transparent 1.4px);
  background-size: 100% 100%, 100% 100%, 18px 18px;
  background-repeat: no-repeat;
  background-position: center top;
  animation: none;
}

/* Ensure outer wrappers do not clip content during initial mount */
.solve-wrap{ position: relative; overflow: visible; }

/* Harden layout against test.css regressions */
.solver-layout { 
  display: flex !important;
  flex-direction: row;
  align-items: flex-start;
  gap: 20px;
  position: relative; 
  overflow: visible; 
  width: 100%;
}
.solver-left { 
  position: relative; 
  overflow: visible;
  /* Force expand to fill remaining space, do not shrink to content */
  flex: 1 0 0%; 
  width: 100%;
}
.solver-right {
  flex: 0 0 320px;
  width: 320px;
  max-width: 35vw;
}

@media (max-width: 991.98px) {
  .solver-layout {
    flex-direction: column;
  }
  .solver-left, .solver-right {
    width: 100%;
    flex: none;
    max-width: 100%;
  }
}

/* Hidden IME input: keep fixed and invisible so focusing it won't scroll the page */
.mobile-ime{
  position: fixed !important;
  left: 0;
  bottom: env(safe-area-inset-bottom, 0);
  width: 1px; height: 1px;
  opacity: 0; pointer-events: none;
  z-index: -1;
}



/* Hide header theme switch on solve page to avoid overlap with floating controls */
body[data-page="solve"] #site-header .theme-switch,
body[data-page="solve"] #site-header #theme-toggle{ display: none !important; }

/* === Mobile: fullscreen overlay left menu when burger opened (override test.css) === */
@media (max-width: 991.98px){
  /* Make opened left menu cover the screen (under header) */
  #menu.menu-open{
    position: fixed !important;
    top: var(--header-h);
    left: 0; right: 0; bottom: 0;
    width: 100% !important;
    height: calc(100vh - var(--header-h)) !important;
    overflow: auto;
    z-index: 1400;
    background: linear-gradient(180deg, var(--lemon-100), var(--lemon-50));
  }
  /* Stack only top-level items vertically when open (keep submenus collapsible) */
  #menu.menu-open nav > ul{ display: block !important; padding: 12px; }
  #menu.menu-open nav > ul > li{ display: block !important; }
}

/* Hide home link inside left menu (handled in header) */
#menu .menu-home{ display: none !important; }

/* Theme toggle visibility: only inside mobile menu when open */
@media (min-width: 992px){
  #menu .theme-toggle-item{ display: none !important; }
}
@media (max-width: 991.98px){
  #menu .theme-toggle-item{ display: none !important; }
  #menu.menu-open .theme-toggle-item{ display: block !important; }
  /* Hide entire menu bar when closed (avoid stray <ul> line) */
  #menu:not(.menu-open),
  #menu:not(.menu-open) nav,
  #menu:not(.menu-open) ul{ display: none !important; height: 0 !important; padding: 0 !important; margin: 0 !important; border: 0 !important; }
}

/* ===== Panoramic question boxes and arrows (safe overrides) ===== */
/* Softer background + borders for in-grid and overlay question boxes */
.solve-canvas .solve-grid .pan-q,
.solve-canvas .pan-layer .pan-q,
.solve-canvas .pan-layer .pan-q-slot{
  background: rgba(246, 239, 255, 0.96);
  border: 1px solid rgba(123, 63, 163, 0.18);
}

/* Active question: calm inner glow, no underline */
.solve-canvas .pan-q.pan-q--active{
  border-color: rgba(123,63,163,0.45);
  box-shadow:
    0 0 0 1px rgba(123,63,163,0.30) inset,
    0 0 10px rgba(123,63,163,0.14);
  position: relative;
}

/* Subtle text glow for active question */
.solve-canvas .pan-q.pan-q--active .pan-q-t{ animation: panQTextGlow 1600ms ease-in-out infinite; }
@keyframes panQTextGlow{
  0%   { text-shadow: 0 0 0 rgba(123,63,163,0.00); }
  50%  { text-shadow: 0 0 10px rgba(123,63,163,0.28); }
  100% { text-shadow: 0 0 0 rgba(123,63,163,0.00); }
}

/* Start arrows: refined stroke/head without changing geometry */
.solve-canvas .solve-cell .start-diag{ color: #7b3fa3; }
.solve-canvas .solve-cell .start-diag polyline{
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  filter: drop-shadow(0 0 1px rgba(123,63,163,0.28));
}
.solve-canvas .solve-cell .start-diag polygon{
  fill: currentColor;
  filter: drop-shadow(0 0 1px rgba(123,63,163,0.28));
  transition: transform 0.2s ease, filter 0.2s ease;
  transform-origin: center;
}
.solve-canvas .solve-cell .start-diag.active-arrow polygon,
.solve-canvas .solve-cell .start-diag.active-arrow polyline,
.solve-canvas .solve-cell .start-diag.active-arrow path {
  color: #9d5bd9 !important; /* Slightly lighter/brighter purple */
  fill: currentColor !important;
  stroke: currentColor !important;
  filter: drop-shadow(0 0 2px rgba(157, 91, 217, 0.4)) !important;
}
.solve-canvas .solve-cell .start-diag.active-arrow polygon {
  animation: arrowPulse 3s infinite ease-in-out !important;
}
@keyframes arrowPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Dark theme adjustments */
html[data-theme='dark'] .solve-canvas .solve-cell .start-diag{ color: #bda3ff; }
html[data-theme='dark'] .solve-canvas .solve-grid .pan-q,
html[data-theme='dark'] .solve-canvas .pan-layer .pan-q,
html[data-theme='dark'] .solve-canvas .pan-layer .pan-q-slot{
  background: rgba(30, 30, 33, 0.94);
  border: 1px solid rgba(189, 163, 255, 0.16);
  color: #f0f0f0;
}
/* Ensure layout container never clips the canvas */
.solver-layout{ position: relative; overflow: visible; align-items: start; }
.solver-left{ position: relative; overflow: visible; }

.mobile-questions-drag {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 280px;
  max-height: 40vh;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #ccc;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mobile-questions-drag .drag-handle {
  width: 100%;
  height: 20px;
  background-color: #f0f0f0;
  cursor: move;
  border-bottom: 1px solid #ccc;
  position: relative;
}

.mobile-questions-drag .drag-handle::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 4px;
  background-color: #aaa;
  border-radius: 2px;
}

.mobile-questions-drag .clue-group {
  padding: 10px;
  overflow-y: auto;
}

html[data-theme="dark"] .mobile-questions-drag {
  background: rgba(30, 30, 30, 0.9);
  border-color: #555;
}

html[data-theme="dark"] .mobile-questions-drag .drag-handle {
  background-color: #444;
  border-bottom-color: #555;
}

html[data-theme="dark"] .mobile-questions-drag .drag-handle::before {
  background-color: #888;
}

/* === Report modal: dark theme polish === */
html[data-theme="dark"] .modal-content{
  background-color: #16161a;
  color: #f3f3f5;
  border-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer{
  border-color: rgba(255,255,255,0.08);
}
html[data-theme="dark"] .modal-body{
  color: #f3f3f5;
}
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .form-control{
  background-color: #1f1f25;
  color: #f3f3f5;
  border-color: rgba(255,255,255,0.16);
}
html[data-theme="dark"] .form-select:focus,
html[data-theme="dark"] .form-control:focus{
  border-color: #9d5bd9;
  box-shadow: 0 0 0 0.2rem rgba(157,91,217,0.25);
}
html[data-theme="dark"] .btn-close{
  filter: invert(90%);
}
/* Keep modals above sticky header on solve page */
body[data-page="solve"] .modal{
  z-index: 4000;
}
body[data-page="solve"] .modal-backdrop{
  z-index: 3990;
}

/* Force header height to stay fixed on mobile solve page */
@media (max-width: 991.98px) {
  body[data-page="solve"] #site-header {
    height: 72px !important; /* Increased from 64px */
    min-height: 72px !important;
    max-height: 72px !important; /* Strictly lock it */
    overflow: hidden;
    grid-template-rows: 72px !important;
    align-items: center !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }

  body[data-page="solve"] .header-left,
  body[data-page="solve"] #home-link {
    flex-shrink: 0 !important; /* Prevent flex shrinking */
  }

  body[data-page="solve"] #home-link {
    height: 60px !important; /* Increased from 48px */
    min-height: 60px !important;
    max-height: 60px !important;
    width: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    padding: 0 4px !important; /* Reduce padding to give more space for image */
  }

  body[data-page="solve"] .home-logo {
    height: 52px !important; /* Increased from 40px */
    min-height: 52px !important;
    max-height: 52px !important;
    width: auto !important; /* Ensure aspect ratio */
    min-width: 80px !important; /* Force min-width to prevent horizontal squash */
    object-fit: contain !important;
    transition: width 0.3s ease, height 0.3s ease, transform 0.3s ease !important; /* Smooth animation */
  }
}

/* === FULLSCREEN SOLVER LOCKS (Prevent "continuation of page" leak) === */
html.solver-fs,
html.solver-fs body {
  overflow: hidden !important;
  height: 100% !important;
  width: 100% !important;
  position: fixed !important; /* Lock scroll position strictly */
  inset: 0 !important;
  touch-action: none; /* Disable browser zooming/panning on body */
}

/* Ensure the game layout sits on top of everything else */
html.solver-fs .solver-layout {
  z-index: 5 !important; /* Above page content */
  height: 100vh !important;
  height: 100dvh !important; /* Use dynamic viewport height */
}

/* If header is visible in FS, ensure it doesn't get squashed */
html.solver-fs #site-header {
  position: absolute !important; /* Attach to the fixed body, not viewport, to avoid keyboard jumps */
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  z-index: 1500 !important;
}
