:root {
  --bg-1: #f7efe1;
  --bg-2: #dce8e8;
  --ink: #12232e;
  --ink-soft: #35515f;
  --card: #ffffff;
  --line: #c9d6d8;
  --accent: #0f7b8a;
  --accent-soft: #d2eef2;
  --ok: #2d8f5e;
  --mono: "IBM Plex Mono", monospace;
  --display: "Space Grotesk", sans-serif;
  --viewer-bg: #0d1b21;
}

* { box-sizing: border-box; }

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--display);
  color: var(--ink);
  background:
    radial-gradient(1000px 500px at 88% -5%, #ffdeaf 0%, transparent 60%),
    radial-gradient(900px 560px at -10% 110%, #c5e3ee 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

.app-shell {
  width: calc(100% - 2rem);
  margin: 1.6rem auto 2rem;
  display: grid;
  gap: 1rem;
}

.hero-bare {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

.hero-title {
  margin: 0 0 .35rem;
  font-size: clamp(1.8rem, 3.5vw, 3rem);
  letter-spacing: -.02em;
  color: var(--ink);
}

.hero-desc {
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: .98rem;
  max-width: 52ch;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 8px 20px rgba(26,53,58,.08);
  max-width: 100%;
}

.panel h2 { margin: 0 0 .5rem; font-size: 1.2rem; }
.helper { margin: 0 0 .9rem; color: var(--ink-soft); font-size: .93rem; }

.controls-top-row {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 1.2rem;
  align-items: start;
}

.controls-left {
  display: flex;
  flex-direction: column;
}

.controls-right {
  min-width: 0;
}

.palette-wrap { margin-bottom: .85rem; }
.palette-wrap h3 { margin: 0 0 .4rem; font-size: .95rem; }

.mobile-sticky-palette {
  display: none;
}
.palette { display: flex; flex-wrap: wrap; gap: .4rem; }

.color-chip {
  appearance: none;
  border: 2px solid transparent;
  border-radius: 999px;
  padding: .25rem .65rem .25rem .35rem;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  background: #fff;
  cursor: pointer;
  color: var(--ink);
  font-family: var(--display);
  font-size: .9rem;
}

.color-chip.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,123,138,.16); }

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.25);
}

.method-row { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; }
.method-row label { font-size: .9rem; color: var(--ink-soft); }

.method-row select {
  font-family: var(--display);
  font-size: .95rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .45rem .55rem;
  background: #fff;
}

.method-hint { margin: .45rem 0 .8rem; color: var(--ink-soft); font-size: .93rem; }

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .55rem;
  margin-top: .7rem;
  padding-top: 0;
}

.action-row .btn {
  flex: 1;
  text-align: center;
}


.action-row .status-inline {
  flex: 0 0 100%;
  width: 100%;
  order: 99;
}


.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: .55rem .85rem;
  font-family: var(--display);
  font-size: .94rem;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #f5fafb; border-color: var(--line); color: var(--ink); }

.status-inline {
  font-size: .82rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.status-inline:empty { display: none; }

.status-inline[data-tone="error"] { color: #8f2323; }
.status-inline[data-tone="ok"] { color: #1f6842; }

.face-editor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .8rem;
  align-items: start;
  max-width: 900px;
  margin-inline: auto;
}

.face-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .7rem;
  background: #fbfefe;
}

.face-title { margin: 0 0 .55rem; font-size: .95rem; display: flex; align-items: center; gap: .45rem; }

.face-title-color {
  font-size: .72rem;
  font-weight: 600;
  padding: .1rem .45rem;
  border-radius: 20px;
  color: #1a1a1a;
  letter-spacing: .02em;
  white-space: nowrap;
  border: 1px solid rgba(0,0,0,.15);
}
.face-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: .36rem; }

.sticker {
  aspect-ratio: 1;
  border: 1px solid rgba(0,0,0,.22);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
}

.sticker.center { cursor: not-allowed; }

.summary-line, .method-note { margin: 0; color: var(--ink-soft); }
.method-note { margin-top: .4rem; }

.phase-grid {
  margin-top: .8rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: .6rem;
}

.phase-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .68rem;
  background: #fdffff;
}

.phase-card h3 { margin: 0; font-size: 1rem; }
.phase-tip { margin: .35rem 0 .45rem; color: var(--ink-soft); font-size: .9rem; }
.phase-alg { margin: 0; font-family: var(--mono); font-size: .88rem; line-height: 1.4; background: #f3f8f9; border-radius: 8px; padding: .45rem; word-break: break-all; }

.viewer-shell {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--viewer-bg);
  position: relative;
}

