/* ================================
   Inasra — Full Stylesheet (replace)
   ================================ */

:root {
  --bg: #0b1020;
  --panel: #0e1426;
  --line: #334155;
  --text: #e5e7eb;
  --text-dim: #cbd5e1;
  --accent: #3b82f6;
  --accent-2: #38bdf8;

  /*
    INASRA typography
    Title: quiet literary serif for the title-page / coffee-table feel.
    Body: readable, hospitable UI text.
    Grid: unambiguous crossword letters and clue numbers.
  */
  --font-title: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, "Noto Serif", "Liberation Serif", "DejaVu Serif", serif;
  --font-body: "Atkinson Hyperlegible", "Source Sans 3", "Segoe UI", "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-grid: "IBM Plex Mono", "Atkinson Hyperlegible Mono", "Cascadia Mono", "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;            /* the app itself scrolls internally */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


body {
  position: relative;
}

#kenBurnsWallpaper {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: .24;
  background:
    linear-gradient(180deg, rgba(4, 8, 18, 0.92), rgba(8, 12, 24, 0.84)),
    #040812;
  border-radius: 12px;
  z-index: 0;
}

#kenBurnsWallpaper .kb-layer,
#kenBurnsWallpaper .kb-vignette {
  position: absolute;
  inset: -4%;
}

#kenBurnsWallpaper .kb-layer {
  opacity: 0;
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  will-change: transform, opacity;
  filter: saturate(1.03) contrast(1.05) brightness(.86);
}

#kenBurnsWallpaper .kb-layer.kb-visible {
  opacity: 1;
}

#kenBurnsWallpaper .kb-layer.kb-animate {
  animation-name: kb-panzoom;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

#kenBurnsWallpaper .kb-vignette {
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(8, 12, 24, 0.04) 0%, rgba(8, 12, 24, 0.20) 48%, rgba(4, 8, 18, 0.68) 100%),
    linear-gradient(180deg, rgba(7, 11, 20, 0.16), rgba(7, 11, 20, 0.36));
}

@keyframes kb-panzoom {
  from {
    transform: translate3d(var(--kb-from-x, 0%), var(--kb-from-y, 0%), 0) scale(var(--kb-from-scale, 1.12));
  }
  to {
    transform: translate3d(var(--kb-to-x, 0%), var(--kb-to-y, 0%), 0) scale(var(--kb-to-scale, 1.24));
  }
}

#app {
  position: relative;
  z-index: 1;
}

/* ================================
   App Layout
   - left controls / center canvas / right info
   - right panel never drifts off-screen
   ================================ */
#app {
  display: grid;
  grid-template-columns:
    clamp(260px, 18vw, 320px)     /* left */
    minmax(0, 1fr)                /* center */
    clamp(360px, 28vw, 560px);    /* right */
  gap: 12px;
  height: 100vh;
  padding: 10px;
}

/* Panels */
#leftPanel, #rightPanel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  overflow: auto;
}

/* Center board wrapper
   - JS sets the canvas size; this wrapper simply centers it */
#canvasWrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #091024;
  min-height: 80vh;               /* gives breathing room vertically */
  overflow: hidden;               /* keep the board crisp */
}

/* Make sure canvas respects wrapper and doesn’t spill */
#board {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

/* ================================
   Typography & Cards
   ================================ */
h1 {
  margin: 4px 0 8px;
  font-family: var(--font-title);
  font-size: 18px;
  font-weight: 700;
}
h2 {
  margin: 8px 0;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-dim);
}
.tiny { font-size: 12px; color: var(--text-dim); }

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
  background: #0b1120;
}

.log {
  max-height: 200px;
  overflow: auto;
  border: 1px dashed var(--line);
  padding: 6px;
  border-radius: 8px;
}

/* ================================
   Inputs & Buttons
   ================================ */
input, select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  outline: none;
  font-family: var(--font-body);
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59,130,246,.25);
}

button {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0b1220;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 650;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }

/* ================================
   Docked chooser (right column)
   ================================ */
.chooser-dock {
  display: none;                  /* toggled by JS */
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0b1020;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  margin-bottom: 12px;
}
.chooser-dock header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.chooser-dock header b { font-weight: 600; }
.chooser-dock .body {
  max-height: 76vh;               /* tall, but leaves room for summary */
  overflow: auto;
  padding: 8px 10px;
}

.choice {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 6px 0;
  background: #0b1220;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.choice:hover { border-color: var(--accent); background: #0c162a; }

/* ================================
   Summary & Relephants (right column)
   ================================ */
#summaryBox {
  min-height: 220px;              /* reserve space to avoid layout jumps */
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}
#summaryBox a { color: var(--accent-2); text-decoration: none; }
#summaryBox a:hover { text-decoration: underline; }

