/* =========================================================
   CubeLab — Light Precision Puzzle Studio
   Signature: cool mist canvas + soft color chips + mono notation
   ========================================================= */

:root {
  /* Surfaces */
  --bg: #F4F7FB;
  --bg-elevated: #FFFFFF;
  --bg-soft: #EAF0F8;
  --bg-wash: #DDE7F4;
  --ink: #152033;
  --ink-soft: #4A5A72;
  --ink-faint: #8A9BB2;
  --line: rgba(21, 32, 51, 0.08);
  --line-strong: rgba(21, 32, 51, 0.14);

  /* Brand */
  --blue: #4C6FFF;
  --blue-deep: #3352E0;
  --blue-soft: #E8EEFF;
  --coral: #FF6B4A;
  --mint: #1FB8A0;
  --gold: #E8A317;
  --violet: #7B6CFF;

  /* Cube face refs (UI chips) */
  --face-u: #F7F7F7;
  --face-d: #F5D547;
  --face-f: #3DBE6A;
  --face-b: #3B82F6;
  --face-r: #EF4444;
  --face-l: #F97316;

  /* Type */
  --font-display: "Syne", system-ui, sans-serif;
  --font-body: "Figtree", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  /* Space & shape */
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(21, 32, 51, 0.04), 0 4px 12px rgba(21, 32, 51, 0.04);
  --shadow: 0 4px 6px rgba(21, 32, 51, 0.03), 0 12px 32px rgba(21, 32, 51, 0.06);
  --shadow-lg: 0 8px 16px rgba(21, 32, 51, 0.04), 0 24px 48px rgba(76, 111, 255, 0.08);
  --panel-w: clamp(220px, 22vw, 280px);
  --topbar-h: 56px;
  --footer-h: 0px;
  --page-pad: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(76, 111, 255, 0.09), transparent 55%),
    radial-gradient(ellipse 40% 30% at 100% 80%, rgba(255, 107, 74, 0.05), transparent 50%),
    radial-gradient(ellipse 35% 25% at 0% 60%, rgba(31, 184, 160, 0.05), transparent 50%);
  background-attachment: fixed;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
code, kbd {
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
}
.skip-link:focus { left: 12px; }

/* ---------- Shell (single viewport page) ---------- */
.app-shell {
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
}
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(76, 111, 255, 0.28);
  display: block;
}

/* legacy grid mark kept unused; logo uses assets/logo.svg */

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-text strong {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand-text span {
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.order-nav {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
  padding: 4px;
  background: var(--bg-soft);
  border-radius: 14px;
  max-width: 520px;
  margin: 0 auto;
}

.order-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 8px 12px;
  border-radius: 11px;
  color: var(--ink-soft);
  transition: background 0.2s var(--ease), color 0.2s, box-shadow 0.2s;
}
.order-btn em {
  font-style: normal;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}
.order-btn span {
  font-size: 0.68rem;
  font-weight: 500;
  opacity: 0.85;
}
.order-btn:hover { color: var(--ink); background: rgba(255,255,255,0.6); }
.order-btn.is-active {
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.order-btn.is-active em { color: var(--blue); }

.topbar-actions {
  min-width: 100px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  font-weight: 500;
  font-size: 0.88rem;
  transition: border-color 0.15s, color 0.15s, background 0.15s, box-shadow 0.15s;
}
.ghost-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.ghost-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ghost-btn.primary-ghost {
  border-color: rgba(76, 111, 255, 0.25);
  color: var(--blue);
  background: var(--blue-soft);
}
.ghost-btn.primary-ghost:hover:not(:disabled) {
  background: #dce5ff;
  border-color: rgba(76, 111, 255, 0.4);
}

/* Install to home screen */
.install-btn {
  border-color: rgba(76, 111, 255, 0.28);
  color: var(--blue-deep);
  background: var(--blue-soft);
  font-weight: 600;
}
.install-btn:hover {
  background: #dce5ff;
  border-color: rgba(76, 111, 255, 0.45);
  color: var(--blue-deep);
  box-shadow: 0 2px 10px rgba(76, 111, 255, 0.15);
}
.install-btn.is-available {
  animation: install-pulse 2.4s ease-in-out infinite;
}
.install-btn.is-installed {
  background: #eefaf6;
  border-color: rgba(31, 184, 160, 0.35);
  color: #0f8a76;
  animation: none;
}
@keyframes install-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(76, 111, 255, 0); }
  50% { box-shadow: 0 0 0 4px rgba(76, 111, 255, 0.12); }
}

