/* Rubik's cube simulator - UI styles */
:root {
  --bg0: #070b16;
  --bg1: #101a33;
  --panel: rgba(14, 20, 38, 0.78);
  --panel-solid: #0f172a;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.32);
  --text: #e6ebf5;
  --muted: #93a0b8;
  --accent: #4f8cff;
  --accent-2: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #d97706;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 800px at 50% 40%, #1a2850 0%, var(--bg1) 35%, var(--bg0) 100%);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; cursor: grab; }
#scene.dragging { cursor: grabbing; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- top bar ---------- */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 60px;
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: linear-gradient(to bottom, rgba(7, 11, 22, 0.85), rgba(7, 11, 22, 0));
  z-index: 20; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { display: grid; grid-template-columns: repeat(3, 8px); gap: 2px; padding: 3px; background: #0a0a0a; border-radius: 5px; }
.logo i { width: 8px; height: 8px; border-radius: 2px; background: #fff; }
.logo i:nth-child(1), .logo i:nth-child(8) { background: #c41e3a; }
.logo i:nth-child(3), .logo i:nth-child(7) { background: #009e60; }
.logo i:nth-child(4) { background: #ffd500; }
.logo i:nth-child(5) { background: #0051ba; }
.logo i:nth-child(6) { background: #ff5800; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 16px; letter-spacing: 0.2px; }
.brand-text small { color: var(--muted); font-size: 12px; }
.player { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.player label { color: var(--muted); font-size: 13px; }
.player input {
  width: 170px; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: rgba(15, 23, 42, 0.8); outline: none;
}
.player input:focus { border-color: var(--accent); }
.player input.missing { border-color: var(--warn); box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25); }
.top-actions { display: flex; gap: 6px; }
.lang-btn {
  height: 34px; min-width: 40px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: rgba(15, 23, 42, 0.8); cursor: pointer; font-size: 12px; font-weight: 700; letter-spacing: 0.5px;
}

/* ---------- buttons ---------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: rgba(15, 23, 42, 0.8); cursor: pointer; transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: rgba(51, 65, 85, 0.8); }
.icon-btn.small { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn.small svg { width: 15px; height: 15px; }
.icon-btn:disabled { opacity: .4; cursor: default; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  flex: 1; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--line-strong);
  background: rgba(30, 41, 59, 0.85); cursor: pointer; font-size: 14px; font-weight: 600;
  transition: transform .08s, background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: rgba(51, 65, 85, 0.95); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: linear-gradient(180deg, #5b95ff, #3b72e6); border-color: #6aa0ff; color: #fff; }
.btn.primary:hover { background: linear-gradient(180deg, #6ea2ff, #4a7ff0); }
.btn.accent { background: linear-gradient(180deg, #2fcf6a, #18a34a); border-color: #3ddc79; color: #04210f; }
.btn.accent:hover { background: linear-gradient(180deg, #45dc7c, #1fb455); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- panels ---------- */
.panel {
  position: absolute; top: 70px; width: 300px; max-height: calc(100% - 86px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
  z-index: 15; scrollbar-width: thin;
}
.panel.left { left: 16px; }
.panel.right { right: 16px; width: 290px; }
.panel section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h2 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted); font-weight: 700; }
.hint { margin: 8px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--muted); }

.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.chip {
  padding: 7px 0; border-radius: 9px; border: 1px solid var(--line-strong); background: rgba(30, 41, 59, 0.7);
  cursor: pointer; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:disabled { opacity: .4; cursor: default; }

.segmented { display: flex; padding: 3px; gap: 3px; border-radius: 11px; background: rgba(2, 6, 23, 0.6); border: 1px solid var(--line); }
.segmented button { flex: 1; padding: 8px 6px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--muted); }
.segmented button.active { background: rgba(79, 140, 255, 0.18); color: #fff; box-shadow: inset 0 0 0 1px rgba(79, 140, 255, 0.55); }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.field select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: rgba(2, 6, 23, 0.6); color: var(--text); outline: none;
}
.field select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: var(--mono); font-size: 12.5px; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); }
.advanced { margin-top: 10px; }
.advanced summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.scramble-text { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-word; margin: 10px 0 0; max-height: 90px; overflow: auto; }

.speed-row { display: flex; align-items: center; gap: 8px; }
.speed-row input[type=range] { flex: 1; accent-color: var(--accent); }
.speed-row output { min-width: 54px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  text-align: center; z-index: 10; pointer-events: none; text-shadow: 0 2px 12px rgba(0, 0, 0, .6);
}
.hud-time { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.hud-sub { font-size: 13px; color: var(--muted); }
.hud-sub .dot { margin: 0 6px; }
.hud.running .hud-time { color: #fff; }
.hud.ready .hud-time { color: var(--warn); }
.hud.done .hud-time { color: var(--accent-2); }
.hud.idle .hud-time { color: rgba(230, 235, 245, .35); }

/* ---------- ranking ---------- */
.rank-head { display: flex; align-items: center; justify-content: space-between; }
.rank-head h2 { margin: 0; }
.rank-list, .history { list-style: none; margin: 10px 0 0; padding: 0; counter-reset: rank; }
.rank-list li {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 9px; font-size: 13.5px;
}
.rank-list li:nth-child(odd) { background: rgba(148, 163, 184, 0.06); }
.rank-list li.me { box-shadow: inset 0 0 0 1px rgba(79, 140, 255, .6); background: rgba(79, 140, 255, .12); }
.rank-list .pos { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.rank-list li:nth-child(1) .pos { color: var(--gold); }
.rank-list li:nth-child(2) .pos { color: var(--silver); }
.rank-list li:nth-child(3) .pos { color: var(--bronze); }
.rank-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .time { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.rank-list .time small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.rank-list li.rank-empty { display: block; color: var(--muted); font-size: 13px; padding: 8px; background: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { padding: 8px; border-radius: 10px; background: rgba(2, 6, 23, 0.5); border: 1px solid var(--line); text-align: center; }
.stat b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.history li { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); padding: 4px 2px; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.history li b { color: var(--text); font-weight: 600; }

/* ---------- solution player ---------- */
.player-bar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(720px, calc(100% - 660px)); min-width: 420px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
  padding: 12px 14px; z-index: 16;
}
.pb-top { display: flex; align-items: center; gap: 12px; }
.phase { flex: 1; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.counter { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.progress { position: relative; height: 8px; margin: 10px 0; border-radius: 99px; background: rgba(2, 6, 23, 0.7); cursor: pointer; overflow: hidden; }
.progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--accent), #7aa9ff); border-radius: 99px; }
.progress-marks { position: absolute; inset: 0; pointer-events: none; }
.progress-marks i { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, .35); }
.pb-controls { display: flex; justify-content: center; gap: 8px; }
.pb-controls .icon-btn { width: 40px; height: 40px; border-radius: 12px; }
.pb-controls .play { width: 52px; background: var(--accent); border-color: var(--accent); color: #fff; }
.pb-controls .play svg { fill: currentColor; stroke: none; }
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.phase-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; max-height: 58px; overflow: auto; scrollbar-width: thin; }
.phase-chip {
  padding: 3px 9px; border-radius: 99px; border: 1px solid var(--line-strong); font-size: 12px; color: var(--muted);
  background: transparent; cursor: pointer;
}
.phase-chip.done { color: var(--accent-2); border-color: rgba(34, 197, 94, .45); }
.phase-chip.current { color: #fff; background: rgba(79, 140, 255, .25); border-color: var(--accent); }
.move-list {
  margin-top: 8px; max-height: 62px; overflow: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  color: var(--muted); padding: 2px; scrollbar-width: thin;
}
.move-list span { display: inline-block; padding: 0 3px; border-radius: 4px; margin-right: 2px; cursor: pointer; }
.move-list span.done { color: #cbd5e1; }
.move-list span.cur { background: var(--accent); color: #fff; }

/* ---------- misc ---------- */
.loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-radius: 12px;
  background: var(--panel-solid); border: 1px solid var(--line-strong); box-shadow: var(--shadow); z-index: 40;
}
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: absolute; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 16px; border-radius: 12px; background: var(--panel-solid); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow); font-size: 14px; z-index: 50; transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(239, 68, 68, .6); }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, .6); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 16px; }
.modal {
  position: relative; width: min(460px, 100%); max-height: calc(100% - 32px); overflow: auto;
  background: var(--panel-solid); border: 1px solid var(--line-strong); border-radius: 18px; padding: 22px; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 12px; font-size: 20px; }
.modal p { color: var(--muted); line-height: 1.5; font-size: 14px; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.result-time { font-size: 48px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; margin: 8px 0; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: rgba(34, 197, 94, .18); color: #4ade80; }
.badge.warn { background: rgba(245, 158, 11, .18); color: #fbbf24; }
.help-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.help-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-table td:first-child { color: var(--muted); white-space: nowrap; padding-right: 12px; }
kbd { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-strong); background: rgba(2, 6, 23, .6); }

.mobile-only { display: none; }
.quick-bar { display: none; }

@media (max-width: 1180px) {
  .quick-bar {
    display: flex; gap: 10px; position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-50%); z-index: 14; width: min(420px, calc(100% - 32px));
  }
  .quick-bar.covered { display: none; }
  .quick-bar .btn { padding: 12px; box-shadow: var(--shadow); }
  .player-bar { width: calc(100% - 32px); min-width: 0; bottom: 12px; }
  .panel { top: 64px; }
  .mobile-only { display: inline-flex; }
  .panel.left, .panel.right { transform: translateX(calc(-100% - 24px)); transition: transform .25s; }
  .panel.right { transform: translateX(calc(100% + 24px)); }
  .panel.open { transform: none !important; }
}
@media (max-width: 640px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand-text { display: none; }
  .player { flex: 1; min-width: 0; }
  .player label { display: none; }
  .player input { width: 100%; min-width: 0; }
  .top-actions { gap: 4px; }
  .top-actions .icon-btn, .lang-btn { width: 34px; min-width: 34px; }
  .hud { top: 58px; }
  .hud-time { font-size: 32px; }
  .panel { left: 8px !important; right: 8px !important; width: auto !important; }
  .pb-controls .icon-btn { width: 36px; height: 36px; }
  .move-list { display: none; }
}
