/* ══════════════════════════════════════════════════════════
   allocator playground — all styles namespaced .ag-
   consumes the site palette via custom properties, nothing else.
   the global prefers-reduced-motion kill in style.css covers
   every animation declared here.
   ══════════════════════════════════════════════════════════ */

/* Reserve the built game's height before boot: the fallback paragraph
   and the game then occupy the same box, so the swap never moves the
   page under a reader — that swap-jump is exactly the reported bug. */
#allocator { min-height: 40.625rem; }

@media (max-width: 860px) {
  #allocator { min-height: 51.875rem; }
}

.ag {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* :where keeps this reset at zero specificity, so any .ag-* rule that
   sets a font on a button actually wins */
:where(.ag) button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ── fallback paragraph is replaced by the game at boot ── */

.ag-fallback {
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--ink-soft);
  max-width: 70ch;
}

/* ── readout ── */

.ag-top {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem 1.375rem;
  font-family: var(--mono);
}

.ag-brk {
  font-size: clamp(1.25rem, 3vw, 1.875rem);
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--amber);
  text-shadow: 0 0 1.125rem rgba(255, 161, 39, .35);
  font-variant-numeric: tabular-nums;
}

.ag-bytes {
  font-size: 0.8125rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* the spendable half of the ledger — what the store prices talk to */
.ag-wal {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}

.ag-rate {
  font-size: 0.6875rem;
  font-weight: 300;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

/* ── the heap strip ── */

.ag-bar {
  position: relative;
  height: 1.625rem;
  border: 1px solid var(--line);
  border-radius: 0.3125rem;
  background: rgba(14, 15, 25, .8);
  overflow: hidden;
}

.ag-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background:
    repeating-linear-gradient(90deg,
      rgba(255, 161, 39, .28) 0 0.625rem,
      rgba(255, 161, 39, .16) 0.625rem 1.25rem);
  box-shadow: 0 0 1.125rem rgba(255, 161, 39, .35);
  border-right: 2px solid var(--amber);
  transition: width .25s linear;
}

.ag-fill::after {
  /* the write head: a hot edge that never stops shimmering */
  content: '';
  position: absolute;
  right: -1px;
  top: 0;
  bottom: 0;
  width: 1.625rem;
  background: linear-gradient(90deg, transparent, rgba(255, 200, 90, .5));
  animation: ag-head 1.6s var(--ease) infinite;
}

@keyframes ag-head {
  0%, 100% { opacity: .4; }
  50%      { opacity: 1; }
}

.ag-notch {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--dimmer);
}

.ag-notch::after {
  content: attr(data-label);
  position: absolute;
  top: 0.1875rem;
  left: 0.3125rem;
  font-family: var(--mono);
  font-size: 0.5312rem;
  color: var(--dimmer);
  white-space: nowrap;
}

.ag-notch.hit { background: var(--teal); }
.ag-notch.hit::after { color: var(--teal-dim); }

/* ── main: clicker + store ── */

.ag-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
  gap: 0.875rem;
  align-items: stretch;
}

.ag-clickzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  min-height: 11.875rem;
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  background: rgba(14, 15, 25, .7);
  overflow: hidden;
}

/* the page mosaic: the address space filling up behind the button */
.ag-pages {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ag-malloc {
  position: relative;
  padding: 1.125rem 1.875rem;
  border: 1px solid rgba(255, 161, 39, .5);
  border-radius: 0.375rem;
  background: rgba(255, 161, 39, .08);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--amber);
  transition: transform .06s var(--ease), background .12s var(--ease),
              box-shadow .12s var(--ease);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.ag-malloc:hover {
  background: rgba(255, 161, 39, .14);
  box-shadow: 0 0 1.375rem rgba(255, 161, 39, .3);
}

.ag-malloc:active { transform: scale(.94); }

.ag-click-note {
  position: relative; /* above the mosaic canvas */
  font-family: var(--mono);
  font-size: 0.6562rem;
  font-weight: 300;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  /* legible over lit mosaic cells */
  background: rgba(8, 8, 15, .6);
  padding: 2px 0.5625rem;
  border-radius: 6.25rem;
}

/* floating +N motes */
.ag-mote {
  position: absolute;
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--amber);
  pointer-events: none;
  animation: ag-mote .8s var(--ease) forwards;
  text-shadow: 0 0 0.5rem rgba(255, 161, 39, .6);
}