#relephantsList {
  max-height: calc(100vh - 360px);  /* within right panel; scrolled internally */
  overflow: auto;
  padding-right: 6px;
}
#relephantsList li {
  margin: 4px 0;
}
#relephantsList a {
  color: var(--text);
  text-decoration: none;
}
#relephantsList a:hover {
  color: var(--accent-2);
  text-decoration: underline;
}

/* ================================
   Confirmation Modal
   ================================ */
.backdrop {
  position: fixed;
  inset: 0;
  display: none;                  /* toggled by JS */
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  z-index: 50;
}
.modal {
  width: min(540px, 92vw);
  background: #0b1020;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.modal header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.modal .body { padding: 10px 12px; }
.btnrow {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 8px 12px 12px;
}

/* ================================
   Scrollbar Tweak (WebKit)
   ================================ */
#rightPanel::-webkit-scrollbar,
#leftPanel ::-webkit-scrollbar,
.chooser-dock .body::-webkit-scrollbar,
.log::-webkit-scrollbar,
#relephantsList::-webkit-scrollbar,
#summaryBox::-webkit-scrollbar,
#referenceSummaryBox::-webkit-scrollbar,
#referenceRelationshipBox::-webkit-scrollbar {
  width: 10px;
}
#rightPanel::-webkit-scrollbar-thumb,
#leftPanel ::-webkit-scrollbar-thumb,
.chooser-dock .body::-webkit-scrollbar-thumb,
.log::-webkit-scrollbar-thumb,
#relephantsList::-webkit-scrollbar-thumb,
#summaryBox::-webkit-scrollbar-thumb,
#referenceSummaryBox::-webkit-scrollbar-thumb,
#referenceRelationshipBox::-webkit-scrollbar-thumb {
  background: #1f2a44;
  border-radius: 8px;
  border: 2px solid #0b1020;
}

/* ================================
   Responsive
   ================================ */
@media (max-width: 1100px) {
  #app {
    grid-template-columns:
      clamp(240px, 22vw, 300px)
      minmax(0, 1fr)
      clamp(300px, 30vw, 420px);
  }
  #summaryBox { max-height: 240px; }
  #relephantsList { max-height: calc(100vh - 340px); }
}

/* Utility */
.hidden { display: none !important; }


/* Crib in bottom-left: make the left panel a column so sticky works nicely */
#leftPanel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Push crib card to the bottom and keep it visible while left panel scrolls */
#cribCard {
  position: sticky;
  bottom: 10px;
  z-index: 1;              /* stay above panel scrollbar track */
}

/* Left-docked crib uses single column (narrow) */
.crib.leftDock {
  display: block;
}
.crib.leftDock h3 {
  margin: 8px 0 6px;
  font-size: 13px;
}
.cribList {
  list-style: none;
  margin: 0 0 6px 0;
  padding-left: 0;
  max-height: 22vh;        /* balanced height so both lists fit */
  overflow: auto;
}
.cribList li {
  margin: 0 0 8px 0;
}

/* Make lists a bit taller on short screens */
@media (max-height: 820px) {
  .cribList { max-height: 18vh; }
}


/* ======================================================
   TRUE COLLAPSE: left panel goes to zero width
   ====================================================== */

#leftPanel.collapsed {
  width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  border: none !important;
  opacity: 0;
  overflow: hidden !important;
  transition:
    width .45s ease,
    max-width .45s ease,
    opacity .3s ease;
}

/* Grid reconfiguration when collapsed */
#app.left-collapsed {
  grid-template-columns:
    0px                      /* left invis */
    minmax(0, 1fr)           /* center expands fully */
    clamp(360px, 28vw, 560px); /* right */
  transition: grid-template-columns .35s ease;
}

/* Grid when expanded */
#app.left-expanded {
  grid-template-columns:
    clamp(260px, 18vw, 320px)  /* left */
    minmax(0, 1fr)
    clamp(360px, 28vw, 560px);
  transition: grid-template-columns .35s ease;
}

/* =====================================================
   TRUE COLLAPSE / TRUE EXPAND GRID SYSTEM
   ===================================================== */

/* Expanded layout — normal three columns */
#app.left-expanded {
  display: grid;
  grid-template-columns:
    clamp(260px, 18vw, 320px)   /* left */
    minmax(0, 1fr)              /* center expands */
    clamp(360px, 28vw, 560px);  /* right */
  gap: 12px;
  height: 100vh;
  padding: 10px;
  transition: grid-template-columns .35s ease;
}

/* Collapsed layout — left disappears entirely, center grows */
#app.left-collapsed {
  display: grid;
  grid-template-columns:
    0px                        /* left = fully hidden */
    minmax(0, 1fr)             /* center takes the space */
    clamp(360px, 28vw, 560px); /* right */
  gap: 12px;
  height: 100vh;
  padding: 10px;
  transition: grid-template-columns .35s ease;
}

