@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;700;800&display=swap');

/* Color Variables */
:root {
  --color-bg: #f6f3eb;
  --color-card-bg: #ffffff;
  --color-border: #000000;
  --color-text: #1a1a1a;
  --color-muted: #5e5e5e;

  /* Puzzle Sticker Colors */
  --color-u: #fffc00; /* Yellow */
  --color-f: #ff4663; /* Red */
  --color-b: #ff9146; /* Orange */
  --color-d: #ffffff; /* White */
  --color-l: #468bff; /* Blue */
  --color-r: #67ff46; /* Green */

  /* Theme Accents (Using Cube Colors) */
  --color-blue: #468bff;
  --color-red-accent: #ff4663;
  --color-yellow: #fffc00;
  --color-lime: #67ff46;
  --color-white: #ffffff;
}

/* Global Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Screen reader utility for accessibility */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  height: 100%;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* App shell: header on top, game area fills the rest of the viewport */
.app-container {
  width: min(1320px, 100%);
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: clamp(0.6rem, 1.8vh, 1.25rem);
  padding: max(clamp(0.75rem, 2vh, 1.5rem), env(safe-area-inset-top))
           max(clamp(0.75rem, 3vw, 2rem), env(safe-area-inset-right))
           max(clamp(0.75rem, 2vh, 1.5rem), env(safe-area-inset-bottom))
           max(clamp(0.75rem, 3vw, 2rem), env(safe-area-inset-left));
}

.app-header {
  position: relative;
  text-align: center;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: clamp(2rem, 5vh, 3.25rem);
  line-height: 1;
}