@keyframes ag-mote {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-2.875rem); }
}

/* ── store ── */

.ag-store {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
}

.ag-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 0.75rem;
  padding: 0.5625rem 0.8125rem;
  border: 1px solid var(--line);
  border-radius: 0.3125rem;
  background: rgba(14, 15, 25, .7);
  text-align: left;
  transition: border-color .15s var(--ease), background .15s var(--ease),
              opacity .15s var(--ease);
}

.ag-row:not(:disabled):hover {
  border-color: rgba(255, 161, 39, .4);
  background: rgba(255, 161, 39, .05);
}

.ag-row:disabled { cursor: default; opacity: .45; }

/* an author display beats the UA [hidden] rule — restate it */
.ag-row[hidden] { display: none; }

.ag-row.ag-bought {
  animation: ag-buyflash .5s var(--ease);
}

@keyframes ag-buyflash {
  0%   { background: rgba(255, 161, 39, .22); border-color: var(--amber); }
  100% { background: rgba(14, 15, 25, .7); }
}

.ag-row-name {
  grid-column: 1;
  grid-row: 1;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ag-row-meta {
  grid-column: 1;
  grid-row: 2;
  font-family: var(--mono);
  font-size: 0.625rem;
  font-weight: 300;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

/* explicit column — a row-definite item otherwise packs into column 1
   ahead of the auto-placed name */
.ag-row-cost {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ag-row-price {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--amber-dim);
}

.ag-row:not(:disabled) .ag-row-price { color: var(--amber); }

.ag-row-eta {
  font-size: 0.5625rem;
  font-weight: 300;
  color: var(--dim);
  min-height: 1em;
}

.ag-row.ag-locked .ag-row-name { color: var(--dim); }
.ag-row.ag-locked .ag-row-price {
  color: var(--dimmer);
  font-weight: 300;
  font-size: 0.625rem;
}

/* ── dmesg ── */

.ag-log {
  border: 1px solid var(--line-soft);
  border-radius: 0.3125rem;
  background: rgba(8, 8, 15, .6);
  padding: 0.5rem 0.75rem;
  min-height: 4.625rem;
  font-family: var(--mono);
  font-size: 0.6562rem;
  font-weight: 300;
  line-height: 1.75;
  color: var(--dim);
  overflow: hidden;
}

.ag-log div:first-child { color: var(--ink-soft); }
.ag-log .t { color: var(--dimmer); margin-right: 0.5rem; }
.ag-log .hot { color: var(--teal); }

/* ── SIGTRAP puzzle ── */

.ag-trap {
  border: 1px solid rgba(255, 61, 127, .35);
  border-radius: 0.375rem;
  background: rgba(14, 15, 25, .9);
  overflow: hidden;
  animation: ag-trap-in .4s var(--ease);
}

@keyframes ag-trap-in {
  0%   { transform: translateY(0.5rem); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

.ag-trap-cap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  padding: 0.5rem 0.875rem;
  background: rgba(255, 61, 127, .08);
  border-bottom: 1px solid rgba(255, 61, 127, .2);
  font-family: var(--mono);
  font-size: 0.6875rem;
}

.ag-trap-sig { color: var(--magenta); font-weight: 700; }
.ag-trap-why { color: var(--dim); font-weight: 300; }

.ag-trap-body { padding: 1rem 1rem 1.125rem; }

.ag-trap-task {
  font-size: 0.8125rem;
  color: var(--ink-soft);
  margin-bottom: 0.875rem;
  max-width: 60ch;
}

/* the corrupted string: one cell per byte */
.ag-word {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4375rem;
  margin-bottom: 1rem;
}

.ag-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  min-width: 2.875rem;
  padding: 0.5rem 0.5rem 0.4375rem;
  border: 1px solid var(--line);
  border-radius: 0.3125rem;
  background: rgba(23, 26, 39, .6);
  font-family: var(--mono);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}

.ag-cell-hex {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: -.02em;
}

.ag-cell-ch {
  font-size: 0.9375rem;
  font-weight: 700;
  min-height: 1.2em;
  color: var(--dimmer);
}

.ag-cell.on {
  border-color: var(--amber);
  background: rgba(255, 161, 39, .1);
  box-shadow: 0 0 0.875rem rgba(255, 161, 39, .25);
}
.ag-cell.on .ag-cell-hex { color: var(--amber); }

.ag-cell.ok { border-color: rgba(53, 232, 224, .4); }
.ag-cell.ok .ag-cell-hex { color: var(--dim); }
.ag-cell.ok .ag-cell-ch {
  color: var(--teal);
  text-shadow: 0 0 0.625rem rgba(53, 232, 224, .5);
}

.ag-cell.err { animation: ag-shake .3s var(--ease); }

@keyframes ag-shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-0.1875rem); }
  60% { transform: translateX(0.1875rem); }
}