/* =====================================================
   LEFT PANEL COLLAPSE BEHAVIOR
   ===================================================== */

#leftPanel {
  position: relative;
  transition:
    width .35s ease,
    max-width .35s ease,
    padding .25s ease,
    opacity .2s ease;
}

/* Fullscreen intro mode */
#leftPanel.seed-fullscreen {
  width: 100% !important;
  max-width: none !important;
  height: 100vh;
  overflow: hidden;
}

/* TRUE collapse to 0px — no borders, no padding, invisible */
#leftPanel.collapsed {
  width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;

  border: none !important;
  opacity: 0 !important;

  overflow: hidden !important;
  pointer-events: none; /* prevent interacting with invisible content */
}

/* =====================================================
   CENTER PANEL VISIBILITY ANIMATION
   ===================================================== */

#canvasWrap.hidden,
#rightPanel.hidden {
  opacity: 0;
  transform: translateX(25px);
  transition: opacity .4s ease, transform .4s ease;
}

#canvasWrap.reveal,
#rightPanel.reveal {
  opacity: 1;
  transform: translateX(0);
}

#rightPanel {
  transition:
    width .35s ease,
    max-width .35s ease,
    padding .25s ease,
    margin .25s ease,
    border-color .25s ease,
    opacity .2s ease,
    transform .2s ease;
}

#rightPanel.collapsed-finalized {
  width: 0 !important;
  max-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: none !important;
  opacity: 0 !important;
  overflow: hidden !important;
  pointer-events: none;
}

#app.left-collapsed.right-collapsed {
  grid-template-columns:
    0px
    minmax(0, 1fr);
}

#app.left-expanded.right-collapsed {
  grid-template-columns:
    clamp(260px, 18vw, 320px)
    minmax(0, 1fr);
}

/* =====================================================
   FLOATING DEV TOGGLE BUTTON
   ===================================================== */

#leftCollapseToggle {
  position: fixed;
  top: auto;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: max(18px, env(safe-area-inset-left));
  width: 36px;
  height: 36px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: #152032;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  opacity: .85;

  z-index: 500; /* Stay well above cards, canvas, and the docked dev panel */
  transition: opacity .2s ease;
}

#leftCollapseToggle:hover {
  opacity: 1;
}

#leftCollapseToggle:hover::after {
  content: "panel";
  position: absolute;
  left: 46px;
  top: 6px;

  padding: 4px 8px;
  border-radius: 6px;

  background: #0b1020;
  border: 1px solid var(--line);
  color: var(--text);

  font-size: 12px;
  white-space: nowrap;
}


/* Make canvasWrap expand fully to grid area */
#canvasWrap {
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 8px;
}

/* Make #app allow full growth */
#app {
  padding: 0 !important;   /* remove global padding */
  gap: 1px;
}


#boardShell {
  display: grid;
  grid-template-columns: minmax(220px, 24%) minmax(0, 1fr) minmax(220px, 24%);
  gap: 12px;
  width: 100%;
  height: 100%;
  align-items: stretch;
}

#boardShell.clues-hidden {
  grid-template-columns: minmax(0, 1fr);
}

#boardShell.clues-hidden .board-clues {
  display: none;
}

#boardFrame {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

#boardToolbar {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.board-toolbar-title {
  font-weight: 600;
}
.board-toolbar-actions {
  padding: 0;
}

#boardViewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #091024;
  isolation: isolate;
}

#board {
  position: relative;
  z-index: 1;
}

#boardFooterControls {
  display: flex;
  justify-content: center;
  margin-top: -2px;
}

#btnWallpaperControl {
  min-width: 180px;
}

#wallpaperControlPopup {
  position: absolute;
  left: 50%;
  bottom: 58px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  max-height: min(70vh, 680px);
  overflow: auto;
  z-index: 8;
  box-shadow: 0 18px 60px rgba(0,0,0,.48);
  background: rgba(11, 17, 32, 0.98);
  backdrop-filter: blur(6px);
}

#wallpaperControlPopup[hidden] {
  display: none !important;
}

.wallpaper-popup-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.wallpaper-popup-title {
  font-weight: 700;
}

#btnCloseWallpaperControl {
  flex: 0 0 auto;
  min-width: 36px;
  padding: 4px 8px;
}

.board-clues {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  margin-bottom: 0;
}

.board-clues-header {
  font-size: 16px;
  font-weight: 700;
}

.boardClueList {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow: auto;
  min-height: 0;
}

.boardClueList li {
  margin: 0 0 10px 0;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(51, 65, 85, 0.55);
  background: rgba(11, 17, 32, 0.75);
}

.boardClueList .clue-main {
  font-size: 13px;
  line-height: 1.45;
}