/* App Header Wordmark Logo */
.app-logo {
  height: 1.2em; /* dynamically scale relative to h1 font-size */
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

.logo-text {
  fill: var(--color-text);
  transition: fill 0.2s ease;
}

.logo-tile-shadow {
  fill: var(--color-border);
}

.logo-tile {
  stroke: var(--color-border);
  transition: fill 0.2s ease;
}

.logo-tile-u {
  fill: var(--color-u);
}

.logo-tile-r {
  fill: var(--color-f);
}

.logo-char {
  transition: fill 0.2s ease;
}

.logo-char-dark {
  fill: var(--color-border);
}

.logo-char-light {
  fill: var(--color-white);
}

/* Modal Logo styles */
.help-title {
  font-size: clamp(1.25rem, 3.4vh, 1.7rem);
  text-align: center;
  margin-bottom: clamp(0.6rem, 1.8vh, 1rem);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.1em;
}

.help-wordmark {
  height: 1.1em;
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

.win-logo {
  width: 76px;
  height: 76px;
  border-radius: 16px;
  border: 4px solid var(--color-border);
  box-shadow: 5px 5px 0px var(--color-border);
  margin: 0 auto 1.25rem auto;
  display: block;
  animation: logo-pop-spin 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes logo-pop-spin {
  0% {
    transform: scale(0) rotate(-180deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.15) rotate(10deg);
  }
  80% {
    transform: scale(0.95) rotate(-5deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Round "?" help button in the top-right corner */
.btn-help {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid var(--color-border);
  background-color: var(--color-yellow);
  font-family: inherit;
  font-weight: 800;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  outline: none;
  box-shadow: 3px 3px 0px var(--color-border);
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-help:hover {
  transform: translateY(-50%) translate(-1px, -1px);
  box-shadow: 4px 4px 0px var(--color-border);
}

.btn-help:active {
  transform: translateY(-50%) translate(3px, 3px);
  box-shadow: 0px 0px 0px var(--color-border);
}

/* 2-Column Layout: the puzzle column is sized by the cube's aspect ratio so
   the artwork exactly fills it (no letterbox gaps), and the cube + sidebar
   are centered together as one group. */
.game-grid {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  gap: 1.75rem;
}

.puzzle-column {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 320 / 509.714; /* matches the SVG viewBox */
}

.sidebar-column {
  width: 320px;
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  gap: clamp(0.8rem, 2vh, 1.25rem);
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  /* breathing room so card shadows are not clipped by the scroll container */
  padding: 0.25rem 0.5rem 0.5rem 0.25rem;
  margin: -0.25rem -0.5rem -0.5rem -0.25rem;
}

/* Puzzle canvas: SVG scales to fill all the space it can get */
.canvas-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  min-height: 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.canvas-container:active {
  cursor: grabbing;
}

#puzzle-svg {
  width: 100%;
  height: 100%;
  display: block;
  isolation: isolate; /* keep the bottom-shade blending inside the SVG */
}

/* SVG Sticker Styling */
.sticker {
  stroke: var(--color-border);
  stroke-width: 4px;
  stroke-linejoin: round;
  paint-order: markers fill stroke;
  stroke-opacity: 1;
  cursor: pointer;
}

/* Cards (Neobrutalism Style) */
.card {
  background: var(--color-card-bg);
  border: 4px solid var(--color-border);
  border-radius: 20px;
  padding: clamp(0.9rem, 2vh, 1.25rem);
  box-shadow: 6px 6px 0px var(--color-border);
  width: 100%;
  flex-shrink: 0;
}

.card h2 {
  font-size: clamp(1rem, 2.4vh, 1.2rem);
  font-weight: 800;
  margin-bottom: clamp(0.55rem, 1.6vh, 1rem);
  letter-spacing: -0.5px;
  text-transform: uppercase;
  border-bottom: 4px solid var(--color-border);
  padding-bottom: 0.4rem;
  display: inline-block;
}

/* Neobrutalist Buttons */
.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 0.9rem;
  text-transform: uppercase;
  border: 3px solid var(--color-border);
  border-radius: 10px;
  cursor: pointer;
  outline: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn-action {
  width: 100%;
  padding: clamp(0.5rem, 1.5vh, 0.7rem) 0.5rem;
  box-shadow: 4px 4px 0px var(--color-border);
}

.btn-action:hover:not(:disabled) {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0px var(--color-border);
}

.btn-action:active:not(:disabled) {
  transform: translate(4px, 4px);
  box-shadow: 0px 0px 0px var(--color-border);
}

.btn:disabled {
  background-color: #e2e2e2 !important;
  color: #8c8c8c !important;
  border-color: #8c8c8c !important;
  cursor: not-allowed;
  box-shadow: 0px 0px 0px var(--color-border) !important;
  transform: none !important;
}

.btn-blue { background-color: var(--color-blue); color: white; }
.btn-red-accent { background-color: var(--color-red-accent); color: white; }
.btn-white { background-color: var(--color-white); }
.btn-yellow { background-color: var(--color-yellow); }
.btn-lime { background-color: var(--color-lime); color: #000000; }

/* Stats rows */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.stat-box {
  background: var(--color-bg);
  border: 3px solid var(--color-border);
  border-radius: 10px;
  padding: 0.45rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 3px 3px 0px var(--color-border);
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--color-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  margin-top: 0.1rem;
  font-variant-numeric: tabular-nums;
}

/* Toggles */
.toggles-row {
  display: flex;
  gap: 1.25rem;
  width: 100%;
  margin: clamp(0.5rem, 1.5vh, 0.75rem) 0;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.toggle-label {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #e2e2e2;
  border: 2px solid var(--color-border);
  transition: .2s;
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background-color: var(--color-border);
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--color-blue);
}

input:checked + .slider:before {
  transform: translateX(18px);
  background-color: white;
}

/* High Scores */
.high-scores-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.8rem;
  border-top: 2px dashed #ccc;
  padding-top: 0.75rem;
}

.high-score-item {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 600;
}

.high-score-item span:last-child {
  font-weight: 800;
  color: var(--color-muted);
}

/* Actions Card */
.action-buttons-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 0.6rem;
  width: 100%;
}

.special-algos-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-top: 2px dashed #ccc;
  padding-top: 0.75rem;
  margin-top: 0.85rem;
  width: 100%;
}

.section-label {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--color-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}

.special-algos-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  width: 100%;
}

.btn-special-algo {
  color: #000000;
  font-size: 0.78rem;
  white-space: nowrap;
}

.scramble-length-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  border-top: 2px dashed #ccc;
  padding-top: 0.75rem;
  margin-top: 0.85rem;
}

.neoselect {
  font-family: inherit;
  font-weight: 700;
  padding: 0.2rem 0.4rem;
  border: 3px solid var(--color-border);
  border-radius: 8px;
  background-color: white;
  cursor: pointer;
  outline: none;
  box-shadow: 2px 2px 0px var(--color-border);
  font-size: 0.8rem;
}

/* History Card: a compact single-line strip of the latest moves */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 4px solid var(--color-border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
  width: 100%;
}

.history-header h2 {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.btn-star {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: transform 0.1s;
  user-select: none;
  outline: none;
}

.btn-star:hover {
  transform: scale(1.2);
}

.btn-star:active {
  transform: scale(0.9);
}

/* Scramble box: always shows the full sequence as wrapped move tags */
.scramble-section {
  margin-bottom: 0.75rem;
}

.scramble-section.hidden {
  display: none;
}

.scramble-tags {
  background: var(--color-bg);
  border: 3px solid var(--color-border);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.history-strip {
  background: var(--color-bg);
  border: 3px solid var(--color-border);
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* Latest moves stick to the right; older ones overflow left and fade out */
.history-log-content {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
  height: 30px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 3.5rem);
  mask-image: linear-gradient(to right, transparent 0, #000 3.5rem);
}

/* Expanded (on click): full wrapped history, no fade */
.history-strip.expanded .history-log-content {
  flex-wrap: wrap;
  justify-content: flex-start;
  align-content: flex-start;
  height: auto;
  min-height: 30px;
  max-height: 40vh;
  overflow-y: auto;
  -webkit-mask-image: none;
  mask-image: none;
}

.history-placeholder {
  font-size: 0.72rem;
  color: var(--color-muted);
  font-style: italic;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.move-tag {
  flex: none;
  background: white;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: 1px 1px 0px var(--color-border);
  animation: pop-in 0.15s ease-out;
}

.move-tag.u-move { background-color: #fffebd; }
.move-tag.r-move { background-color: #ffcbd1; }

@keyframes pop-in {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Modal Overlay & Dialog */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(26, 26, 26, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(4px);
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: white;
  border: 5px solid var(--color-border);
  border-radius: 24px;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 10px 10px 0px var(--color-border);
  text-align: center;
  transform: scale(1);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal-content {
  transform: scale(0.85);
}

.modal-content h2 {
  font-size: 2.2rem;
  font-weight: 900;
  margin-bottom: 0.75rem;
  letter-spacing: -0.5px;
  color: var(--color-text);
}

.win-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 1.4rem !important;
  font-weight: 900;
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.win-wordmark {
  height: 2.2rem;
  width: auto;
  display: inline-block;
  vertical-align: middle;
}

.modal-congrats {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: 1.25rem;
}

.modal-stats-layout {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.modal-stats-subgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.modal-stat-box {
  background: var(--color-bg);
  border: 3px solid var(--color-border);
  border-radius: 12px;
  padding: 0.5rem 0.25rem;
  display: flex;
  flex-direction: column;
  box-shadow: 3px 3px 0px var(--color-border);
}

.modal-stat-hero-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
  margin-bottom: 0.5rem;
}

.modal-stat-hero-container .label {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.modal-stat-hero-container strong {
  font-size: 14rem;
  font-weight: 900;
  line-height: 1;
  color: var(--color-text);
  margin-top: 0.25rem;
  display: inline-flex;
  align-items: center;
}

.modal-stat-hero-container.has-new-best strong {
  font-size: 10rem;
}

.modal-stat-hero-container .new-record-badge {
  font-size: 0.8rem;
  padding: 0.15rem 0.35rem;
  border-width: 2px;
  margin-left: 0.75rem;
  vertical-align: middle;
}

.modal-stat-box .label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
}

.modal-stat-box strong {
  font-size: 1.15rem;
  font-weight: 800;
  margin-top: 0.2rem;
}

.modal-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

/* Help Modal: fluid width, sections flow into two columns on wide screens */
.help-content {
  max-width: min(720px, 100%);
  max-height: min(90dvh, 760px);
  overflow-y: auto;
  scrollbar-width: thin;
  text-align: left;
  padding: clamp(1.1rem, 3vh, 2rem);
}

.help-content h2 {
  font-size: clamp(1.25rem, 3.4vh, 1.7rem);
  text-align: center;
  margin-bottom: clamp(0.6rem, 1.8vh, 1rem);
}

.help-intro {
  margin-bottom: clamp(0.4rem, 1.4vh, 0.8rem);
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 1.75rem;
  align-items: start;
}

.help-content h3 {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 3px solid var(--color-border);
  padding-bottom: 0.2rem;
  margin: clamp(0.6rem, 1.8vh, 1.1rem) 0 0.45rem;
  display: inline-block;
}

.help-content p,
.help-content li {
  font-size: clamp(0.82rem, 1.7vh, 0.92rem);
  font-weight: 500;
  line-height: 1.55;
}

.help-content ul {
  padding-left: 1.2rem;
}

.help-content li {
  margin-bottom: 0.35rem;
}

/* Narrow viewports: sections stack in a single column */
@media (max-width: 700px) {
  .help-grid {
    grid-template-columns: 1fr;
  }
}

/* Phones: the help becomes a near-fullscreen sheet */
@media (max-width: 600px) {
  #help-modal {
    padding: 0.6rem;
  }

  .help-content {
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: none;
    border-width: 4px;
    border-radius: 18px;
    box-shadow: 6px 6px 0px var(--color-border);
  }
}

.help-content kbd {
  font-family: inherit;
  font-weight: 800;
  font-size: 0.72rem;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: 6px;
  padding: 0 0.35rem;
  box-shadow: 1px 1px 0px var(--color-border);
  white-space: nowrap;
}

.help-content .btn {
  margin-top: 1.25rem;
}

/* Confetti Canvas */
.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1001;
  transition: opacity 0.5s ease;
}

.confetti-canvas.hidden {
  opacity: 0;
}

/* New Record Badge */
.new-record-badge {
  background-color: var(--color-lime);
  color: black;
  font-size: 0.6rem;
  padding: 0.1rem 0.25rem;
  border: 1.5px solid black;
  border-radius: 4px;
  margin-left: 0.2rem;
  display: inline-block;
  vertical-align: middle;
  font-weight: 800;
  box-shadow: 1px 1px 0px var(--color-border);
}

/* Height-constrained desktop windows: tighten the sidebar and drop the
   move-history card (the URL still records every move) so the stats and
   actions fit without scrolling. */
@media (min-width: 821px) and (max-height: 740px) {
  .history-card {
    display: none;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .stat-box {
    padding: 0.35rem;
  }

  .high-scores-list {
    padding-top: 0.5rem;
    gap: 0.3rem;
  }
}

/* ============================================================
   Mobile dock: a minimal bottom bar so the puzzle owns the
   screen. Hidden on desktop. The inner styles live outside the
   media queries because both the portrait and landscape mobile
   layouts use them.
   ============================================================ */
.mobile-dock {
  display: none;
  flex-shrink: 0;
  background: var(--color-card-bg);
  border: 3px solid var(--color-border);
  border-radius: 16px;
  box-shadow: 4px 4px 0px var(--color-border);
  padding: 0.6rem 0.7rem;
}

.dock-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.dock-stats {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: none;
}

.dock-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.4rem;
}

.dock-stat-value {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dock-stat-label {
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dock-buttons {
  flex: 1;
  display: flex;
  gap: 0.5rem;
  min-width: 0;
}

.dock-buttons .btn,
.dock-extra-actions .btn {
  box-shadow: 3px 3px 0px var(--color-border);
}

.dock-buttons .btn:active:not(:disabled),
.dock-extra-actions .btn:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 0px 0px 0px var(--color-border);
}

.dock-buttons .btn-scramble-action {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.3rem;
  font-size: 0.8rem;
}

.dock-buttons .btn-undo-action,
.dock-buttons .btn-dock-more {
  flex: none;
  width: 42px;
  padding: 0.6rem 0;
  font-size: 1rem;
}

/* Extra options revealed by the "⋯" button */
.dock-extra {
  display: none;
  flex-direction: column;
  gap: 0.6rem;
  padding-bottom: 0.65rem;
  margin-bottom: 0.65rem;
  border-bottom: 2px dashed #ccc;
}

.mobile-dock.expanded .dock-extra {
  display: flex;
}

.dock-extra-toggles {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.dock-extra-actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1.2fr;
  gap: 0.5rem;
}

.dock-extra-actions .btn {
  padding: 0.5rem 0.25rem;
  font-size: 0.7rem;
  white-space: nowrap;
}

.dock-best {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-muted);
}

.dock-best strong {
  color: var(--color-text);
  font-weight: 800;
}

/* ============================================================
   Mobile portrait: distraction-free — slim header, no sidebar,
   the cube fills everything above the dock.
   ============================================================ */
@media (max-width: 820px) {
  .app-container {
    gap: 0.5rem;
    padding: max(0.5rem, env(safe-area-inset-top))
             max(0.75rem, env(safe-area-inset-right))
             max(0.6rem, env(safe-area-inset-bottom))
             max(0.75rem, env(safe-area-inset-left));
  }

  /* Slim header: title and help share one row */
  .app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .app-header h1 {
    font-size: 1.45rem;
    letter-spacing: -1px;
  }

  .btn-help {
    position: static;
    transform: none;
    width: 32px;
    height: 32px;
    border-width: 2px;
    font-size: 0.95rem;
    box-shadow: 2px 2px 0px var(--color-border);
  }

  .btn-help:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0px var(--color-border);
  }

  .btn-help:active {
    transform: translate(2px, 2px);
    box-shadow: 0px 0px 0px var(--color-border);
  }

  .sidebar-column {
    display: none;
  }

  .mobile-dock {
    display: block;
  }

  .game-grid {
    gap: 0;
  }

  .puzzle-column {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    aspect-ratio: auto; /* the SVG letterboxes itself inside the free space */
  }
}

/* ============================================================
   Landscape phones / very short windows: the dock moves to the
   side so the puzzle keeps the full height.
   ============================================================ */
@media (max-height: 520px) and (max-width: 1000px) {
  .app-container {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 0.9rem;
    row-gap: 0.4rem;
  }

  .app-header {
    grid-column: 1 / -1;
  }

  .app-header h1 {
    font-size: 1.3rem;
  }

  .game-grid {
    grid-row: 2;
    grid-column: 1;
  }

  .sidebar-column {
    display: none;
  }

  .mobile-dock {
    display: block;
    grid-row: 2;
    grid-column: 2;
    width: min(250px, 42vw);
    align-self: center;
  }

  .dock-main {
    flex-wrap: wrap;
    justify-content: center;
  }

  .dock-stats {
    width: 100%;
    justify-content: center;
  }

  .puzzle-column {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    aspect-ratio: auto;
  }
}

/* Narrow phones: stack the win modal buttons */
@media (max-width: 480px) {
  .modal-content {
    padding: 1.25rem;
  }

  .modal-content h2 {
    font-size: 1.7rem;
  }

  .modal-stats {
    gap: 0.5rem;
  }

  .modal-buttons {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
}

/* Very short screens: reclaim header space for the puzzle */
@media (max-height: 540px) {
  .app-header h1 {
    font-size: 1.5rem;
  }
}

/* Actions Header (synced style with history-header) */
.action-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 4px solid var(--color-border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.75rem;
  width: 100%;
}

.action-header h2 {
  border-bottom: none !important;
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

/* Settings Modal Styles */
.settings-content {
  max-width: min(760px, 100%);
}

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: left;
  margin-bottom: 1.25rem;
  width: 100%;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.settings-section h3 {
  border-bottom: none !important;
  margin: 0 0 0.2rem 0 !important;
}

.setting-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4rem;
  align-items: center;
  gap: 1rem;
}



.range-hints {
  display: flex;
  justify-content: space-between;
  margin: 0.45rem 5rem 0 0;
  color: var(--color-muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.color-picker-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  width: 100%;
}

@media (min-width: 780px) {
  .color-picker-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.color-picker-row {
  display: grid;
  grid-template-columns: 7.25rem 40px minmax(1rem, 1fr) 40px;
  align-items: center;
  column-gap: 0.85rem;
  background: var(--color-bg);
  border: 3px solid var(--color-border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  box-shadow: 2px 2px 0px var(--color-border);
}

.color-picker-row label {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  min-width: 0;
}

.color-picker-row input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  display: block;
  justify-self: center;
  border: 3px solid var(--color-border);
  border-radius: 6px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  background: none;
  padding: 0;
  grid-column: 2;
}

.color-picker-row input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker-row input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 3px;
}

.color-picker-row input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 3px;
}

.btn-reset-color {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  justify-self: center;
  margin: 0;
  padding: 0;
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-radius: 6px;
  box-shadow: 2px 2px 0 var(--color-border);
  line-height: 1;
  grid-column: 4;
}

.settings-content .btn-reset-color {
  margin-top: 0;
}

.btn-reset-color svg {
  display: block;
  width: 20px;
  height: 20px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-reset-color:active {
  transform: translate(1px, 1px);
  box-shadow: 0px 0px 0px var(--color-border);
}

/* Neobrutalist Range Slider */
.neorange {
  -webkit-appearance: none;
  width: 100%;
  height: 12px;
  background: white;
  border: 3px solid var(--color-border);
  border-radius: 6px;
  outline: none;
  box-shadow: 2px 2px 0px var(--color-border);
}

.neorange::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 3px solid var(--color-border);
  background: var(--color-blue);
  cursor: pointer;
  box-shadow: 1px 1px 0px var(--color-border);
}

.neorange::-webkit-slider-thumb:active {
  transform: scale(0.95);
}

.neorange::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 3px solid var(--color-border);
  background: var(--color-blue);
  cursor: pointer;
  box-shadow: 1px 1px 0px var(--color-border);
}

.debug-animation-panel {
  padding: 1rem;
}

.debug-animation-panel[hidden] {
  display: none;
}

.debug-animation-panel h2 {
  margin-bottom: 0.8rem;
}

.debug-control-row,
.debug-control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.debug-control-row,
.debug-slider-control {
  margin-top: 0.75rem;
}

.debug-animation-panel label,
.debug-animation-panel output {
  font-size: 0.8rem;
  font-weight: 800;
}

.debug-animation-panel .neorange {
  margin-top: 0.55rem;
}

@media (max-width: 600px) {
  #settings-modal {
    padding: 0.6rem;
  }

  .settings-content {
    height: auto;
    max-height: calc(100dvh - 1.2rem);
  }
}
