/* Superflip: paper/ink/sage palette, light and dark. */

:root {
  color-scheme: light dark;
  --paper: #faf7f2;
  --ink: #26241f;
  --ink-soft: #6f6a5c;
  --accent: #4f7267;
  --hairline: #dbd2c0;
  --panel: #f2ecdf;
  --pb: #b7791f;
  --badge-bg: #7a4a10;   /* paper-on-badge ≥ 4.5:1 in light */
  --danger: #8f2f20;
  --font: "Avenir Next", Avenir, "Helvetica Neue", Seravek, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1C1917; --ink: #ECE6DA; --ink-soft: #C9C2B2; --accent: #7FA294;
    --hairline: #332E27; --panel: #26221C; --pb: #d9a441;
    --badge-bg: #d9a441; --danger: #e8907f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1C1917; --ink: #ECE6DA; --ink-soft: #C9C2B2; --accent: #7FA294;
  --hairline: #332E27; --panel: #26221C; --pb: #d9a441;
  --badge-bg: #d9a441; --danger: #e8907f;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.visually-hidden, .skip-link {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.skip-link:focus {
  width: auto; height: auto; clip-path: none; white-space: normal;
  top: 8px; left: 16px; z-index: 10;
  background: var(--ink); color: var(--paper);
  padding: 8px 14px; border-radius: 8px; font-weight: 600; text-decoration: none;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

a { color: var(--accent); }

/* ---------- header ---------- */
.site-header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--hairline);
}
.wordmark { font-size: 1.25rem; letter-spacing: 0.01em; color: var(--ink-soft); }
.wordmark b { color: var(--ink); font-weight: 700; }
.top-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-btn {
  font: inherit; font-size: 0.9rem;
  color: var(--ink-soft);
  background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 5px 10px; cursor: pointer; text-decoration: none;
  transition: color 150ms var(--ease-out), border-color 150ms var(--ease-out);
}
.nav-btn:hover { color: var(--accent); border-color: var(--hairline); }
.theme-toggle { font-variant-numeric: tabular-nums; }
.theme-toggle .theme-word { display: inline-block; min-width: 3.2em; text-align: left; }

/* ---------- layout ---------- */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(320px, 1fr) auto;
  grid-template-areas:
    "scramble scramble"
    "stage stats"
    "timer stats";
  gap: 0 24px;
  padding: 0 24px 8px;
  max-width: 1180px;
  width: 100%;
  margin-inline: auto;
}

.scramble-bar {
  grid-area: scramble;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 18px 0 6px;
  flex-wrap: wrap;
}
.scramble-text {
  font-family: var(--mono);
  font-size: clamp(0.85rem, 1.5vw, 1.05rem);
  letter-spacing: 0.06em;
  color: var(--ink);
  text-align: center;
  max-width: 62ch;
}
.scramble-badge {
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.03em;
  color: var(--paper); background: var(--badge-bg);
  border-radius: 999px; padding: 2px 9px; cursor: help;
}
:root[data-theme="dark"] .scramble-badge,
:root:not([data-theme="light"]) .scramble-badge { color: #1C1917; }
.scramble-tag {
  font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft); border: 1px solid var(--hairline);
  border-radius: 999px; padding: 1px 8px; cursor: help;
}
.scramble-btn {
  font-size: 1.05rem; line-height: 1;
  color: var(--ink-soft); background: none;
  border: 1px solid var(--hairline); border-radius: 8px;
  width: 32px; height: 32px; cursor: pointer;
  transition: color 150ms var(--ease-out), transform 300ms var(--ease-out);
}
.scramble-btn:hover { color: var(--accent); transform: rotate(90deg); }

.stage-wrap { grid-area: stage; position: relative; min-height: 320px; }
.stage { position: absolute; inset: 0; }
.cube-canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.cube-canvas:active { cursor: grabbing; }

/* layout chip + key cheat overlay */
.chip {
  position: absolute; left: 0; bottom: 6px;
  font: inherit; font-size: 0.76rem; letter-spacing: 0.03em;
  color: var(--ink-soft); background: var(--panel);
  border: 1px solid var(--hairline); border-radius: 999px;
  padding: 3px 11px; cursor: pointer;
  transition: color 150ms var(--ease-out), border-color 150ms var(--ease-out);
}
.chip:hover { color: var(--accent); border-color: var(--accent); }
.cheat {
  position: absolute; right: 0; top: 0;
  background: var(--panel); border: 1px solid var(--hairline);
  border-radius: 12px; padding: 12px 14px;
  max-width: 300px; max-height: 100%; overflow-y: auto;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.10);
}
.cheat-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  font-size: 0.74rem; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 8px;
}
.cheat-groups { display: flex; flex-direction: column; gap: 10px; }
.cheat h3 {
  font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 4px;
}
.cheat ul { list-style: none; display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 10px; }
.cheat li { display: flex; justify-content: space-between; gap: 8px; font-size: 0.8rem; }
.cheat b { font-family: var(--mono); font-weight: 600; }
kbd {
  font-family: var(--mono); font-size: 0.72rem;
  background: var(--paper); border: 1px solid var(--hairline);
  border-radius: 5px; padding: 0 5px; color: var(--ink-soft);
}
.notice { padding: 48px 24px; color: var(--ink-soft); text-align: center; }