.move-indicator {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 206px;
  max-width: min(92vw, 320px);
  background: rgba(0,0,0,.65);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  padding: 8px 14px 8px 8px;
  pointer-events: none;
}

.move-indicator.hidden { opacity: 0; pointer-events: none; }

.move-face-badge {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  border: 2px solid rgba(255,255,255,.25);
  flex-shrink: 0;
}

.move-dir-arrow { font-size: 2rem; color: #ffd700; line-height: 1; flex-shrink: 0; font-family: var(--display); text-shadow: 0 0 8px rgba(255,215,0,.6); }

.move-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.move-desc-badge {
  font-family: var(--mono);
  font-size: .8rem;
  color: rgba(255,255,255,.85);
  line-height: 1.25;
}

.move-noob-hint {
  font-size: .7rem;
  color: rgba(220,239,244,.84);
  line-height: 1.25;
  max-width: 220px;
}

.cube-3d-viewer {
  width: 100%;
  height: 430px;
  display: block;
  background: var(--viewer-bg);
}

twisty-player.cube-3d-viewer {
  width: 100%;
  height: 430px;
  min-height: 300px;
  display: block;
}

.cube-3d-viewer canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.twisty-fallback {
  width: 100%;
  min-height: 620px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  color: rgba(235,248,250,.95);
  text-align: center;
}

.twisty-fallback-note {
  margin: 0;
  font-size: .88rem;
  line-height: 1.4;
  color: rgba(235,248,250,.9);
  max-width: 520px;
}

.twisty-fallback .iso-cube-svg {
  width: min(460px, 90vw);
  height: auto;
}

.viewer-shell-nav {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  gap: .8rem;
}

.btn-shell-nav {
  min-width: 92px;
  padding: .45rem .95rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(7,14,18,.78);
  color: #f3fbff;
}

.btn-shell-nav:disabled { opacity: .38; cursor: default; }

.move-notation-badge {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffe0d8;
  background: rgba(6,10,16,.88);
  border: 1.5px solid rgba(255,120,90,.65);
  border-radius: 10px;
  padding: .32rem .65rem;
  white-space: nowrap;
  letter-spacing: .02em;
  min-width: 3.5rem;
  text-align: center;
}

.hidden { display: none !important; }
.moves-title { margin: 1rem 0 .6rem; }
.move-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(160px,100%), 1fr)); gap: .5rem; }

.step-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(214px, 100%), 1fr));
  gap: 1rem;
  margin-top: .35rem;
}

.step-card {
  border: 1px solid #d4d4d4;
  border-radius: 16px;
  padding: .68rem .58rem .54rem;
  background: #e0e0e0;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  min-height: 224px;
}

.step-card-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; min-height: 2.1rem; }
.step-card-title { font-size: 2.08rem; font-weight: 500; line-height: 1; color: #273845; letter-spacing: -.01em; padding-left: .05rem; }
.step-card-cube-wrap { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; position: relative; gap: .4rem; }

.step-card-notation {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: #ffe0d8;
  background: rgba(6,10,16,.88);
  border: 1.5px solid rgba(255,120,90,.65);
  border-radius: 8px;
  padding: .28rem .42rem;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: .02em;
}
.step-card-repeat { font-family: var(--display); font-size: 1.28rem; font-weight: 700; color: #101417; background: #f0f2f4; border: 1px solid #bcc6cd; border-radius: 8px; padding: .06rem .34rem; }

.iso-cube-svg { display: block; width: 176px; height: 160px; overflow: visible; }

.step-card-side {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: 100%;
}

.step-card-dir {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .22rem;
}

.step-card-dir-face {
  font-family: var(--mono);
  font-size: .66rem;
  font-weight: 700;
  color: #4a6070;
  text-transform: uppercase;
  letter-spacing: .05em;
  line-height: 1;
  white-space: nowrap;
}

.step-card-dir-label {
  font-family: var(--display);
  font-size: .71rem;
  font-weight: 700;
  color: #12263a;
  background: #cfe8f2;
  border: 1.5px solid #7ab8d0;
  border-radius: 6px;
  padding: .2rem .42rem;
  white-space: nowrap;
  line-height: 1.25;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.step-card-finish {
  background: linear-gradient(140deg, #fffbe6, #f0fdf4);
  border-color: #4cb86c;
}

.step-card-finish .step-card-title {
  color: #1f6842;
}

.finish-overlay {
  font-size: 4rem;
  line-height: 1;
  text-align: center;
  animation: pop-in .4s cubic-bezier(.36,1.56,.64,1) both;
}

@keyframes pop-in {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---- 3D Editor ---- */

.view-toggle-group {
  display: flex;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #f0f4f5;
  margin-bottom: .85rem;
}

.view-toggle-btn {
  appearance: none;
  border: none;
  background: transparent;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  padding: .55rem 0;
  flex: 1;
  cursor: pointer;
  color: var(--ink-soft);
  letter-spacing: .06em;
  transition: background .15s, color .15s;
}

.view-toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.editor-3d-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: center;
}

.editor-3d-canvas-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #0d1b21;
  box-shadow: 0 6px 24px rgba(0,0,0,.22);
  flex: 0 0 auto;
}

#cube3DCanvas {
  display: block;
  width: 420px;
  height: 420px;
}

@media (max-width: 480px) {
  #cube3DCanvas { width: 290px; height: 290px; }
}

.editor-3d-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .72rem;
  color: rgba(220,240,245,.7);
  white-space: nowrap;
  pointer-events: none;
  font-family: var(--mono);
}

.editor-3d-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
}

