:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --line: #262a31;
  --text: #e9ebef;
  --muted: #8b919c;
  --accent: #36c46a;
  --warn: #ff9f43;
  --bad: #ff5d5d;
  font-family: "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

#loader {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: grid; place-items: center; transition: opacity .45s ease, visibility .45s;
}
#loader.done { opacity: 0; visibility: hidden; }
#loader-cube { width: min(80vw, 420px); aspect-ratio: 1; }
body { margin: 0; background: var(--bg); color: var(--text); height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
button {
  font: inherit; color: var(--text); background: #232831; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button:hover { background: #2c323c; }
button.primary { background: var(--accent); border-color: var(--accent); color: #07140c; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.link { background: none; border: none; color: var(--muted); padding: 0 4px; text-decoration: underline; }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
h1 span { color: var(--accent); }
.conn { display: flex; align-items: center; gap: 12px; }
#status { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
#status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #555; }
#status[data-kind="ok"]::before { background: var(--accent); }
#status[data-kind="busy"]::before { background: var(--warn); }
#status[data-kind="error"] { color: var(--bad); }
#status[data-kind="error"]::before { background: var(--bad); }
#battery { font-size: 15px; font-weight: 600; color: var(--text); background: #0f1215; padding: 4px 10px; border-radius: 999px; }
#battery.low { color: #fff; background: var(--bad); }

main {
  display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px;
  padding: 20px 24px; min-height: 0;
}
.stage {
  position: relative; background: radial-gradient(ellipse at 50% 40%, #1d2128, var(--bg) 70%);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; min-height: 420px;
}
#cube { position: absolute; inset: 0; }
#cube canvas { display: block; cursor: grab; }
.move-card { position: absolute; top: 18px; left: 22px; pointer-events: none; }
#last-move { font-size: 64px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
#last-desc { color: var(--muted); margin-top: 6px; font-size: 15px; }
.stage-foot {
  position: absolute; left: 22px; right: 22px; bottom: 14px; display: flex; gap: 18px;
  align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap;
}
.stage-foot .hint { margin-left: auto; }
#gyro-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#gyro-row button { padding: 5px 10px; font-size: 13px; }
#demo-hint { position: absolute; top: 18px; right: 22px; margin: 0; font-size: 13px; color: var(--warn); }
#flash {
  position: absolute; left: 50%; bottom: 56px; transform: translate(-50%, 12px); opacity: 0;
  background: #22362a; color: #c9f5d6; border: 1px solid #2f6b44; padding: 10px 18px;
  border-radius: 10px; transition: .25s; pointer-events: none; white-space: nowrap;
}
#cal {
  position: absolute; left: 50%; top: 120px; transform: translateX(-50%); width: min(92%, 460px);
  background: rgba(23, 26, 31, .94); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 16px;
}
.cal-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
#cal-text { margin: 6px 0 10px; font-size: 17px; line-height: 1.4; }
#cal-dots { display: flex; gap: 6px; }
#cal-dots i { flex: 1; height: 5px; border-radius: 3px; background: #2c323c; }
#cal-dots i.ok { background: var(--accent); }
#cal-dots i.now { background: var(--warn); }
.c-U { color: #fff; } .c-D { color: #ffd51a; } .c-R { color: #ff4d52; }
.c-L { color: #ff8a2a; } .c-F { color: #2ec95e; } .c-B { color: #4d8bff; }
#flash.show { opacity: 1; transform: translate(-50%, 0); }

aside { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; padding-right: 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.card h2 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

.timer-card { text-align: center; }
#timer { font-size: 64px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
#timer[data-phase="ready"] { color: var(--accent); }
#timer[data-phase="solving"] { color: #fff; }
#solve-info { color: var(--muted); font-size: 14px; min-height: 18px; }
#phase-text { color: var(--muted); font-size: 14px; margin: 8px 0; }
#scramble {
  font-family: Consolas, monospace; font-size: 20px; line-height: 1.6; background: #0f1215;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; word-spacing: 4px;
}
#scramble .done { color: #3d434c; }
#scramble .next { color: #07140c; background: var(--accent); border-radius: 4px; padding: 0 4px; }
#scramble .next.half { background: var(--warn); }
#scramble .fix { color: var(--bad); font-family: "Segoe UI", sans-serif; font-size: 16px; }
.next-desc { word-spacing: normal; font-family: "Segoe UI", sans-serif; font-size: 14px; color: var(--muted); margin-top: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.stats div { background: #0f1215; border-radius: 8px; padding: 8px; text-align: center; }
.stats small { display: block; color: var(--muted); font-size: 12px; }
.stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
#times { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
#times li {
  display: grid; grid-template-columns: 34px 1fr 72px 80px 24px; align-items: center;
  padding: 5px 2px; border-bottom: 1px solid var(--line); font-size: 14px;
}
#times li.empty { display: block; color: var(--muted); border: none; }
#times .n, #times .m, #times .d { color: var(--muted); }
#times .t { font-weight: 600; font-variant-numeric: tabular-nums; }
#times .t.best { color: var(--accent); }
#times button { padding: 0; background: none; border: none; color: #555b65; }
#times button:hover { color: var(--bad); }

.history { display: flex; flex-wrap: wrap; gap: 6px; font-family: Consolas, monospace; min-height: 28px; }
.history span { background: #0f1215; border-radius: 6px; padding: 3px 8px; }
.history span:first-child { background: var(--accent); color: #07140c; }

.help summary { cursor: pointer; font-weight: 600; }
.help p { color: #c3c7ce; font-size: 14px; line-height: 1.5; }
.legend { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 14px; }
.legend b { display: inline-block; width: 22px; color: var(--accent); }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  max-width: 520px; padding: 22px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin-top: 0; font-size: 18px; }
dialog p { color: #c3c7ce; font-size: 14px; line-height: 1.5; }
dialog code { background: #0f1215; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
#mac-input {
  width: 100%; font: 18px Consolas, monospace; padding: 10px; margin-bottom: 14px;
  background: #0f1215; color: var(--text); border: 1px solid var(--line); border-radius: 8px;
}

@media (max-width: 900px) {
  body { height: auto; display: block; }
  main { display: flex; flex-direction: column; gap: 12px; padding: 12px 16px; }
  aside { display: contents; }
  .timer-card { order: -1; }
  /* Phone: canvas, wizard and controls stacked instead of overlaid, so nothing covers anything. */
  .stage { height: auto; display: flex; flex-direction: column; }
  #cube { position: relative; height: 46vh; min-height: 300px; order: 0; }
  #cal { position: static; transform: none; width: auto; margin: 0 12px 12px; order: 1; }
  .stage-foot { position: static; padding: 0 16px 14px; order: 2; }
  #last-move { font-size: 40px; }
  #last-desc { font-size: 13px; }
  .stage-foot .hint { display: none; }
  #timer { font-size: 52px; }
  header { padding: 12px 16px; flex-wrap: wrap; }
}