.boardClueList .clue-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
}

@media (max-width: 1320px) {
  #boardShell:not(.clues-hidden) {
    grid-template-columns: minmax(180px, 22%) minmax(0, 1fr) minmax(180px, 22%);
  }
}

@media (max-width: 1080px) {
  #boardShell:not(.clues-hidden) {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  .board-clues {
    max-height: 22vh;
  }
}


details.dev-card {
  padding: 0;
  overflow: hidden;
}

details.dev-card > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 700;
  background: linear-gradient(180deg, rgba(21, 32, 50, 0.95), rgba(11, 16, 32, 0.95));
  border-bottom: 1px solid rgba(51, 65, 85, 0.75);
}

details.dev-card > summary::-webkit-details-marker {
  display: none;
}

details.dev-card > summary::after {
  content: '▾';
  float: right;
  opacity: 0.75;
}

details.dev-card:not([open]) > summary::after {
  content: '▸';
}

.dev-card .subcard {
  padding: 12px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.45);
}

.dev-card .subcard:last-child {
  border-bottom: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0 8px;
}

.toggle-row input[type="checkbox"] {
  width: auto;
  transform: scale(1.15);
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin: 6px 0 12px;
}

.range-row output {
  min-width: 48px;
  text-align: right;
  color: var(--text-dim);
}

.kb-now-playing {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(51, 65, 85, 0.5);
  border-radius: 8px;
  background: rgba(11, 18, 32, 0.7);
}

.kb-queue-preview {
  margin: 8px 0 0;
  padding-left: 18px;
  max-height: 22vh;
  overflow: auto;
}

.kb-queue-preview li {
  margin: 0 0 6px;
}

.dev-actions {
  padding: 0;
  justify-content: flex-start;
}



#boardFrame > * {
  min-height: 0;
}

#boardViewport {
  min-height: 0;
}


@media (max-width: 900px) {
  #wallpaperControlPopup {
    width: min(92vw, 560px);
    bottom: 52px;
  }
}


#referenceHoverPopup {
  position: fixed;
  top: 120px;
  left: 120px;
  width: min(420px, calc(100vw - 32px));
  max-height: min(72vh, 720px);
  overflow: hidden;
  z-index: 900;
  box-shadow: 0 22px 64px rgba(0,0,0,.55);
  background: rgba(11, 17, 32, 0.985);
  backdrop-filter: blur(8px);
  border-color: rgba(59, 130, 246, 0.38);
}

#referenceHoverPopup[hidden] {
  display: none !important;
}

.reference-popup-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.reference-popup-title {
  font-weight: 700;
}

#btnCloseReferencePopup {
  flex: 0 0 auto;
  min-width: 36px;
  padding: 4px 8px;
}

#referenceHoverPopup .subcard {
  padding: 12px 0 0;
  border-top: 1px solid rgba(51, 65, 85, 0.45);
}

.reference-popup-header a,
.reference-mini-article a {
  color: var(--accent-2);
  text-decoration: none;
}

.reference-popup-header a:hover,
.reference-mini-article a:hover {
  text-decoration: underline;
}

.reference-mini-article {
  max-height: min(54vh, 520px);
  overflow: auto;
  padding-right: 6px;
}

.reference-mini-article p {
  margin: 0 0 1em;
  line-height: 1.48;
}

.reference-mini-article p:last-child {
  margin-bottom: 0;
}

#referenceSummaryBox,
#referenceRelationshipBox {
  overflow-wrap: anywhere;
}

#referenceRelationshipBox[data-evidence-kind="source-graph"],
#referenceRelationshipBox[data-evidence-kind="summary-fallback"] {
  color: var(--muted);
}

.choice.reference-hover-armed {
  border-color: rgba(56, 189, 248, 0.78);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.22);
}

code {
  font-family: var(--font-grid);
  font-size: 12px;
}

.google-signin-slot {
  margin-top: 8px;
  min-height: 42px;
}

.compact-row {
  justify-content: flex-start;
  padding: 8px 0 0;
  flex-wrap: wrap;
}

.saved-puzzles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.saved-puzzle-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: #0b1220;
}

/* ================================
   Top-right account controls
   ================================ */
#authDock {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 650;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

#authTrigger {
  appearance: none;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.96), rgba(10, 15, 28, 0.96));
  color: var(--text);
  border-radius: 999px;
  min-height: 42px;
  padding: 6px 10px 6px 8px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.35);
  cursor: pointer;
  transition: transform .12s ease, border-color .15s ease, background .15s ease;
}

#authTrigger:hover,
#authTrigger[aria-expanded="true"] {
  border-color: rgba(96, 165, 250, 0.55);
  background: linear-gradient(180deg, rgba(20, 30, 50, 0.98), rgba(10, 15, 28, 0.98));
}