.install-guide h3 {
  margin: 14px 0 8px;
  font-size: 0.9rem;
  font-family: var(--font-display);
}
.install-guide h3:first-of-type { margin-top: 4px; }
.install-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  margin-bottom: 8px;
}
.install-hero img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(76, 111, 255, 0.25);
  flex-shrink: 0;
}
.install-hero strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1rem;
  margin-bottom: 4px;
}
.install-hero p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.45;
}
.install-steps {
  margin: 0;
  padding-left: 1.25em;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.65;
}
.install-steps li { margin-bottom: 6px; }
.ios-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6em;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--line-strong);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--blue);
}

/* ---------- Workspace ---------- */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr) var(--panel-w);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--page-pad);
  padding: var(--page-pad);
  width: 100%;
  max-width: 1800px;
  margin: 0 auto;
  overflow: hidden;
}

/* ---------- Panels ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}

.card-head {
  margin-bottom: 12px;
}
.card-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.card-sub {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-weight: 600;
  font-size: 0.78rem;
  transition: transform 0.15s var(--ease), border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.action-btn:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: #fff;
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.action-btn:active:not(:disabled) { transform: translateY(0); }
.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.action-btn.primary {
  background: linear-gradient(165deg, #5B7CFF 0%, var(--blue) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(76, 111, 255, 0.28);
}
.action-btn.primary:hover:not(:disabled) {
  background: linear-gradient(165deg, #6B88FF 0%, var(--blue-deep) 100%);
  border-color: transparent;
}
.action-btn.action-solve {
  background: linear-gradient(165deg, #34d2b8 0%, var(--mint) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(31, 184, 160, 0.28);
}
.action-btn.action-solve:hover:not(:disabled) {
  filter: brightness(1.05);
  border-color: transparent;
}
.action-btn.action-solve.is-running {
  background: linear-gradient(165deg, #f0b429 0%, var(--gold) 100%);
  box-shadow: 0 4px 12px rgba(232, 163, 23, 0.28);
}
.action-btn.full {
  flex-direction: row;
  justify-content: center;
  width: 100%;
  margin-top: 12px;
  padding: 12px;
}
.action-ico { font-size: 1.1rem; line-height: 1; }

/* Persistent hint panel */
.hint-panel {
  margin-top: 12px;
  border-radius: 12px;
  border: 1px solid rgba(232, 163, 23, 0.35);
  background: linear-gradient(165deg, #FFFBF0 0%, #FFF6E0 100%);
  padding: 12px;
  animation: hint-in 0.25s var(--ease);
}
@keyframes hint-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.hint-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.hint-panel-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #8a5a10;
}
.hint-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
  color: #8a5a10;
  background: transparent;
}
.hint-close:hover { background: rgba(0,0,0,0.06); }
.hint-panel-body {
  margin: 0 0 8px;
  font-size: 0.85rem;
  line-height: 1.55;
  color: #5c4318;
}
.hint-panel-algo {
  display: block;
  margin: 0 0 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--ink);
  color: #f5e6c8;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  word-break: break-all;
}
.hint-panel-actions {
  display: flex;
  gap: 8px;
}