.editor-3d-controls-mid {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.btn-3d-rot {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f5fafb;
  color: var(--ink);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.btn-3d-reset {
  font-size: 1.3rem;
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* ---- Camera Editor ---- */

.editor-camera-wrap {
  width: 100%;
}

.editor-camera-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: center;
}

.editor-camera-inner {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #0d1b21;
  box-shadow: 0 6px 24px rgba(0,0,0,.22);
  flex: 0 0 auto;
}

#cameraCanvas {
  display: block;
  width: 420px;
  height: 420px;
}

.camera-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .72rem;
  color: rgba(220,240,245,.85);
  white-space: nowrap;
  pointer-events: none;
  font-family: var(--mono);
  background: rgba(0,0,0,.5);
  padding: 3px 12px;
  border-radius: 20px;
}

.camera-preview-panel {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  align-items: center;
  min-width: 170px;
}

.camera-preview-label {
  font-family: var(--display);
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
}

#cameraPreview {
  border-radius: 8px;
  border: 2px solid var(--line);
  background: #111;
  display: block;
}

.camera-face-controls {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  align-items: stretch;
  width: 100%;
}

.camera-face-controls label {
  font-weight: 600;
  font-family: var(--display);
  font-size: .82rem;
  color: var(--ink-soft);
}

.camera-face-controls select {
  font-family: var(--display);
  font-size: .88rem;
  padding: .4rem .7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f5fafb;
  cursor: pointer;
}

.captured-faces-status {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  justify-content: center;
}

.captured-face-badge {
  font-family: var(--mono);
  font-size: .78rem;
  font-weight: 700;
  padding: .22rem .6rem;
  border-radius: 20px;
  background: #e0f7e9;
  color: #1a7a45;
  border: 1px solid #88d4a8;
}

.captured-face-badge.pending {
  background: #f0f4f5;
  color: var(--ink-soft);
  border-color: var(--line);
}

@media (max-width: 520px) {
  #cameraCanvas { width: 290px; height: 290px; }
  .camera-hint { font-size: .65rem; }
}

/* ---- end Camera Editor ---- */

.viewer { display: none !important; }



