:root {
  color-scheme: dark;
  --bg: #0e1014;
  --card: #171a20;
  --card-edge: #242832;
  --text: #e8e9ec;
  --muted: #8b909a;
  --accent: #4f8cff;
  --warn: #ffb547;
  --rec: #e5484d;
  --radius: 14px;
  font-family: system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2030 0%, var(--bg) 60%);
  color: var(--text);
}

/* --- top bar ----------------------------------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--card-edge);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background:
    linear-gradient(90deg, #0000 31%, var(--bg) 31% 35%, #0000 35% 65%, var(--bg) 65% 69%, #0000 69%),
    linear-gradient(0deg, #0000 31%, var(--bg) 31% 35%, #0000 35% 65%, var(--bg) 65% 69%, #0000 69%),
    conic-gradient(#e53935 0 25%, #43a047 0 50%, #fdd835 0 75%, #1e88e5 0);
}

h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

.status {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: right;
}

/* --- layout: fills the window; one panel in the middle stage, the others in the side slots ------------------------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem 1.5rem;
}

.column {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 0;
}

.slot {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
}

/* The move history is a row of chips and needs little height; the solve guide needs the most. */
.slot-short {
  flex-grow: 0.5;
}

.slot-tall {
  flex-grow: 1.8;
}


.slot > .panel {
  flex: 1;
  min-width: 0;
}

