/* Dual N-Back. Chalk on coal, same ground as Memory Palace. */

:root {
  color-scheme: dark;
  --paper: #1b1b1a;   /* coal */
  --white: #242423;   /* lifted surfaces */
  --ink: #d6d3ca;     /* chalk */
  --ink2: #8a887f;    /* muted chalk */
  --faint: #383836;   /* hairlines */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --rule: 2px solid var(--ink);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.5 var(--serif); min-height: 100vh; display: flex; flex-direction: row; align-items: stretch; }
/* Sand. Sparse specks under a soft vignette. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(ellipse 90% 70% at 50% 35%, transparent 30%, rgba(0, 0, 0, .18) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='1' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .92  0 0 0 0 .9  0 0 0 0 .84  0 0 0 1 0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete' tableValues='0 0 0 0 0 0 0 0 0 0 0 0 0 0 .12 .18 .24 .24 .24 .24'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 100% 100%, 256px 256px;
  animation: drift 40s linear infinite;
}
a { color: inherit; }
::selection { background: var(--ink); color: var(--paper); }
h1 { font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; margin: 0; }
p { margin: 0; }
kbd { font-family: var(--mono); font-size: 0.68rem; border: 1px solid currentColor; padding: 0 0.4em; border-radius: 3px; opacity: .8; }

@keyframes drift { to { background-position: 0 0, 256px 256px; } }
@keyframes pop { 0% { transform: scale(.82); } 60% { transform: scale(1.04); } 100% { transform: none; } }
@keyframes slam { 0% { transform: rotate(-9deg) scale(1.9); opacity: 0; } 60% { transform: rotate(-4deg) scale(.96); opacity: 1; } 100% { transform: rotate(-5deg) scale(1); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes breathe { 50% { opacity: .45; } }

.wrap { flex: 1; min-width: 0; max-width: 600px; margin: 0 auto; padding: 3rem 1.5rem 3rem; display: flex; flex-direction: column; justify-content: center; }

/* ---- frame: sidebar on the left, same as Memory Palace ---- */
.side {
  position: sticky; top: 0; height: 100vh; width: 232px; flex: none; display: flex; flex-direction: column; gap: 1.8rem;
  padding: 1.4rem 1.1rem 1.1rem; border-right: var(--rule); background: color-mix(in srgb, var(--paper) 70%, transparent);
}
.brand { text-decoration: none; font-weight: 700; text-transform: uppercase; letter-spacing: 0.22em; font-size: 0.95rem; padding: 0 0.6rem; transition: letter-spacing .25s var(--ease); }
.brand:hover { letter-spacing: 0.3em; }
.nav { display: flex; flex-direction: column; gap: 0.25rem; font-family: var(--mono); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.14em; }
.nav a { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--ink2); padding: 0.7rem 0.9rem; border: 1.5px solid transparent; border-radius: 3px; transition: color .22s, background .22s, border-color .22s, transform .22s var(--ease); }
.nav a:hover { color: var(--ink); border-color: var(--faint); background: var(--white); transform: translateX(3px); }
.nav a.on { color: var(--paper); background: var(--ink); border-color: var(--ink); }
.lvlbox { display: flex; flex-direction: column; gap: 0.6rem; padding: 0 0.6rem; }
.lbl { font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--ink2); }
.stats { margin-top: auto; display: flex; flex-direction: column; gap: 0.35rem; padding: 0 0.6rem; font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.04em; color: var(--ink2); }
.stats b { color: var(--ink); font-weight: 700; }
.home { margin-top: -1rem; padding: 0 0.6rem; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.04em; color: var(--ink2); text-decoration: none; transition: color .22s; }
.home:hover { color: var(--ink); }
.tag { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink2); }

/* ---- toolbar + progress ---- */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.55rem; font-family: var(--mono); }
.level { display: flex; align-items: center; gap: 0.5rem; font-size: 0.95rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em; }
.step {
  appearance: none; cursor: pointer; width: 26px; height: 26px; display: grid; place-items: center; font: 700 0.95rem/1 var(--mono);
  border: 1.5px solid var(--faint); background: transparent; color: var(--ink2); border-radius: 3px; transition: border-color .2s, color .2s, background .2s;
}
.step:hover { border-color: var(--ink); color: var(--ink); }
.step:disabled { opacity: .25; cursor: default; }
.count { font-size: 0.8rem; color: var(--ink2); font-variant-numeric: tabular-nums; }
.bar { height: 3px; background: var(--faint); margin-bottom: 1.6rem; }
.bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .3s var(--ease); }

/* ---- board ---- */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(360px, 100%); margin: 0 auto; }
.tile { aspect-ratio: 1; border: 1.5px solid var(--faint); background: var(--white); border-radius: 3px; transition: background .12s, border-color .12s, box-shadow .2s; }
.tile.on { background: var(--ink); border-color: var(--ink); box-shadow: 0 0 0 5px color-mix(in srgb, var(--ink) 8%, transparent), 0 0 46px color-mix(in srgb, var(--ink) 30%, transparent); animation: pop .22s var(--ease); }
.tile:nth-child(5) { position: relative; }
.tile:nth-child(5)::after { content: ""; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--faint); }
.tile.on:nth-child(5)::after { display: none; }