@media (min-width: 861px) {
  .controls-top-row {
    grid-template-columns: 300px minmax(0, 900px);
    justify-content: center;
    gap: .9rem;
  }

  .face-editor-grid {
    gap: .6rem;
  }

  .face-card {
    padding: .55rem;
  }

  .face-grid {
    gap: .3rem;
  }
}
@media (max-width: 860px) {
  .controls-top-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .mobile-sticky-palette {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    top: env(safe-area-inset-top, 0px);
    z-index: 220;
    background: var(--card);
    padding: .45rem .75rem .4rem;
    border: 1px solid var(--line);
    border-radius: 0 0 16px 16px;
    box-shadow: 0 4px 14px rgba(20,44,54,.13);
    margin: 0 .5rem;
    transition: opacity .2s ease, visibility .2s ease;
  }

  .mobile-sticky-palette .palette-label {
    font-size: .82rem;
    font-weight: 700;
    color: var(--ink-soft);
    white-space: nowrap;
    margin-right: .2rem;
  }

  /* palette-wrap visible inside panel, above 2D/3D buttons — sticky banner handles scroll */
  .palette-wrap {
    display: block;
  }

  .controls-left {
    display: flex;
    flex-direction: column;
  }

  /* Compact chips in sticky banner: dot only, no text */
  .mobile-sticky-palette .color-chip span:last-child {
    display: none;
  }
  .mobile-sticky-palette .color-chip {
    padding: .25rem .35rem;
    gap: 0;
  }
  .mobile-sticky-palette .color-dot {
    width: 22px;
    height: 22px;
  }

  .app-shell { width: min(1160px, 100% - 1rem); margin-top: 1rem; }
  .cube-3d-viewer { height: 310px; }
  twisty-player.cube-3d-viewer { height: 310px; min-height: 260px; }

  .move-indicator {
    top: 10px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    gap: 8px;
    min-width: 176px;
    padding-right: 10px;
  }

  .move-face-badge { width: 36px; height: 36px; font-size: 1.18rem; }
  .move-dir-arrow { font-size: 1.6rem; }
  .move-text-wrap { min-width: 118px; }
  .move-desc-badge { font-size: .72rem; }
  .move-noob-hint { font-size: .64rem; max-width: 156px; }

  .twisty-fallback { min-height: 470px; }
  .twisty-fallback .iso-cube-svg { width: 340px; height: 306px; }

  .viewer-shell-nav { bottom: 10px; gap: .55rem; }
  .btn-shell-nav { min-width: 78px; padding: .38rem .72rem; font-size: .86rem; }

  .step-grid { grid-template-columns: repeat(auto-fill, minmax(152px, 1fr)); gap: .62rem; }
  .step-card { min-height: 188px; border-radius: 14px; padding: .56rem .48rem .48rem; }
  .step-card-title { font-size: 1.3rem; }
  .step-card-repeat { font-size: 1rem; border-radius: 6px; }
  .iso-cube-svg { width: 132px; height: 120px; }

  .face-editor-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .face-title {
    font-size: .86rem;
    gap: .3rem;
  }

  .face-title > span:first-child {
    white-space: nowrap;
  }

  .face-title-color {
    font-size: .62rem;
    padding: .08rem .32rem;
  }

  .palette-wrap {
    background: var(--card);
    padding: .45rem .5rem .4rem;
    margin: 0 0 .55rem;
    border-bottom: 1px solid var(--line);
  }

  .controls-top-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .controls-left {
    display: flex;
    flex-direction: column;
  }

  .controls-right {
    width: 100%;
  }

  .action-row {
    margin-top: .8rem;
    padding-top: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .55rem;
    align-items: stretch;
  }

  .action-row .btn {
    width: 100%;
    min-width: 0;
    flex: initial;
    padding: .5rem .35rem;
    font-size: .82rem;
    white-space: nowrap;
  }

  .action-row .status-inline {
    grid-column: 1 / -1;
    text-align: center;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
}











/* ---- Desktop layout: no outer box + left menu ---- */
@media (min-width: 861px) {
  .controls-panel {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .controls-top-row {
    grid-template-columns: 310px minmax(0, 860px);
    justify-content: center;
    align-items: stretch;
    gap: .85rem;
  }

  .controls-left {
    position: relative;
    top: auto;
    align-self: stretch;
    background: rgba(255,255,255,.72);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: .75rem;
    box-shadow: 0 6px 16px rgba(20,44,54,.08);
  }

  .controls-right {
    width: 100%;
    max-width: 860px;
  }

  .palette-wrap .palette {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .35rem;
  }

  .palette-wrap .color-chip {
    width: 100%;
    justify-content: center;
    padding-inline: .3rem;
  }

  .face-editor-grid {
    width: 100%;
    max-width: 860px;
    margin-inline: 0;
    gap: .45rem;
  }

  .face-card {
    padding: .45rem;
  }

  .face-title {
    margin-bottom: .38rem;
    font-size: .9rem;
  }

  .face-grid {
    gap: .24rem;
  }

  .action-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .45rem;
    align-items: stretch;
    margin-top: auto;
    padding-top: .6rem;
  }

  .action-row .btn {
    width: 100%;
    min-width: 0;
    flex: initial;
    padding: .5rem .35rem;
    font-size: .82rem;
    white-space: nowrap;
  }

  .action-row .status-inline {
    grid-column: 1 / -1;
  }
}

@media (min-width: 861px) and (max-height: 900px) {
  .controls-right,
  .face-editor-grid {
    max-width: 800px;
  }

  .face-card {
    padding: .4rem;
  }

  .face-title {
    margin-bottom: .32rem;
    font-size: .86rem;
  }

  .face-grid {
    gap: .2rem;
  }
}