/* Auto-solve progress */
.solve-progress {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.solve-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(21, 32, 51, 0.08);
  overflow: hidden;
  margin-bottom: 8px;
}
.solve-progress-bar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), #4C6FFF);
  transition: width 0.25s var(--ease);
}
.solve-progress-text {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  font-family: var(--font-mono);
}

/* Play tip */
.play-tip {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink-soft);
  background: linear-gradient(135deg, #EEF2FF, #F0FDFA);
  border: 1px solid rgba(76, 111, 255, 0.15);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.play-tip strong { color: var(--ink); }
.tip-keys {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
}

/* Turn direction */
.turn-dir {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}
.dir-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  transition: all 0.15s;
}
.dir-btn .dir-ico {
  font-size: 1.15rem;
  line-height: 1;
  color: var(--ink);
}
.dir-btn:hover { border-color: var(--line-strong); background: #fff; }
.dir-btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.dir-btn.is-active .dir-ico { color: #fff; }

/* Layer picker */
.layer-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.layer-chip {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  transition: all 0.15s;
}
.layer-chip.is-active {
  background: var(--blue-soft);
  border-color: rgba(76, 111, 255, 0.35);
  color: var(--blue-deep);
}
.layer-chip:hover:not(.is-active) { border-color: var(--line-strong); color: var(--ink); }

/* Cube net (cross unfold) */
.cube-net {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}
.net-cell.net-empty {
  visibility: hidden;
  pointer-events: none;
  min-height: 0;
}
.net-face {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 10px;
  border: 2px solid rgba(0,0,0,0.08);
  background: var(--fc, #ccc);
  color: var(--ft, #fff);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 2px 6px rgba(21,32,51,0.08);
  transition: transform 0.12s var(--ease), box-shadow 0.12s, border-color 0.12s;
  min-height: 52px;
}
.net-face em {
  font-style: normal;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1;
}
.net-face span {
  font-size: 0.58rem;
  font-weight: 700;
  opacity: 0.9;
  letter-spacing: 0.02em;
}
.net-face:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 6px 14px rgba(21,32,51,0.14);
  border-color: rgba(0,0,0,0.18);
}
.net-face:active { transform: scale(0.96); }
.net-face.is-flash {
  outline: 3px solid var(--blue);
  outline-offset: 1px;
}

.net-legend {
  margin: 0;
  font-size: 0.7rem;
  color: var(--ink-faint);
  line-height: 1.4;
}

.slider-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.speed-hint {
  margin: 0 0 12px;
  font-size: 0.7rem;
  color: var(--ink-faint);
  font-weight: 500;
}
.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}
.slider-val {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
  min-width: 48px;
  text-align: right;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.switch {
  position: relative;
  width: 40px;
  height: 22px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-ui {
  position: absolute;
  inset: 0;
  background: var(--bg-wash);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}
.switch-ui::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform 0.2s var(--ease);
}
.switch input:checked + .switch-ui { background: var(--blue); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }

.text-btn {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--blue);
  padding: 4px 0;
}
.text-btn:hover { text-decoration: underline; }

.card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 12px;
}
.stat {
  text-align: center;
  min-width: 0;
}
.stat-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.stat strong {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-ok { color: var(--mint) !important; }
.status-busy { color: var(--gold) !important; }
.status-scrambled { color: var(--coral) !important; }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.9) 0%, rgba(244,247,251,0.95) 100%);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  height: 100%;
}