@media (max-width: 1150px) {
  body {
    height: auto;
    overflow: auto;
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .slot {
    flex: none;
    height: 320px;
  }
  .stage {
    height: 65vh;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 1rem;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  cursor: default;
}

.panel-head h2 {
  margin: 0;
}

.expand {
  padding: 0.15rem 0.45rem;
  font-size: 0.95rem;
  line-height: 1;
  background: transparent;
  color: var(--muted);
  border-color: var(--card-edge);
}

.expand:hover {
  color: var(--text);
}

.stage .expand {
  display: none;
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  container-type: size;
}

h2 {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

h2 small {
  text-transform: none;
  letter-spacing: 0;
  font-weight: normal;
  opacity: 0.8;
}

/* --- camera ------------------------------------------------------------------------------------------------------ */
.video-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

video,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

video {
  object-fit: contain;
  transform: scaleX(-1);
}

.seen {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  min-height: 1.3rem;
  margin-top: 0.75rem;
}

.side {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
}

.side.faint {
  opacity: 0.5;
}

.swatch {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border-radius: 4px;
  border: 1px solid #0006;
  flex: none;
}

/* --- buttons ----------------------------------------------------------------------------------------------------- */
.actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

button {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.6rem 1rem;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

button.subtle {
  background: transparent;
  color: var(--muted);
  border-color: var(--card-edge);
}

button.subtle:hover {
  color: var(--text);
  border-color: #3a3f48;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button[hidden] {
  display: none;
}

button.recording {
  color: #fff;
  background: var(--rec);
  border-color: var(--rec);
}

/* --- stage: prompt + 3D cube ------------------------------------------------------------------------------------- */
/* --- stage: prompt + whichever panel is in the middle ------------------------------------------------------------ */
.prompt-card {
  padding: 0.85rem 1rem;
}

.prompt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.prompt-row .actions {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: none;
}

.prompt {
  font-size: 1.05rem;
  line-height: 1.45;
  margin: 0;
}

.prompt.warn {
  color: var(--warn);
}

.progress {
  height: 6px;
  border-radius: 3px;
  background: #262a33;
  overflow: hidden;
  margin-top: 0.6rem;
}

.progress[hidden] {
  display: none;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #7fb0ff);
  transition: width 0.3s ease;
}

.cube3d {
  position: relative;
  flex: 1;
  min-height: 0;
  perspective: 1400px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.cube3d:active {
  cursor: grabbing;
}

.cube3d::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: 46%;
  height: 7%;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, #0009, #0000);
  pointer-events: none;
}

.cube3d-anchor {
  position: absolute;
  left: 50%;
  top: 48%;
  transform-style: preserve-3d;
}

.tile3d {
  position: absolute;
  width: var(--tile);
  height: var(--tile);
  left: calc(var(--tile) / -2);
  top: calc(var(--tile) / -2);
  padding: calc(var(--tile) * 0.06);
  background: #08090b;
  backface-visibility: hidden;
}

.tile3d i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 14%;
  background: var(--c, #2c313b);
  box-shadow: inset 0 0 0 1px #ffffff14, inset 0 -6px 12px #0003;
}

.tile3d.unknown i {
  background: #2c313b;
}

.tile3d.uncertain i {
  background-image: repeating-linear-gradient(45deg, #0000 0 5px, #0007 5px 9px);
}

.view-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.5rem;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--card-edge);
  border-radius: 9px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
}

.segmented button.active {
  background: #262b35;
  color: var(--text);
}

.hint {
  color: var(--muted);
  font-size: 0.78rem;
}

@container (max-width: 420px) {
  .hint {
    display: none;
  }
}

@container (max-height: 260px) {
  .view-controls {
    display: none;
  }
}

/* --- moves ------------------------------------------------------------------------------------------------------- */
.moves {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.3rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

@container (min-width: 600px) {
  .moves {
    gap: 0.6rem;
  }
  .move {
    font-size: 1.7rem;
    padding: 0.4rem 0.9rem;
    border-radius: 10px;
  }
}

.moves .empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.move {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: #232833;
}

.move.gap {
  background: transparent;
  color: var(--warn);
  border: 1px dashed #ffb54780;
}

.move.next {
  background: #1f8a4c;
  color: #fff;
}

.move.latest {
  background: var(--accent);
  color: #fff;
}

/* --- unfolded net ------------------------------------------------------------------------------------------------ */
/* The unfolded cube, as an inset over the top-left of the 3D view; click to zoom it up over the cube. */
.panel-body {
  position: relative;
}

.net-inset {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 270px;
  height: 230px;
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  background: #11141acc;
  border: 1px solid var(--card-edge);
  cursor: zoom-in;
  transition: width 0.25s ease, height 0.25s ease;
}

.net-inset.zoomed {
  width: min(100%, 720px);
  height: min(100%, 560px);
  background: #11141af2;
  cursor: zoom-out;
}

.net-inset-head {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
}

.net-inset-head small {
  text-transform: none;
  letter-spacing: 0;
  font-weight: normal;
}

.net-inset-head .zoom-hint {
  margin-left: auto;
}

.net-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  container-type: size;
}

/* When the cube panel itself is small (moved to the sidebar), there is no room for the inset. */
@container (max-width: 520px) {
  .net-inset {
    display: none;
  }
}

.net {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, auto);
  gap: 8px 5px;
  /* Three rows of captioned 3×3 blocks: roughly 0.75 × width tall plus captions and the key below. */
  width: min(100cqw, calc((100cqh - 90px) * 1.33));
}

.net-face {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.net-caption {
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}

.net-face.live .net-caption {
  color: var(--text);
  font-weight: 600;
}

.net-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.net-caption .short {
  display: none;
}

.net-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.net-legend[hidden] {
  display: none;
}

.net-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.key {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 2px;
  background: #4f8cff;
}

.key.faded {
  opacity: 0.45;
}

.key.striped {
  background-image: repeating-linear-gradient(45deg, #0000 0 2px, #0008 2px 4px);
}

/* Small slot: short captions, no key, and the whole height for the cross. */
@container (max-height: 300px) {
  .net {
    width: min(100cqw, calc((100cqh - 45px) * 1.33));
  }
  .net-caption .full,
  .net-legend {
    display: none;
  }
  .net-caption .short {
    display: inline;
  }
}

.sticker {
  aspect-ratio: 1;
  border-radius: 3px;
  border: 1px solid #0008;
}

.sticker.unseen {
  opacity: 0.45;
}

.sticker.uncertain {
  background-image: repeating-linear-gradient(45deg, #0000 0 4px, #0008 4px 7px) !important;
}

/* --- dialog ------------------------------------------------------------------------------------------------------ */
dialog {
  max-width: 34rem;
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 1.5rem;
}

dialog::backdrop {
  background: #000a;
}

dialog h2 {
  margin-top: 0;
  font-size: 1.1rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

dialog p,
dialog li {
  font-size: 0.9rem;
  line-height: 1.5;
}

dialog .actions {
  flex-direction: row;
}

dialog.contribute label {
  display: grid;
  gap: 0.25rem;
  margin: 0.6rem 0;
  font-size: 0.9rem;
}

dialog.contribute label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

dialog.contribute input:not([type='checkbox']),
dialog.contribute select {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--card-edge);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

@container (min-width: 600px) {
  .net-caption {
    font-size: 0.85rem;
  }
  .net-legend {
    font-size: 0.8rem;
  }
}

/* --- solved ------------------------------------------------------------------------------------------------------ */
.confetti {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 50;
}

.celebration {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 1.1rem 2.2rem;
  border-radius: 16px;
  background: #171a20ee;
  border: 1px solid #43a04780;
  box-shadow: 0 10px 40px #0008, 0 0 40px #43a04740;
  text-align: center;
  cursor: pointer;
  animation: pop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.celebration[hidden] {
  display: none;
}

.celebration .title {
  font-size: 2.2rem;
  font-weight: 700;
  background: linear-gradient(90deg, #fdd835, #fb8c00, #e53935, #1e88e5, #43a047);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.celebration .stats {
  margin-top: 0.3rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(0.7);
  }
}

/* On the container, not the 3D anchor: a filter on a preserve-3d element would flatten the cube. */
.cube3d.celebrating {
  animation: glow 1.8s ease-out;
}

@keyframes glow {
  30% {
    filter: drop-shadow(0 0 28px #fdd835aa);
  }
}

/* --- solve panel: guide ------------------------------------------------------------------------------------------ */
.panel-tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.segmented.small button {
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
}

.guide {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.45;
}

.guide[hidden],
#solution[hidden] {
  display: none;
}

.guide-stages {
  display: flex;
  gap: 0.3rem;
  list-style: none;
  padding: 0;
  margin: 0 0 0.6rem;
}

.guide-stages li {
  flex: 1;
  text-align: center;
  font-size: 0.7rem;
  padding: 0.15rem 0;
  border-radius: 5px;
  background: #232833;
  color: var(--muted);
}

.guide-stages li.done {
  background: #1f8a4c55;
  color: #9fe0b5;
}

.guide-stages li.current {
  background: var(--accent);
  color: #fff;
}

.guide-title {
  font-size: 0.95rem;
  margin: 0 0 0.25rem;
}

.guide-focus {
  margin: 0 0 0.6rem;
  color: var(--text);
}

.guide-part {
  margin-bottom: 0.55rem;
}

.guide-label {
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.25rem;
}

.guide .moves {
  flex: none;
  overflow: visible;
}

.move.made {
  opacity: 0.35;
  text-decoration: line-through;
}

.guide-hold {
  font-size: 0.78rem;
  color: var(--warn);
  margin: 0.4rem 0;
}

.guide-hold.ok {
  color: #9fe0b5;
}

.guide-why {
  margin: 0.4rem 0;
  color: var(--muted);
}

.guide-why summary {
  cursor: pointer;
  color: var(--text);
}

button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

.stage-name {
  display: none;
}

@container (min-width: 900px) {
  .stage-name {
    display: inline;
  }
}

@container (min-width: 600px) {
  .guide {
    font-size: 1rem;
  }
  .guide-title {
    font-size: 1.3rem;
  }
  .guide-stages li {
    font-size: 0.85rem;
    padding: 0.3rem 0;
  }
}

/* --- notation dialog --------------------------------------------------------------------------------------------- */
dialog.notation {
  max-width: 46rem;
}

.notation .muted {
  color: var(--muted);
}

.notation-body {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1rem;
  align-items: start;
  margin: 0.5rem 0 1rem;
}

.cube3d.demo {
  height: 240px;
  min-height: 0;
  flex: none;
}

.demo-moves {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.35rem;
}

.demo-moves button {
  font-family: ui-monospace, monospace;
  padding: 0.35rem 0;
}

.demo-words {
  min-height: 4.5em;
  font-size: 0.88rem;
}

/* Guide in a small slot: the step, what's next and the moves; the long explanation is one click away (⤢). */
@container (max-height: 420px) {
  .guide-why {
    display: none;
  }
  .guide-stages {
    margin-bottom: 0.4rem;
  }
  .guide-stages li {
    padding: 0;
  }
  .guide-title {
    font-size: 0.88rem;
  }
  .guide-focus,
  .guide-part {
    margin-bottom: 0.35rem;
  }
  .guide-hold {
    font-size: 0.72rem;
    margin: 0.25rem 0;
  }
}

/* --- a move chip's 3D preview ------------------------------------------------------------------------------------ */
.guide .move,
#solution .move {
  cursor: pointer;
}

.guide .move:hover,
#solution .move:hover {
  outline: 1px solid var(--accent);
}

.move-peek {
  position: fixed;
  z-index: 45;
  width: 280px;
  padding: 0.6rem;
  border-radius: 14px;
  background: #171a20f5;
  border: 1px solid var(--card-edge);
  box-shadow: 0 12px 36px #000a;
  animation: pop-in-plain 0.2s ease-out;
}

.move-peek[hidden] {
  display: none;
}

.cube3d.solve-preview {
  min-height: 140px;
}

.cube3d.peek {
  height: 200px;
  flex: none;
  min-height: 0;
}

.move-peek-words {
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text);
}

@keyframes pop-in-plain {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}