/* ---- answer keys ---- */
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; width: min(360px, 100%); margin: 1.4rem auto 0; }
.key {
  appearance: none; cursor: pointer; font-family: var(--mono); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.12em;
  padding: 1rem 0.5rem; border: var(--rule); background: var(--white); color: var(--ink); border-radius: 3px; user-select: none; touch-action: manipulation;
  display: flex; align-items: center; justify-content: center; gap: 0.6rem;
  transition: background .12s, color .12s, border-color .12s, transform .07s;
}
.key:active { transform: scale(.97); }
.key.ok { background: var(--ink); color: var(--paper); }
.key.bad { border-style: dashed; color: var(--ink2); text-decoration: line-through; }
.key.miss { border-style: dashed; border-color: var(--ink2); }
body[data-view="idle"] .key { opacity: .35; pointer-events: none; }

/* ---- hint + actions ---- */
.hint { text-align: center; font-size: 0.95rem; color: var(--ink2); margin: 1.4rem auto 0; max-width: 40ch; min-height: 1.5em; }
.hint b { color: var(--ink); font-weight: 700; }
.hint.mono { font-family: var(--mono); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.14em; }
.hint.breathe { animation: breathe 2.4s ease-in-out infinite; }
.actions { display: flex; gap: 0.6rem; justify-content: center; margin-top: 1.6rem; }
.btn {
  appearance: none; cursor: pointer; font-family: var(--mono); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em;
  padding: 0.75rem 1.5rem; border: var(--rule); background: var(--white); color: var(--ink); border-radius: 3px; user-select: none;
  display: inline-flex; align-items: center; gap: 0.7rem;
  transition: background .22s, color .22s, transform .22s var(--ease), box-shadow .25s;
}
.btn:hover, .btn:focus-visible { outline: none; transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, .4); }
.btn:active { transform: translateY(0) scale(.97); box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover, .btn.primary:focus-visible { background: var(--white); color: var(--ink); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink2); }
.btn.quiet:hover { color: var(--ink); background: var(--faint); box-shadow: none; }

/* view switching */
#stop, .results { display: none; }
body[data-view="play"] #start, body[data-view="play"] .step { display: none; }
body[data-view="play"] #stop { display: inline-flex; }
body[data-view="done"] .stage { display: none; }
body[data-view="done"] .results { display: block; }

/* ---- results ---- */
.results { text-align: center; padding-top: 1.2rem; animation: rise .32s var(--ease) both; }
.stamp {
  display: inline-block; transform: rotate(-5deg); font-family: var(--mono); font-weight: 700; text-transform: uppercase; letter-spacing: 0.24em;
  font-size: 0.82rem; padding: 0.35rem 0.8rem; border: 3px double var(--ink); border-radius: 4px; margin: 0.6rem 0 0.4rem;
  animation: slam .5s var(--ease) .2s both;
}
.bigscore { font-size: clamp(4rem, 16vw, 6.5rem); font-weight: 700; line-height: 1; margin: 0.4rem 0 0.6rem; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.bigscore small { font-size: 0.38em; color: var(--ink2); font-weight: 400; }
.facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 1.6rem; font-family: var(--mono); font-size: 0.8rem; color: var(--ink2); margin: 0.6rem 0 0.4rem; }
.facts b { color: var(--ink); }

/* ---- sidebar foot ---- */
.foot { border-top: 1px solid var(--faint); padding: 0.9rem 0.6rem 0; display: flex; justify-content: space-between; gap: 1rem; font-family: var(--mono); font-size: 0.74rem; color: var(--ink2); }
button.link { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
button.link:hover { color: var(--ink); }

@media (max-width: 720px) {
  body { flex-direction: column; }
  .side { position: static; height: auto; width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; padding: 0.8rem 1rem; border-right: 0; border-bottom: var(--rule); }
  .brand { padding: 0; }
  .nav { order: 3; width: 100%; flex-direction: row; gap: 0.3rem; }
  .nav a { flex: 1; justify-content: center; padding: 0.5rem 0.4rem; }
  .nav a:hover { transform: none; }
  .lvlbox { order: 4; flex-direction: row; align-items: center; padding: 0; }
  .stats { margin: 0 0 0 auto; flex-direction: row; gap: 0.8rem; padding: 0; font-size: 0.66rem; }
  .foot { border: 0; padding: 0; gap: 0.8rem; order: 5; margin-left: auto; }
  .home { order: 6; margin: 0; padding: 0; width: 100%; }
  .wrap { padding: 1.4rem 1rem 2rem; justify-content: flex-start; }
  .key { padding: 1.15rem 0.5rem; }
  .key kbd { display: none; }
  .btn kbd { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