.stage-halo {
  position: absolute;
  width: 70%;
  height: 55%;
  left: 15%;
  top: 12%;
  background: radial-gradient(ellipse, rgba(76, 111, 255, 0.12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.stage-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(21, 32, 51, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 32, 51, 0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse 70% 65% at 50% 42%, black 20%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

.canvas-host {
  flex: 1 1 auto;
  position: relative;
  z-index: 1;
  min-height: 0;
  height: 100%;
  touch-action: none;
  display: block;
}
.canvas-host canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-height: 0;
  outline: none;
  position: absolute;
  inset: 0;
}

.stage-caption {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  padding: 8px 12px 6px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.eyebrow {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 3px;
}

.scramble-line code,
.history-line code {
  display: block;
  padding: 6px 8px;
  background: var(--bg-soft);
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.4;
  word-break: break-all;
  max-height: 2.8em;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.history-line code.is-solving {
  border: 1px solid rgba(31, 184, 160, 0.35);
  background: #f0faf7;
}

.stage-hint {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 4px 10px 8px;
}
.hint-pill {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
}

.face-hover-tag {
  position: absolute;
  z-index: 5;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  background: rgba(21, 32, 51, 0.88);
  backdrop-filter: blur(8px);
  pointer-events: none;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.face-hover-tag .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border: 1px solid rgba(255,255,255,0.4);
}

/* ---------- Right teaching panel ---------- */
.panel-right {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.teach-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  padding: 6px;
  gap: 4px;
}
.tab {
  flex: 1;
  padding: 9px 8px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--ink-soft);
  transition: all 0.15s;
}
.tab:hover { color: var(--ink); background: rgba(255,255,255,0.7); }
.tab.is-active {
  background: #fff;
  color: var(--blue);
  box-shadow: var(--shadow-sm);
}

.tab-panels {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.tab-panel[hidden] { display: none !important; }

.lesson h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.lesson .lesson-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue-deep);
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 12px;
}
.lesson p {
  margin: 0 0 12px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.65;
}
.lesson ul {
  margin: 0 0 12px;
  padding-left: 1.15em;
  color: var(--ink-soft);
  font-size: 0.88rem;
}
.lesson li { margin-bottom: 6px; }
.lesson .algo {
  display: block;
  margin: 12px 0;
  padding: 12px 14px;
  background: var(--ink);
  color: #E8EEFF;
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.5;
  word-break: break-word;
}
.lesson .tip {
  padding: 10px 12px;
  background: #FFF8EB;
  border: 1px solid rgba(232, 163, 23, 0.25);
  border-radius: 10px;
  font-size: 0.82rem;
  color: #7A5A10;
  margin-top: 8px;
}

.lesson-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.lesson-progress {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-faint);
  font-weight: 500;
}

/* Notation */
.notation-guide h4 {
  margin: 16px 0 8px;
  font-size: 0.85rem;
  font-family: var(--font-display);
}
.notation-guide h4:first-child { margin-top: 0; }
.face-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.face-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 0.82rem;
}
.face-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}
.face-item strong {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin-right: 4px;
}
.notation-note {
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* Formulas */
.formula-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  margin-bottom: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.formula-card:hover {
  border-color: rgba(76, 111, 255, 0.25);
  box-shadow: var(--shadow-sm);
}
.formula-card h4 {
  margin: 0 0 4px;
  font-size: 0.88rem;
  font-weight: 700;
}
.formula-card p {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--ink-faint);
}
.formula-card code {
  display: block;
  padding: 8px 10px;
  background: var(--ink);
  color: #E0E8FF;
  border-radius: 8px;
  font-size: 0.8rem;
  margin-bottom: 8px;
  word-break: break-all;
}
.formula-card button {
  width: 100%;
  padding: 7px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue-deep);
  font-weight: 600;
  font-size: 0.78rem;
}
.formula-card button:hover { background: #dce5ff; }

/* ---------- Footer (hidden to keep single-screen app) ---------- */
.footer {
  display: none;
}
.footer p { margin: 0; }

/* ---------- Modal ---------- */
.modal {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
  background: var(--bg-elevated);
}
.modal::backdrop {
  background: rgba(21, 32, 51, 0.35);
  backdrop-filter: blur(4px);
}
.modal-card { margin: 0; }
.modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
}
.icon-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-soft);
}
.icon-close:hover { background: var(--bg-soft); color: var(--ink); }
.modal-body { padding: 18px; }
.hotkey-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.hotkey-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--ink-soft);
}
.hotkey-list li:last-child { border-bottom: none; }
kbd {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 1px 0 var(--line-strong);
}
.modal-note {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--ink-faint);
  line-height: 1.5;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease);
  z-index: 100;
  max-width: min(90vw, 360px);
  text-align: center;
}
.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Focus ---------- */
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- Responsive: single-screen + iPad landscape / portrait ---------- */

