:root {
  --bg: #0a0d12;
  --panel: #141922;
  --panel-2: #1c2430;
  --ink: #f5f7fb;
  --muted: #9ba7b7;
  --line: #2b3442;
  --accent: #29d391;
  --accent-2: #5aa7ff;
  --danger: #ff6b6b;
  --warn: #f3c969;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(41, 211, 145, 0.09), transparent 360px),
    linear-gradient(135deg, rgba(90, 167, 255, 0.12), transparent 420px),
    var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 12px clamp(16px, 4vw, 56px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 13, 18, 0.88);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #07100c;
  background: linear-gradient(135deg, var(--accent), #e8fb76);
  font-weight: 900;
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(41, 211, 145, 0.22);
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.05;
}

.brand strong {
  font-size: 1.15rem;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions a {
  padding: 9px 10px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
}

.top-actions a:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}

.solver-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 18px;
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
}

.workbench,
.solve-card,
.notation-card {
  background: rgba(20, 25, 34, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.workbench {
  padding: clamp(16px, 2.4vw, 28px);
  min-width: 0;
}

.workbench-head,
.face-card-head,
.solve-head,
.library-band {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow,
.face-kicker {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.06;
}

h1 {
  font-size: clamp(2.15rem, 5vw, 5.4rem);
}

h2 {
  font-size: 1.26rem;
}

.size-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  min-width: 204px;
  padding: 4px;
  background: #0d1118;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.size-tab {
  min-height: 38px;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
}

.size-tab.is-active {
  color: #06100d;
  background: var(--accent);
  font-weight: 800;
}

.input-grid {
  display: grid;
  grid-template-columns: minmax(320px, 480px) minmax(320px, 1fr);
  gap: 18px;
  margin-top: 24px;
}

.face-panel,
.preview-panel,
.solve-panel {
  min-width: 0;
}

.face-order {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.face-order button {
  min-height: 44px;
  padding: 5px;
  color: var(--muted);
  background: #111722;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.face-order button.is-active {
  color: var(--ink);
  border-color: var(--accent);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.face-card {
  padding: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.face-count {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.cube-grid-wrap {
  display: grid;
  place-items: center;
  padding: 18px 0 4px;
}

.cube-grid {
  --n: 3;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  width: min(100%, 390px);
  aspect-ratio: 1;
  gap: clamp(4px, 0.9vw, 8px);
}

.sticker {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 7px;
  border: 2px solid rgba(0, 0, 0, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 8px 18px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}

.sticker:focus-visible,
.palette button:focus-visible,
.face-order button:focus-visible,
button:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(90, 167, 255, 0.72);
  outline-offset: 2px;
}

.sticker.is-fixed {
  cursor: not-allowed;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.sticker:disabled {
  opacity: 1;
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.palette button {
  min-height: 48px;
  border-radius: 8px;
  border: 2px solid transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
  cursor: pointer;
}

.palette button.is-active {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.face-actions,
.button-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.solve-btn {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.primary-btn,
.solve-btn {
  color: #07100c;
  background: var(--accent);
}

.secondary-btn {
  color: var(--ink);
  background: #243042;
  border: 1px solid #344255;
}

.ghost-btn {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

.preview-panel {
  display: grid;
  gap: 14px;
}

.cube-stage {
  min-height: 330px;
  background: radial-gradient(circle at 50% 18%, rgba(90, 167, 255, 0.16), transparent 54%), #101620;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

#cubeCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 330px;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.health-item {
  min-height: 70px;
  padding: 12px;
  background: #101620;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.health-item strong,
.health-item span {
  display: block;
}

.health-item strong {
  font-size: 1.25rem;
}

.health-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.health-item.is-ok {
  border-color: rgba(41, 211, 145, 0.48);
}

.health-item.is-warn {
  border-color: rgba(243, 201, 105, 0.58);
}

.solve-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  position: sticky;
  top: 90px;
}

.solve-card,
.notation-card {
  padding: 18px;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.field span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 98px;
  padding: 12px;
  color: var(--ink);
  background: #0e141d;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.button-row {
  flex-wrap: wrap;
}

.button-row button {
  flex: 1 1 120px;
}

.solve-btn {
  width: 100%;
  min-height: 50px;
  margin-top: 12px;
  font-size: 1rem;
}

.status-box {
  margin-top: 14px;
  padding: 12px;
  color: var(--muted);
  background: #0e141d;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.45;
}

.status-box.is-ok {
  color: #baf5dc;
  border-color: rgba(41, 211, 145, 0.42);
}

.status-box.is-warn {
  color: #ffe4a3;
  border-color: rgba(243, 201, 105, 0.52);
}

.status-box.is-bad {
  color: #ffc8c8;
  border-color: rgba(255, 107, 107, 0.5);
}

.status-box.is-work {
  color: #d9e8ff;
  border-color: rgba(90, 167, 255, 0.5);
}

.solution-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.solution-list li {
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 8px;
  background: #101620;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 900;
}

.notation-grid {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 8px 12px;
  margin-top: 14px;
}

.notation-grid span {
  display: grid;
  place-items: center;
  min-height: 34px;
  color: #07100c;
  background: var(--accent-2);
  border-radius: 6px;
  font-weight: 900;
}

.notation-grid p {
  margin: 0;
  align-self: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.library-band {
  width: min(1520px, calc(100% - clamp(32px, 6vw, 68px)));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.library-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  min-width: min(560px, 100%);
}

.library-list article {
  padding: 14px;
  background: #101620;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.library-list strong,
.library-list span {
  display: block;
}

.library-list span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

[data-color="U"] { background: #f8fafc; }
[data-color="R"] { background: #e63b3b; }
[data-color="F"] { background: #25c46f; }
[data-color="D"] { background: #ffd447; }
[data-color="L"] { background: #f58a2d; }
[data-color="B"] { background: #2f6dff; }

@media (max-width: 1180px) {
  .solver-layout,
  .input-grid {
    grid-template-columns: 1fr;
  }

  .solve-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .topbar,
  .workbench-head,
  .library-band {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: space-between;
  }

  .size-control {
    width: 100%;
  }

  .face-order {
    grid-template-columns: repeat(3, 1fr);
  }

  .health-grid,
  .library-list {
    grid-template-columns: 1fr;
  }

  .face-card-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 440px) {
  .solver-layout {
    padding: 12px;
  }

  h1 {
    font-size: 2.1rem;
  }

  .palette {
    grid-template-columns: repeat(3, 1fr);
  }

  .face-actions {
    flex-direction: column;
  }
}
