:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #dcdcd8;
  --accent: #3b6fd8;
  --accent-text: #ffffff;
  --danger: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131315;
    --surface: #1e1e21;
    --text: #ececef;
    --muted: #9a9aa2;
    --line: #34343a;
    --accent: #6f9bff;
    --accent-text: #0d1426;
    --danger: #ff8a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131315; --surface: #1e1e21; --text: #ececef; --muted: #9a9aa2;
  --line: #34343a; --accent: #6f9bff; --accent-text: #0d1426; --danger: #ff8a80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
main { flex: 1; display: flex; min-height: 0; }
[hidden] { display: none !important; }

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  min-height: 0;
}
#start { justify-content: center; text-align: center; gap: 4px; }
h1 { font-size: clamp(28px, 6vw, 40px); margin: 0 0 8px; }
h2 { font-size: 22px; margin: 0 0 12px; }
.lede { max-width: 34em; margin: 0 0 24px; }
.q { margin: 0 0 8px; color: var(--muted); }
.fineprint { color: var(--muted); font-size: 13px; max-width: 40em; text-align: center; }

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.big { min-width: 140px; min-height: 48px; font-size: 17px; }
button.link, label.link {
  background: none; border: none; color: var(--accent); padding: 4px 8px; cursor: pointer; font-size: 14px;
}
.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.resume-row { margin-top: 16px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* duel */
#duel { gap: 10px; }
.hint { margin: 0; font-size: 17px; text-align: center; }
.keys { color: var(--muted); font-size: 14px; }
.faces {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  place-items: center;
}
.face {
  padding: 0;
  border: 4px solid transparent;
  border-radius: 10px;
  background: none;
  line-height: 0;
  /* largest square that fits the cell */
  width: min(100%, calc(100vh - 150px));
  width: min(100%, calc(100dvh - 150px));
  aspect-ratio: 1;
}
.face:hover:not(:disabled) { border-color: var(--accent); }
.face canvas, .result-face canvas {
  width: 100%; height: 100%; border-radius: 6px; background: var(--line);
}
.faces.busy .face canvas { opacity: 0.55; transition: opacity 0.2s 0.15s; }
.bar {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.progress {
  position: relative;
  flex: 1;
  min-width: 160px;
  height: 22px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow: hidden;
}
.progress .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); opacity: 0.35; transition: width 0.2s; }
.progress .count { position: relative; display: block; text-align: center; font-size: 13px; line-height: 20px; }
.status { color: var(--muted); font-size: 14px; min-width: 6em; }

/* portrait phones: stack the faces */
@media (max-aspect-ratio: 4/5) {
  .faces { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .face { width: min(100%, calc((100dvh - 190px) / 2)); }
  .keys { display: none; }
}

/* result */
.result-face { width: min(100%, calc(100dvh - 230px)); aspect-ratio: 1; line-height: 0; }

/* overlay + banner */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  padding: 16px;
}
.overlay .card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}
.overlay .progress { margin: 12px 0 0; }
.banner {
  position: fixed; left: 16px; right: 16px; bottom: 36px; margin: 0 auto; max-width: 640px;
  background: var(--surface); color: var(--danger);
  border: 1px solid var(--danger); border-radius: 10px; padding: 12px 16px;
}
footer { padding: 4px 16px 8px; text-align: right; color: var(--muted); font-size: 12px; min-height: 24px; }

/* footer */
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
a { color: var(--accent); }
footer { display: flex; justify-content: space-between; gap: 12px; }
#unsupported { justify-content: center; text-align: center; }

/* password gate */
#gate { justify-content: center; text-align: center; }
.gate { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.gate input {
  font: inherit; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); min-width: 200px;
}