#authTrigger:focus-visible,
#btnCloseAuthPopover:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.9);
  outline-offset: 2px;
}

.auth-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(59,130,246,.32), rgba(56,189,248,.18));
  color: #f8fafc;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  flex: 0 0 auto;
}

.auth-avatar.has-image {
  background: #0b1120;
}

.auth-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.auth-trigger-label {
  font-weight: 600;
  white-space: nowrap;
}

.auth-trigger-caret {
  color: var(--text-dim);
  font-size: 12px;
}

#authPopover {
  width: min(360px, calc(100vw - 24px));
  margin: 0;
  padding: 14px;
  background: rgba(10, 16, 30, 0.98);
  border-color: rgba(71, 85, 105, 0.95);
  box-shadow: 0 20px 48px rgba(2, 6, 23, 0.56);
}

.auth-popover-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.auth-popover-title {
  font-size: 15px;
  font-weight: 700;
}

.auth-popover-subtitle {
  margin-top: 2px;
  max-width: 30ch;
}

#btnCloseAuthPopover {
  appearance: none;
  border: 1px solid rgba(71, 85, 105, 0.9);
  background: transparent;
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  cursor: pointer;
}

#btnCloseAuthPopover:hover {
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.9);
}

#authStatus {
  margin-bottom: 12px;
}

.google-signin-slot {
  min-height: 44px;
}

.auth-popover-actions {
  margin-top: 12px;
}

#authStatus code {
  font-family: var(--font-grid);
  font-size: 12px;
  color: #c7d2fe;
}

@media (max-width: 720px) {
  #authDock {
    top: 12px;
    right: 12px;
  }

  #authTrigger {
    min-height: 38px;
    padding-right: 8px;
  }

  .auth-trigger-label {
    max-width: 18ch;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}


/* ================================
   Puzzle history modal
   ================================ */
.history-modal {
  width: min(820px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.history-modal header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#btnCloseHistory {
  appearance: none;
  border: 1px solid rgba(71, 85, 105, 0.9);
  background: transparent;
  color: var(--text-dim);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  cursor: pointer;
}

#btnCloseHistory:hover {
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.9);
}

.history-modal .body {
  overflow: auto;
}

.history-branch-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.history-branch-list button {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
}

.history-branch-list button.selected {
  border-color: rgba(56, 189, 248, 0.82);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25);
}

.history-branch-list button span {
  color: var(--text-dim);
  font-size: 11px;
}

.history-timeline {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-timeline li {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #0b1220;
}

.history-event-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-event-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.history-badge {
  display: inline-flex;
  margin-left: 6px;
  padding: 1px 6px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11px;
}

/* =====================================================
   Developer Panel Polish
   ===================================================== */

#leftCollapseToggle {
  padding: 0;
  line-height: 1;
  font: inherit;
}

#leftCollapseToggle[aria-expanded="false"] {
  background: rgba(59, 130, 246, 0.20);
  border-color: rgba(56, 189, 248, 0.75);
}

#leftCollapseToggle:hover::after {
  content: "dev panel";
}

#leftPanel {
  gap: 12px;
  scroll-behavior: smooth;
}

#leftPanel.seed-fullscreen {
  overflow: auto !important;
  padding: clamp(14px, 2vw, 24px);
}

#leftPanel .card {
  margin-bottom: 0;
}

.dev-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 2px;
}

.dev-panel-header h1 {
  margin-bottom: 2px;
  letter-spacing: 0.08em;
}

.dev-panel-badge {
  flex: 0 0 auto;
  padding: 4px 7px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  color: var(--accent-2);
  background: rgba(14, 165, 233, 0.10);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.dev-panel-nav {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(51, 65, 85, 0.72);
  border-radius: 12px;
  background: rgba(11, 17, 32, 0.94);
  backdrop-filter: blur(8px);
}

.dev-panel-nav a {
  display: block;
  padding: 6px 5px;
  border: 1px solid rgba(51, 65, 85, 0.72);
  border-radius: 8px;
  color: var(--text-dim);
  text-align: center;
  text-decoration: none;
  font-size: 11px;
  line-height: 1.1;
}

.dev-panel-nav a:hover,
.dev-panel-nav a:focus-visible {
  color: var(--text);
  border-color: var(--accent);
  outline: none;
}

details.dev-card {
  padding: 0;
  overflow: hidden;
  border-color: rgba(51, 65, 85, 0.78);
  background: rgba(11, 17, 32, 0.92);
}

details.dev-card > summary {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 12px 36px 12px 14px;
}

details.dev-card > summary::after {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  float: none;
}

.dev-summary-hint {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  opacity: 0.75;
  text-align: right;
}

.dev-card-body {
  padding: 12px;
}

.dev-section-note {
  margin: 0 0 10px;
}

.dev-control-grid {
  display: grid;
  gap: 8px;
}

.seed-control-grid {
  grid-template-columns: minmax(0, 1fr);
}

#leftPanel.seed-fullscreen .seed-control-grid {
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
}

