:root {
  --bg: #ffffff;
  --bg-subtle: #f7f7f8;
  --border: #d4d4d8;
  --border-light: #e4e4e7;
  --ink: #111113;
  --muted: #52525b;
  --danger: #b91c1c;

  --face-blue: #4a6cf7;
  --face-grey: #e3dede;
  --face-orange: #f59e0b;
  --face-red: #ef4444;
  --face-green: #16a34a;
  --face-yellow: #facc15;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--muted);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  max-width: 1020px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2.5rem;
}

/* Top Bar */
.top-bar {
  margin-bottom: 0.85rem;
}

.site-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Shared Solved Puzzle Section */
.solved-section {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.1rem;
  background: var(--bg);
}

.solved-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.solved-bar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.6rem;
}

.solved-bar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.9rem;
}

.section-heading {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.hex-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
}

.solved-editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(200px, 0.85fr);
  gap: 1.25rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
  align-items: center;
}

.solved-editor-grid[hidden] {
  display: none;
}

@media (max-width: 740px) {
  .solved-editor-grid {
    grid-template-columns: 1fr;
  }
}

.editor-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.solved-3d-host {
  display: flex;
  justify-content: center;
  align-items: center;
}

.setup-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  max-width: 280px;
}

/* Numbered Tabs */
.tab-bar {
  display: flex;
  gap: 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.15rem;
}