/* the tool: an honest ascii table */
.ag-table-cap {
  font-family: var(--mono);
  font-size: 0.5938rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--dimmer);
  margin-bottom: 0.4375rem;
}

.ag-table {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.25rem, 1fr));
  gap: 0.25rem;
}

.ag-key {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.375rem 0.25rem;
  border: 1px solid var(--line-soft);
  border-radius: 0.25rem;
  background: rgba(14, 15, 25, .6);
  font-family: var(--mono);
  transition: border-color .12s var(--ease), background .12s var(--ease),
              transform .06s var(--ease);
}

.ag-key:hover {
  border-color: rgba(255, 161, 39, .45);
  background: rgba(255, 161, 39, .06);
}

.ag-key:active { transform: scale(.92); }

.ag-key-hex { font-size: 0.625rem; font-weight: 300; color: var(--dim); }
.ag-key-ch  { font-size: 0.7812rem; font-weight: 700; color: var(--ink); }

.ag-key.err { animation: ag-shake .3s var(--ease); border-color: rgba(255, 61, 127, .5); }

.ag-key.hint {
  animation: ag-hint 1s var(--ease) infinite;
  border-color: rgba(53, 232, 224, .6);
}

@keyframes ag-hint {
  0%, 100% { background: rgba(53, 232, 224, .04); }
  50%      { background: rgba(53, 232, 224, .18); }
}

.ag-key.spent {
  animation: ag-keyflash .45s var(--ease);
}

@keyframes ag-keyflash {
  0%   { background: rgba(53, 232, 224, .35); border-color: var(--teal); }
  100% { background: rgba(14, 15, 25, .6); }
}

.ag-trap-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  margin-top: 0.875rem;
  font-family: var(--mono);
  font-size: 0.625rem;
  color: var(--dimmer);
}

/* ── banner between states ── */

.ag-banner {
  padding: 0.625rem 0.875rem;
  border-left: 2px solid var(--teal);
  background: rgba(53, 232, 224, .06);
  border-radius: 0 0.3125rem 0.3125rem 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--teal);
  animation: ag-trap-in .35s var(--ease);
}

/* ── core dumped ── */

.ag-done {
  border: 1px solid rgba(255, 161, 39, .4);
  border-radius: 0.375rem;
  background: rgba(14, 15, 25, .9);
  padding: 1.625rem 1.5rem 1.375rem;
  text-align: center;
  animation: ag-trap-in .5s var(--ease);
}

.ag-done-sig {
  font-family: var(--display);
  font-size: clamp(1.875rem, 4.5vw, 2.75rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .01em;
  color: #fff;
  text-shadow: 0 0 1.625rem rgba(255, 161, 39, .4);
}

.ag-done-sub {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--dim);
  margin: 0.375rem 0 1.125rem;
}

.ag-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.125rem;
}

.ag-stat {
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.ag-stat b { color: var(--amber); font-weight: 700; }

.ag-badge {
  display: inline-block;
  margin-bottom: 1.125rem;
  padding: 0.375rem 0.875rem;
  border: 1px solid rgba(255, 61, 127, .5);
  border-radius: 6.25rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--magenta);
  background: rgba(255, 61, 127, .07);
  text-shadow: 0 0 0.75rem rgba(255, 61, 127, .5);
}

.ag-reset {
  display: inline-block;
  margin-top: 2px;
  padding: 0.5625rem 1.125rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
  transition: color .15s var(--ease), border-color .15s var(--ease);
}

.ag-reset:hover { color: var(--amber); border-color: rgba(255, 161, 39, .5); }

/* ── responsive ── */

@media (max-width: 860px) {
  .ag-main { grid-template-columns: minmax(0, 1fr); }
  .ag-clickzone { min-height: 9.375rem; }
  .ag-table { grid-template-columns: repeat(auto-fill, minmax(2.875rem, 1fr)); }
}