#leftPanel label {
  display: block;
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 650;
}

.primary-action {
  border-color: rgba(56, 189, 248, 0.72);
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.30), rgba(29, 78, 216, 0.26));
  font-weight: 750;
  white-space: nowrap;
}

.status-readout {
  padding: 8px 10px;
  border: 1px solid rgba(51, 65, 85, 0.58);
  border-radius: 8px;
  background: rgba(2, 6, 23, 0.35);
}

.dev-button-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  padding: 8px 0 0;
}

#cribCard {
  position: static;
  bottom: auto;
}

#cribCard .dev-card-body {
  display: grid;
  gap: 8px;
}

#leftPanel.seed-fullscreen .crib.leftDock {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}

#leftPanel.seed-fullscreen .crib.leftDock h3:nth-of-type(1),
#leftPanel.seed-fullscreen .crib.leftDock #cribAcross {
  grid-column: 1;
}

#leftPanel.seed-fullscreen .crib.leftDock h3:nth-of-type(2),
#leftPanel.seed-fullscreen .crib.leftDock #cribDown {
  grid-column: 2;
}

#leftPanel.seed-fullscreen .cribList {
  max-height: 30vh;
}

#devSectionDiagnostics .log {
  max-height: 260px;
}

@media (max-width: 720px) {
  .dev-panel-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #leftPanel.seed-fullscreen .seed-control-grid,
  #leftPanel.seed-fullscreen .crib.leftDock {
    grid-template-columns: 1fr;
  }

  #leftPanel.seed-fullscreen .crib.leftDock h3,
  #leftPanel.seed-fullscreen .crib.leftDock #cribAcross,
  #leftPanel.seed-fullscreen .crib.leftDock #cribDown {
    grid-column: auto;
  }
}

/* =====================================================
   Developer Panel Spacing + Scroll Refinement
   - keeps developer tools readable before they are hidden by default
   ===================================================== */

#app.seed-mode {
  grid-template-columns: min(520px, 92vw) minmax(0, 1fr);
  gap: 0;
  padding: 0;
  overflow: hidden;
}

#leftPanel {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #263653 #0b1020;
}

#leftPanel.seed-fullscreen {
  width: min(520px, 100vw) !important;
  max-width: min(520px, 100vw) !important;
  height: 100dvh;
  max-height: 100dvh;
  padding: 16px 18px 20px;
  border-radius: 0 14px 14px 0;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

#leftPanel::-webkit-scrollbar,
#rightPanel::-webkit-scrollbar,
.cribList::-webkit-scrollbar {
  width: 10px;
}

#leftPanel::-webkit-scrollbar-track,
#rightPanel::-webkit-scrollbar-track,
.cribList::-webkit-scrollbar-track {
  background: rgba(2, 6, 23, 0.35);
  border-radius: 999px;
}

#leftPanel::-webkit-scrollbar-thumb,
#rightPanel::-webkit-scrollbar-thumb,
.cribList::-webkit-scrollbar-thumb {
  background: #263653;
  border: 2px solid #0b1020;
  border-radius: 999px;
}

#leftPanel::-webkit-scrollbar-thumb:hover,
#rightPanel::-webkit-scrollbar-thumb:hover,
.cribList::-webkit-scrollbar-thumb:hover {
  background: #33466b;
}

.dev-panel-header {
  min-height: 46px;
  padding: 0 2px 4px;
  margin-bottom: 8px;
  align-items: center;
}

.dev-panel-header h1 {
  margin: 0;
  line-height: 1.1;
}

.dev-panel-header .tiny {
  margin: 10px 0 0;
  max-width: 38rem;
  line-height: 1.45;
}

.dev-panel-badge {
  margin-top: 2px;
}

.dev-panel-nav {
  grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
  gap: 7px;
  margin: 0 0 14px;
  top: 0;
}

.dev-panel-nav a {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 8px;
  line-height: 1.15;
  white-space: nowrap;
}

#leftPanel .card,
#leftPanel details.dev-card {
  margin-bottom: 10px;
}

#leftPanel details.dev-card:last-child {
  margin-bottom: 0;
}

details.dev-card > summary {
  min-height: 52px;
  padding: 12px 38px 12px 14px;
  gap: 12px;
}

details.dev-card > summary > span:first-child {
  min-width: 0;
  line-height: 1.2;
}

.dev-summary-hint {
  max-width: 16ch;
  line-height: 1.2;
}

#leftPanel:not(.seed-fullscreen) .dev-summary-hint {
  display: none;
}