.timer-block { grid-area: timer; text-align: center; padding: 4px 0 18px; }
.timer {
  font-size: clamp(3rem, 8vw, 5rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.1;
  transition: color 200ms var(--ease-out);
}
.timer.is-solved { color: var(--accent); }
.timer.is-pb { color: var(--pb); }
.timer.pop { animation: pop 420ms var(--ease-out); }
@keyframes pop {
  0% { transform: scale(1); }
  38% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.status { color: var(--ink-soft); font-size: 0.95rem; min-height: 1.5em; }

/* ---------- stats rail ---------- */
.stats {
  grid-area: stats;
  align-self: start;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 18px;
  margin: 8px 0 18px;
  max-height: calc(100vh - 220px);
  display: flex; flex-direction: column;
}
.stats-title { font-size: 1rem; font-weight: 700; margin-bottom: 10px; }
.stats-hint { display: block; font-size: 0.72rem; font-weight: 400; color: var(--ink-soft); }
.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 12px; margin-bottom: 10px;
}
/* Not uppercased: the standard notation is "Ao5" and "Ao12". */
.stat-grid dt { font-size: 0.74rem; letter-spacing: 0.04em; color: var(--ink-soft); }
.stat-grid dd { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.05rem; }
.recent { list-style: none; overflow-y: auto; flex: 1; min-height: 0; }
.recent li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 5px 2px; border-bottom: 1px dotted var(--hairline);
  font-size: 0.9rem;
}
.recent-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.recent li.is-dnf .recent-time { color: var(--danger); }
.recent-meta { color: var(--ink-soft); font-size: 0.78rem; margin-left: auto; }
.recent-del {
  font: inherit; font-size: 0.9rem; line-height: 1;
  background: none; border: none; color: var(--hairline);
  cursor: pointer; padding: 2px 4px; border-radius: 6px;
  transition: color 120ms var(--ease-out);
}
.recent li:hover .recent-del, .recent-del:focus-visible { color: var(--danger); }
.recent li.recent-empty { color: var(--ink-soft); border-bottom: none; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--hairline);
  padding: 16px 24px 22px;
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-align: center;
}

/* ---------- dialogs ---------- */
.dlg {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 22px 24px;
  width: min(560px, calc(100vw - 32px));
  max-height: min(85vh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.dlg::backdrop { background: rgba(20, 18, 14, 0.45); backdrop-filter: blur(2px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dlg h2 { font-size: 1.15rem; }
.dlg h3 { font-size: 0.85rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); margin: 18px 0 8px; }
.dlg-close {
  font: inherit; background: none; border: none; color: var(--ink-soft);
  cursor: pointer; font-size: 1rem; padding: 4px 8px; border-radius: 8px;
}
.dlg-close:hover { color: var(--ink); }
.fine { font-size: 0.8rem; color: var(--ink-soft); margin: 6px 0; }

.preset-row { display: flex; flex-direction: column; gap: 8px; }
.preset-row label { display: flex; gap: 10px; align-items: baseline; cursor: pointer; }
.preset-row span { font-size: 0.92rem; }

.bindings-scroll { max-height: 220px; overflow-y: auto; border: 1px solid var(--hairline); border-radius: 10px; }
.bindings { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.bindings th {
  text-align: left; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft); padding: 8px 12px; position: sticky; top: 0; background: var(--paper);
}
.bindings td { padding: 4px 12px; border-top: 1px solid var(--hairline); }
.key-btn {
  font: inherit; font-family: var(--mono); font-size: 0.82rem;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: 7px;
  padding: 3px 10px; cursor: pointer; min-width: 84px;
}
.key-btn:hover { border-color: var(--accent); }
.key-btn.is-custom { border-color: var(--accent); }

.range-row { display: flex; align-items: center; gap: 14px; font-size: 0.92rem; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row select {
  font: inherit; padding: 4px 8px; border-radius: 8px;
  border: 1px solid var(--hairline); background: var(--paper); color: var(--ink);
}

.data-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.data-row button {
  font: inherit; font-size: 0.88rem;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
.data-row button:hover { border-color: var(--accent); }
.data-row .danger { color: var(--danger); }

.help-list { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 0.95rem; }

/* ---------- touch/mobile notice ---------- */
.touch-note {
  display: none;
  margin: 0 16px 16px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
@media (pointer: coarse) and (max-width: 820px) {
  .touch-note { display: block; }
}

/* ---------- narrow layout ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "scramble"
      "stage"
      "timer"
      "stats";
  }
  .stats { max-height: none; }
  .stage-wrap { min-height: 300px; }
}

@media (max-width: 1240px) {
  .cheat { max-width: 240px; font-size: 0.94em; }
}
@media (max-width: 1000px) {
  .cheat { position: static; max-width: none; margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .scramble-btn { transition: none; }
  .scramble-btn:hover { transform: none; }
  .timer { transition: none; }
  .timer.pop { animation: none; }
}