/* Large tablet / small desktop: slightly narrower side panels */
@media (max-width: 1200px) {
  :root {
    --panel-w: clamp(200px, 24vw, 260px);
    --page-pad: 8px;
    --topbar-h: 52px;
  }
}

/*
 * iPad landscape & medium landscape tablets
 * Keep 3-column single-page app layout
 */
@media (orientation: landscape) and (max-height: 900px) {
  :root {
    --topbar-h: 48px;
    --page-pad: 8px;
    --panel-w: clamp(190px, 22vw, 250px);
  }
  html, body { font-size: 13px; }
  .card { padding: 10px; }
  .card-head { margin-bottom: 8px; }
  .action-btn { padding: 8px 4px; font-size: 0.72rem; }
  .play-tip { padding: 8px 10px; margin-bottom: 8px; font-size: 0.72rem; }
  .net-face { min-height: 42px; }
  .stage-hint { display: none; }
  .brand-text span { display: none; }
  .order-btn span { display: none; }
  .order-btn { padding: 6px 8px; }
}

/* Short landscape (iPad landscape ~768–820 tall) */
@media (orientation: landscape) and (max-height: 820px) {
  :root {
    --topbar-h: 44px;
    --page-pad: 6px;
  }
  .hint-panel { padding: 8px; }
  .cube-net { gap: 4px; }
  .net-legend { display: none; }
  .card-stats { padding: 10px 8px; }
  .stage-caption { padding: 6px 10px 4px; }
  .scramble-line code,
  .history-line code { max-height: 2.2em; font-size: 0.68rem; }
}

/*
 * iPad / tablet portrait: stage on top, controls + tutorial below
 * Still fits in one viewport with internal scroll only in panels
 */
@media (orientation: portrait) and (max-width: 1100px) {
  :root {
    --topbar-h: 52px;
    --page-pad: 8px;
  }
  .workspace {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1.15fr) minmax(0, 0.85fr);
    grid-template-areas:
      "stage stage"
      "left right";
  }
  .stage { grid-area: stage; }
  .panel-left { grid-area: left; }
  .panel-right { grid-area: right; }
  .order-btn span { display: none; }
}

/* Narrow phones / small portrait */
@media (max-width: 760px) {
  :root {
    --topbar-h: auto;
    --page-pad: 6px;
  }
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 44px;
    padding: 6px 8px;
    gap: 6px;
  }
  .brand { min-width: auto; }
  .brand-text span { display: none; }
  .order-nav {
    order: 3;
    width: 100%;
    max-width: none;
  }
  .order-btn span { display: none; }
  .order-btn { padding: 6px 4px; }
  .topbar-actions { margin-left: auto; }
  .ghost-btn span { display: none; }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1.2fr) minmax(0, 0.9fr) minmax(0, 0.85fr);
    grid-template-areas:
      "stage"
      "left"
      "right";
  }
  .stage { grid-area: stage; min-height: 0; }
  .panel-left {
    grid-area: left;
    display: flex;
    flex-direction: column;
  }
  .panel-right { grid-area: right; }
  .stage-hint { display: none; }
}

/* Very short phones landscape */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --topbar-h: 40px; --page-pad: 4px; }
  .workspace {
    grid-template-columns: minmax(160px, 28vw) 1fr minmax(160px, 28vw);
  }
  .brand-text { display: none; }
  .play-tip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .scramble-line code,
  .history-line code { scroll-behavior: auto; }
}