.dev-card-body {
  padding: 14px;
}

.dev-section-note {
  margin-bottom: 12px;
  line-height: 1.45;
}

.status-readout,
#persistStatus,
#currentPuzzleMeta,
.log {
  line-height: 1.45;
}

#leftPanel.seed-fullscreen .seed-control-grid {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

#leftPanel.seed-fullscreen .crib.leftDock {
  column-gap: 18px;
  row-gap: 2px;
}

#leftPanel.seed-fullscreen .cribList {
  max-height: 34vh;
  padding-right: 4px;
}

@media (max-width: 640px) {
  #app.seed-mode {
    grid-template-columns: 1fr;
  }

  #leftPanel.seed-fullscreen {
    width: 100vw !important;
    max-width: 100vw !important;
    border-radius: 0;
    padding-right: 14px;
  }

  .dev-panel-header {
    padding-left: 0;
  }

  #leftPanel.seed-fullscreen .seed-control-grid,
  #leftPanel.seed-fullscreen .crib.leftDock {
    grid-template-columns: 1fr;
  }
}

/* =====================================================
   Developer Panel Scroll + Navigation Fix
   - makes the open dev panel independently scrollable in play mode
   - keeps section navigation usable inside the panel scroll container
   ===================================================== */

#app {
  height: 100dvh;
  min-height: 0;
}

#app.left-expanded,
#app.left-collapsed {
  height: 100dvh;
  min-height: 0;
}

#leftPanel {
  height: calc(100dvh - 20px);
  max-height: calc(100dvh - 20px);
  min-height: 0;
  overflow-y: scroll !important;
  overflow-x: hidden !important;
  align-self: stretch;
}

#leftPanel.seed-fullscreen {
  height: 100dvh;
  max-height: 100dvh;
}

#leftPanel.collapsed {
  overflow: hidden !important;
}

#leftPanel:not(.seed-fullscreen) {
  padding: 12px 10px 72px;
}

#leftPanel:not(.seed-fullscreen) .dev-panel-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 42px;
  padding: 0 2px;
  margin: 0 0 12px;
}

#leftPanel:not(.seed-fullscreen) .dev-panel-header h1 {
  font-size: 15px;
  letter-spacing: 0.07em;
}

#leftPanel:not(.seed-fullscreen) .dev-panel-header .tiny {
  display: none;
}

#leftPanel:not(.seed-fullscreen) .dev-panel-badge {
  padding: 3px 7px;
  font-size: 9px;
}

.dev-panel-nav {
  scroll-margin-top: 10px;
}

#leftPanel:not(.seed-fullscreen) .dev-panel-nav {
  position: sticky;
  top: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
  padding: 9px;
}

#leftPanel:not(.seed-fullscreen) .dev-panel-nav a {
  min-height: 32px;
  padding: 8px 6px;
  font-size: 11px;
}

#leftPanel:not(.seed-fullscreen) details.dev-card > summary {
  min-height: 48px;
  padding: 12px 36px 12px 14px;
}

#leftPanel:not(.seed-fullscreen) .dev-card-body {
  padding: 14px 12px;
}

#leftPanel:not(.seed-fullscreen) .dev-section-note {
  margin-bottom: 12px;
}

#leftPanel:not(.seed-fullscreen) .crib.leftDock h3 {
  margin-top: 12px;
}

#leftPanel:not(.seed-fullscreen) .cribList {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

#leftPanel .dev-card.dev-nav-flash {
  border-color: rgba(56, 189, 248, 0.95);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.22), 0 0 28px rgba(56, 189, 248, 0.10);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

@media (max-width: 980px) {
  #app.left-expanded {
    grid-template-columns:
      minmax(280px, 34vw)
      minmax(0, 1fr)
      clamp(300px, 30vw, 420px);
  }
}

/* =====================================================
   Player-friendly intro seed screen
   - keeps the developer panel hidden on first launch
   - puts the initial seed prompt in the center of the playfield
   ===================================================== */

#app.intro-mode {
  display: block !important;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  gap: 0;
  padding: 0 !important;
  background:
    radial-gradient(circle at 50% 42%, rgba(56, 189, 248, 0.10), transparent 32rem),
    linear-gradient(180deg, #071020 0%, #090f1f 100%);
}

#app.intro-mode #canvasWrap,
#canvasWrap.intro-active {
  position: fixed;
  inset: 0;
  z-index: 1;
  grid-column: 1 / -1;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh;
  border: 0;
  border-radius: 0;
  padding: clamp(18px, 4vw, 48px);
  background: transparent;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#introSeedScreen {
  width: min(720px, 100%);
  display: grid;
  place-items: center;
}

#introSeedScreen[hidden] {
  display: none !important;
}

