:root {
  --bg: #0d0f14;
  --bg2: #141821;
  --panel: #181d28;
  --panel-2: #1f2533;
  --line: #2a3142;
  --text: #eef1f7;
  --muted: #98a2b8;
  --accent: #ffcf33;
  --accent-2: #ff8a3d;
  --good: #3ddc84;
  --bad: #ff4d6d;
  --radius: 16px;
  --c-yellow: #ffd500;
  --c-green: #22c46b;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #22283a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin: 0 0 .4em; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; margin: 0 0 .4em; }
[hidden] { display: none !important; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.tiny { font-size: .78rem; }
.center { text-align: center; }
.error { color: var(--bad); font-weight: 600; margin: .6em 0; }
.c-yellow { color: var(--c-yellow); }
.c-green { color: var(--c-green); }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 10px; }
.spacer { flex: 1; }
.center-row { justify-content: center; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
  background: rgba(13, 15, 20, .7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; font-size: 1.15rem; display: flex; align-items: center; gap: 10px; letter-spacing: -0.01em; }
.brand-cube {
  width: 22px; height: 22px; border-radius: 5px;
  background: conic-gradient(#ffd500 0 25%, #00a651 0 50%, #ff6a00 0 75%, #0a4fd6 0);
  box-shadow: 0 0 0 2px #000 inset;
}
.player-chip { display: flex; align-items: center; gap: 10px; background: var(--panel); padding: 5px 12px 5px 5px; border-radius: 999px; border: 1px solid var(--line); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; color: #1a1300; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  flex: none;
}

/* ---------------------------------------------------------------- layout */
main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.screen-center { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.hero { max-width: 560px; width: 100%; text-align: center; padding: 36px; }
.section-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 28px 0 10px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px 18px; border-radius: 12px; font: inherit; font-weight: 650; cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: #3b4560; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a1300; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 26px; font-size: 1.05rem; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(20, 24, 33, .85); color: var(--text); font-size: 1.05rem; cursor: pointer;
}
.icon-btn:hover { border-color: #3b4560; }

/* ---------------------------------------------------------------- profile */
.profile-form { display: flex; gap: 10px; margin-top: 22px; }
.profile-form input {
  flex: 1; min-width: 0; padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); font: inherit; font-size: 1.05rem;
}
.profile-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.profile-list { display: grid; gap: 10px; }
.profile-card {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  color: var(--text); font: inherit; cursor: pointer;
}
.profile-card:hover { border-color: var(--accent); }
.profile-card .pc-main { flex: 1; min-width: 0; }
.profile-card .pc-name { font-weight: 700; }
.profile-card .pc-del { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.profile-card .pc-del:hover { color: var(--bad); background: rgba(255, 77, 109, .1); }

/* ---------------------------------------------------------------- setup */
.setup-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.hold-tip { display: flex; gap: 12px; align-items: flex-start; background: var(--panel-2); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.tip-icon { font-size: 1.3rem; }
.tabs { display: flex; gap: 6px; background: var(--bg2); padding: 5px; border-radius: 12px; margin-bottom: 14px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px; border-radius: 9px; font: inherit; font-weight: 650; cursor: pointer; }
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }
.tab-body { display: grid; gap: 12px; }
.palette { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px 6px 6px; border-radius: 10px;
  border: 2px solid transparent; background: var(--panel-2); color: var(--text); font: inherit; font-size: .85rem; cursor: pointer;
}
.swatch .dot { width: 24px; height: 24px; border-radius: 6px; box-shadow: 0 0 0 1px rgba(0,0,0,.4) inset; }
.swatch.active { border-color: var(--accent); }
.swatch .count.full { color: var(--good); }
.swatch .count.over { color: var(--bad); }
.net-wrap { overflow-x: auto; }
.net { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; max-width: 540px; margin: 4px auto; }
.sticker {
  aspect-ratio: 1; border-radius: 5px; border: 0; cursor: pointer; padding: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,.5) inset; transition: transform .08s;
}
.sticker:hover { transform: scale(1.08); }
.sticker.center { cursor: default; box-shadow: 0 0 0 2px rgba(0,0,0,.6) inset; }
.sticker.center::after { content: attr(data-face); font-size: .7rem; font-weight: 800; color: rgba(0,0,0,.55); }
.sticker.unpainted { background: #3a404f; }
.sticker.bad { animation: blink .7s steps(2) infinite; }
@keyframes blink { 50% { box-shadow: 0 0 0 3px var(--bad) inset; } }
.notation { margin-top: 18px; background: var(--bg2); border-radius: 12px; padding: 10px 14px; }
.notation summary { cursor: pointer; font-weight: 650; }
.notation ul { margin: 10px 0 4px; padding-left: 20px; }
.view-panel { position: relative; padding: 10px; }
.cube-view { width: 100%; aspect-ratio: 1; min-height: 280px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #252c3d, #11141b 70%); overflow: hidden; }
.cube-view canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: ui-monospace, "SF Mono", Consolas, monospace; font-weight: 700; font-size: .95rem;
  padding: 5px 10px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line);
  min-width: 40px; text-align: center; transition: background .15s, color .15s, transform .15s, opacity .15s;
}
.chips.big .chip { font-size: 1.1rem; padding: 7px 12px; }
.chip.done { opacity: .45; }
.chip.now { background: var(--accent); color: #1a1300; border-color: var(--accent); transform: scale(1.12); }

/* ---------------------------------------------------------------- method */
.method-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 24px; }
.method-card { display: flex; flex-direction: column; gap: 12px; position: relative; overflow: hidden; }
.method-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--level-color); }
.level { display: inline-block; font-weight: 800; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--level-color); }
.method-card .big-num { font-size: 3rem; font-weight: 850; line-height: 1; letter-spacing: -0.03em; }
.method-card .big-num small { font-size: 1rem; font-weight: 600; color: var(--muted); margin-left: 6px; }
.method-card ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; color: var(--muted); font-size: .9rem; }
.method-card ul b { color: var(--text); }
.method-card .btn { margin-top: auto; }
.tag { position: absolute; top: 14px; right: 14px; font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.card-loading { display: flex; align-items: center; gap: 12px; color: var(--muted); min-height: 3rem; }

/* ---------------------------------------------------------------- solve */
.solve-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 20px; align-items: start; }
.solve-view-panel { position: sticky; top: 84px; }
.cube-view.big { aspect-ratio: auto; height: min(72vh, 680px); }
.view-controls { position: absolute; left: 20px; right: 20px; bottom: 20px; display: flex; align-items: center; gap: 8px; }
.speed { margin-left: auto; display: flex; align-items: center; gap: 8px; background: rgba(20,24,33,.85); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; font-size: .85rem; color: var(--muted); }
.speed input { width: 110px; accent-color: var(--accent); }
.ready-overlay { position: absolute; inset: 10px; border-radius: 12px; display: grid; place-items: center; background: rgba(8, 10, 14, .72); backdrop-filter: blur(3px); }
.ready-card { max-width: 420px; text-align: center; padding: 20px; }
.ready-card h2 { font-size: 1.8rem; }
.solve-side { display: grid; gap: 14px; }
.metrics-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.metrics-head .avatar { width: 42px; height: 42px; font-size: 1.2rem; }
.m-name { font-weight: 800; font-size: 1.1rem; }
.m-timer { margin-left: auto; font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.progress { height: 10px; background: var(--bg2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .4s ease; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--panel-2); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; align-items: center; }
.stat-v { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; text-align: center; }
.phases { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.phase { font-size: .78rem; padding: 3px 9px; border-radius: 999px; background: var(--bg2); color: var(--muted); border: 1px solid transparent; }
.phase.done { color: var(--good); }
.phase.done::before { content: "✓ "; }
.phase.now { color: var(--text); border-color: var(--accent); }
.step-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.phase-chip { font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.step-lines { margin: 0 0 14px; padding-left: 18px; color: #cdd3e1; }
.step-lines li { margin: 3px 0; }
.nav { margin-top: 16px; }
.quit { color: var(--muted); justify-self: center; font-size: .85rem; }

/* ---------------------------------------------------------------- finish */
.finish-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(40, 32, 8, .82), rgba(5, 6, 9, .93));
  animation: fade .4s ease;
}
.finish-inner { text-align: center; padding: 24px; }
.finish-title {
  font-size: clamp(4.5rem, 19vw, 13rem); font-weight: 900; line-height: .9; margin: 0; letter-spacing: -0.04em;
  background: linear-gradient(135deg, #fff6c2, var(--accent) 35%, var(--accent-2) 70%, #ff4d6d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 10px 40px rgba(255, 170, 40, .35));
  animation: pop .7s cubic-bezier(.2, 1.6, .4, 1) both;
}
.finish-sub { font-size: 1.25rem; color: #e9dcb8; margin: 10px 0 18px; }
.badge { display: inline-block; font-weight: 800; padding: 6px 14px; border-radius: 999px; background: var(--good); color: #062612; margin-bottom: 18px; animation: pop .6s .3s cubic-bezier(.2, 1.6, .4, 1) both; }
.finish-stats { display: grid; grid-template-columns: repeat(4, minmax(90px, 140px)); gap: 10px; justify-content: center; margin: 8px 0 26px; }
.finish-stats .stat { background: rgba(255, 255, 255, .06); }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 980px) {
  .setup-grid, .solve-grid { grid-template-columns: minmax(0, 1fr); }
  .solve-view-panel { position: relative; top: 0; }
  .cube-view.big { height: 48vh; }
  .solve-side .step-card { order: -1; } /* what to do next comes before the stats */
  .method-cards { grid-template-columns: minmax(0, 1fr); }
  .setup-grid .view-panel { order: -1; }
  .setup-grid .cube-view { max-height: 45vh; aspect-ratio: auto; height: 45vh; }
}
@media (max-width: 560px) {
  main { padding: 14px; }
  .profile-form { flex-direction: column; }
  .finish-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .speed input { width: 70px; }
}