.tab-btn {
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  padding: 0.2rem 0.1rem 0.55rem;
  margin-bottom: -1px;
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.is-active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

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

/* Common Controls */
.mono-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

.btn-link {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-link:hover {
  color: var(--ink);
}

.btn-flat {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  border-radius: 3px;
  padding: 0.28rem 0.62rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-flat:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: #a1a1aa;
}

.btn-flat:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-ink {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #ffffff;
  border-radius: 3px;
  padding: 0.3rem 0.8rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-ink:hover:not(:disabled) {
  background: #27272a;
}

.flat-select {
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--ink);
  padding: 0.26rem 0.42rem;
  font: inherit;
  font-size: 0.82rem;
}

/* Hex Bar & Turn Bar */
.hex-bar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.hex-input {
  flex: 1;
  min-width: 0;
  padding: 0.28rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--bg);
}

.hex-input:focus {
  outline: 1px solid var(--ink);
  border-color: var(--ink);
}

.hex-input.is-invalid {
  border-color: var(--danger);
  outline-color: var(--danger);
  background: #fef2f2;
}

.turn-bar {
  display: flex;
  justify-content: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.turn-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  border-radius: 3px;
  width: 28px;
  height: 24px;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.turn-chip:hover:not(:disabled) {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.turn-chip:disabled {
  opacity: 0.26;
  cursor: not-allowed;
  text-decoration: line-through;
}

/* SVG Cube Net */
.net-host {
  display: flex;
  justify-content: center;
  user-select: none;
}

.cube-net-svg {
  width: 100%;
  max-width: 360px;
  height: auto;
  display: block;
}

.face-blue .face-bg { fill: var(--face-blue); }
.face-grey .face-bg { fill: var(--face-grey); }
.face-orange .face-bg { fill: var(--face-orange); }
.face-red .face-bg { fill: var(--face-red); }
.face-green .face-bg { fill: var(--face-green); }
.face-yellow .face-bg { fill: var(--face-yellow); }

.face-border {
  fill: none;
  stroke: #14161a;
  stroke-width: 1.75;
  pointer-events: none;
}

.bond-control {
  cursor: pointer;
  outline: none;
}

.bond-control:focus-visible .bond-hit,
.bond-control:focus-visible .center-hit {
  fill: rgba(255, 255, 255, 0.45);
  stroke: #111;
  stroke-width: 1.5;
}

.bond-line {
  stroke: #14161a;
  stroke-width: 1.75;
  stroke-linecap: butt;
}

.bond-hit {
  fill: transparent;
}

.seam-control.is-bonded .bond-line {
  opacity: 0;
}

.seam-control.is-hovered .bond-hit {
  fill: rgba(255, 255, 255, 0.35);
}

.seam-control.is-hovered .bond-line {
  stroke: #ffffff;
  stroke-width: 2.5;
  opacity: 1;
}

.seam-control.is-bonded.is-hovered .bond-line {
  stroke: #14161a;
  stroke-dasharray: 3 3;
  opacity: 0.75;
}

.center-hit {
  fill: transparent;
}

.center-control.is-hovered .center-hit {
  fill: rgba(255, 255, 255, 0.3);
}

.face-label {
  font-size: 11px;
  font-weight: 700;
  fill: rgba(17, 24, 39, 0.55);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.face-blue .face-label,
.face-green .face-label,
.face-red .face-label {
  fill: rgba(255, 255, 255, 0.8);
}

.center-control.is-bonded .face-label {
  opacity: 0.25;
}

.center-lock-mark {
  opacity: 0;
  pointer-events: none;
}

.center-lock-mark line {
  stroke: #111827;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.center-control.is-bonded .center-lock-mark {
  opacity: 1;
}

/* Tab 1: Restore Shape */
.restore-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 780px) {
  .restore-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.9rem 1rem;
  background: var(--bg);
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.panel-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.restore-result-panel {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.cube3d-box {
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  background: var(--bg-subtle);
}

.cube3d-canvas {
  width: 100%;
  height: 205px;
  display: block;
  cursor: grab;
  touch-action: none;
}

.cube3d-canvas.is-dragging,
.cube3d-mini-canvas.is-dragging {
  cursor: grabbing;
}

.cube3d-mini-canvas {
  display: block;
  box-sizing: content-box;
  padding: 10px 18px;
  cursor: grab;
  touch-action: none;
}

@media (max-width: 620px) {
  .cube3d-mini-canvas {
    padding: 14px 36px;
  }
}

.canvas-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.2rem;
}

.result-alg {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.02rem;
  font-weight: 700;
  word-break: break-word;
}

.move-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.move-token {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  border-radius: 3px;
  padding: 0.14rem 0.42rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.move-token.is-done {
  color: var(--muted);
  background: var(--bg-subtle);
}

.move-token.is-current {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.player-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.twizzle-link {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Tab 2: Solving Guide */
.guide-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.guide-status-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.guide-preview-note {
  font-size: 0.78rem;
  color: var(--muted);
}

.guide-actions {
  display: flex;
  gap: 0.4rem;
}

.stages-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.stage-section {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.stage-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.stage-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.55rem;
}

.stage-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.stage-order-controls {
  display: inline-flex;
  gap: 0.25rem;
}

.order-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  border-radius: 3px;
  width: 24px;
  height: 22px;
  padding: 0;
  font-size: 0.78rem;
  cursor: pointer;
}

.order-btn:hover:not(:disabled) {
  border-color: var(--ink);
}

.order-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.stage-note {
  margin: 0 0 0.6rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.guide-alg-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border-light);
}

.guide-alg-item {
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr);
  gap: 1rem;
  padding: 0.75rem 0.15rem;
  border-bottom: 1px solid var(--border-light);
  align-items: center;
}

@media (max-width: 620px) {
  .guide-alg-item {
    grid-template-columns: 1fr;
  }
}

.alg-3d-col {
  display: flex;
  justify-content: center;
  align-items: center;
}

.alg-info-col {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.alg-headline-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.alg-headline {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--ink);
}

.alg-role-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.76rem;
  color: var(--muted);
}

.alg-expr {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  word-break: break-word;
  padding: 0.25rem 0;
}

.alg-side-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.alg-actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.alg-raw-box {
  margin-top: 0.2rem;
  padding: 0.4rem 0.55rem;
  border-left: 2px solid var(--border);
  background: var(--bg-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  color: var(--ink);
  word-break: break-word;
}

.alg-raw-box[hidden] {
  display: none;
}

.stage-more-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.65rem;
}

.stage-more-row .btn-flat {
  font-size: 0.8rem;
  padding: 0.28rem 0.65rem;
}

/* Footer */
.site-footer {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.84rem;
}

@media (max-width: 600px) {
  .site-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

.footer-key-img {
  display: block;
  width: 118px;
  height: auto;
}

.footer-text p {
  margin: 0 0 0.3rem;
}

.footer-text p:last-child {
  margin-bottom: 0;
}