.intro-seed-card {
  width: min(680px, 100%);
  display: grid;
  gap: clamp(24px, 4vw, 42px);
  justify-items: center;
  text-align: center;
}

.intro-seed-mark {
  color: rgba(229, 231, 235, 0.92);
  font-family: var(--font-title);
  font-size: clamp(34px, 8vw, 78px);
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 0.98;
  text-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

.intro-seed-form {
  width: min(620px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

#introSeedWord {
  height: 54px;
  padding: 0 22px;
  border-radius: 999px;
  border-color: rgba(148, 163, 184, 0.34);
  background: rgba(11, 18, 32, 0.86);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  letter-spacing: 0.005em;
  box-shadow:
    0 18px 48px rgba(2, 6, 23, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

#introSeedWord::placeholder {
  color: rgba(148, 163, 184, 0.78);
}

#introSeedWord:focus {
  border-color: rgba(56, 189, 248, 0.80);
  box-shadow:
    0 18px 48px rgba(2, 6, 23, 0.38),
    0 0 0 3px rgba(56, 189, 248, 0.18);
}

#btnIntroSeed {
  height: 54px;
  padding: 0 22px;
  border-radius: 999px;
  font-size: 15px;
  letter-spacing: 0.005em;
}

@media (max-width: 640px) {
  .intro-seed-form {
    grid-template-columns: 1fr;
  }

  #btnIntroSeed {
    width: 100%;
  }
}

/* =====================================================
   Seed disambiguation mode
   - removes the fullscreen intro overlay so the chooser is clickable
   - presents Wikipedia page choices as the temporary primary view
   ===================================================== */
#app.seed-resolution-mode {
  display: grid;
  grid-template-columns: 0 minmax(0, 1fr) minmax(360px, 44vw, 560px);
  height: 100vh;
  padding: 10px !important;
  gap: 12px;
  background:
    radial-gradient(circle at 45% 34%, rgba(56, 189, 248, 0.08), transparent 30rem),
    linear-gradient(180deg, #071020 0%, #090f1f 100%);
}

#rightPanel.seed-resolution-panel {
  grid-column: 3;
  position: relative;
  z-index: 20;
}

#rightPanel.seed-resolution-panel .chooser-dock {
  display: flex;
  height: calc(100dvh - 20px);
  max-height: calc(100dvh - 20px);
  margin: 0;
}

#rightPanel.seed-resolution-panel .chooser-dock .body {
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
}

.choice.seed-choice {
  display: block;
  width: 100%;
  text-align: left;
  color: var(--text);
  font: inherit;
}

#canvasWrap.hidden {
  pointer-events: none;
}

@media (max-width: 780px) {
  #app.seed-resolution-mode {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  #rightPanel.seed-resolution-panel {
    grid-column: 2;
  }
}

/* Published crossword controls ------------------------------------------------ */
.publish-status {
  min-height: 1.25rem;
  margin-top: 0.35rem;
  color: var(--muted, #a9b3c8);
}
.publish-status a {
  color: var(--accent, #f0c86f);
  font-weight: 700;
}
.publish-status .publish-copy-link {
  margin-left: 0.5rem;
}

/* Published crossword management ------------------------------------------------ */
.published-puzzles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.published-puzzle-item {
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 12px;
  padding: 10px;
  background:
    radial-gradient(circle at top left, rgba(240, 200, 111, 0.10), transparent 42%),
    rgba(11, 18, 32, 0.92);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}

.published-puzzle-item.is-archived {
  opacity: 0.72;
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(30, 41, 59, 0.82));
}

.published-puzzle-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.published-puzzle-title {
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0.01em;
}

.published-puzzle-meta {
  color: var(--muted);
  line-height: 1.4;
  margin-top: 2px;
}

.published-puzzle-id {
  flex: 0 0 auto;
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid rgba(240, 200, 111, 0.22);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--accent);
  background: rgba(2, 6, 23, 0.45);
  font-family: var(--font-grid);
  font-size: 10px;
}

.published-public-title-row {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin: 8px 0;
  color: var(--muted);
}

.published-public-title-row input {
  min-width: 0;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.26);
  background: rgba(2, 6, 23, 0.72);
  color: var(--text);
  padding: 7px 8px;
}

.published-public-title-row input:disabled,
.published-visibility-control select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.published-puzzle-url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 8px;
  border: 1px dashed rgba(148, 163, 184, 0.24);
  padding: 6px 8px;
  background: rgba(2, 6, 23, 0.46);
  color: rgba(226, 232, 240, 0.82);
  font-family: var(--font-grid);
  font-size: 11px;
}

.published-puzzle-actions {
  align-items: center;
}

.published-visibility-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.published-visibility-control select {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(2, 6, 23, 0.75);
  color: var(--text);
  padding: 5px 8px;
}
