/* ALGO-GAMES — layered on /css/style.css; reuses its tokens (--ink, --coral, --teal, --yellow, --paper) and components (.card, .btn, .pill, .wordcard). */

.ag-page { padding-bottom: 40px; }
.ag-top { width: 100%; max-width: 960px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.ag-wordmark { font-size: 1.7rem; color: var(--ink); text-decoration: none; letter-spacing: -0.5px; }
.ag-wordmark span { color: var(--coral); }
.ag-main { width: 100%; max-width: 960px; }
.ag-main > * + * { margin-top: 16px; }
.ag-loading { text-align: center; color: var(--graphite); }
/* style.css gives .btn display:inline-flex, which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

a { color: var(--teal-dark); }
a.btn { text-decoration: none; }
:where(a, button, input, select, summary, [tabindex]):focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; box-shadow: 0 0 0 5px var(--ink); }
.btn:hover:not(:disabled) { filter: brightness(1.04); }
.btn.coral:hover:not(:disabled) { background: var(--coral-dark); }
.btn.teal:hover:not(:disabled) { background: var(--teal-dark); }
.btn.small { min-height: 40px; }

/* ---- Game page chrome ---- */
.ag-crumbs { font-weight: 700; font-size: 0.9rem; color: var(--graphite); }
.ag-crumbs a { text-decoration: none; }
.ag-game-header h1 { margin: 2px 0 6px; font-size: clamp(1.6rem, 5vw, 2.3rem); line-height: 1.1; }
.ag-subtitle { color: var(--coral); }
.ag-game-header p { margin: 6px 0; }
.ag-eyebrow { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 800; color: var(--graphite); }
.ag-meta { color: var(--graphite); font-size: 0.88rem; font-weight: 600; }
.ag-game-progress { margin-top: 10px; }
.ag-sim-note { background: var(--paper-dark); border: 2px dashed var(--ink); border-radius: 12px; padding: 10px 14px; font-size: 0.88rem; margin: 16px 0 0; }

.ag-levels { display: flex; gap: 8px; flex-wrap: wrap; }
.ag-level {
  font: 700 0.85rem/1.2 "Baloo 2", system-ui, sans-serif; color: var(--ink); background: #fff;
  border: 2px solid var(--ink); border-radius: 999px; padding: 8px 14px; cursor: pointer; min-height: 40px;
}
.ag-level.is-done { background: #e6f7f4; border-color: var(--teal-dark); }
.ag-level.is-current { background: var(--ink); color: var(--yellow); }
.ag-level:disabled { opacity: 0.5; cursor: not-allowed; }
.ag-stats { margin: 0; justify-content: flex-start; }
.ag-stats .timer-pill { margin-left: auto; }
.ag-goal { margin-bottom: 0; }
.ag-goal .word { font-size: clamp(1.1rem, 3.6vw, 1.45rem); line-height: 1.25; }
.ag-stage { background: repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(31,37,71,0.04) 28px), #fff; padding: 20px; overflow-x: auto; }
.ag-stage.is-over { opacity: 0.92; }
.ag-feedback { min-height: 1.6em; font-weight: 700; margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; }
.ag-feedback:empty { padding: 0; }
.ag-feedback.is-good { background: #e6f7f4; border: 2px solid var(--teal); }
.ag-feedback.is-bad { background: #ffe9ea; border: 2px solid var(--coral); }
.ag-feedback.is-info { background: #fff; border: 2px solid var(--line); }
.ag-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.ag-learn { background: var(--yellow); transform: rotate(0.5deg); }
.ag-learn h2 { margin: 0 0 6px; }
.ag-learn-score { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 1.2rem; margin-bottom: 0; }
.ag-concept summary { cursor: pointer; font-size: 1.2rem; list-style-position: inside; }
.ag-concept h3 { margin: 16px 0 4px; font-size: 1.05rem; }
.ag-concept p, .ag-concept ol { margin: 4px 0; line-height: 1.5; }

.ag-complexity-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ag-complexity { display: inline-flex; align-items: stretch; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; font-size: 0.85rem; font-weight: 700; }
.ag-complexity-label { background: #fff; padding: 4px 8px; }
.ag-complexity code { padding: 4px 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ag-complexity-fast code { background: var(--teal); color: #fff; }
.ag-complexity-mid code { background: var(--yellow); color: var(--ink); }
.ag-complexity-slow code { background: var(--coral); color: #fff; }

.ag-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.ag-chip { background: var(--paper-dark); border: 1.5px solid var(--line); border-radius: 999px; padding: 2px 9px; font-size: 0.75rem; font-weight: 600; }

.ag-progress { position: relative; height: 22px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; flex: 1; min-width: 80px; }
.ag-progress-fill { position: absolute; inset: 0 auto 0 0; background: repeating-linear-gradient(-45deg, var(--teal), var(--teal) 8px, var(--teal-dark) 8px, var(--teal-dark) 16px); transition: width .4s ease; }
.ag-progress-text { position: relative; display: block; text-align: center; font: 800 0.72rem/18px "Baloo 2", sans-serif; color: var(--ink); text-shadow: 0 0 3px #fff, 0 0 3px #fff; }

.ag-toasts { position: fixed; right: 16px; bottom: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; z-index: 60; pointer-events: none; }
.ag-toast { pointer-events: auto; display: flex; gap: 12px; align-items: center; max-width: 380px; background: var(--yellow); border: 2.5px solid var(--ink); border-radius: 14px; padding: 12px 14px; box-shadow: 4px 4px 0 var(--ink); transform: rotate(-1deg); animation: ag-pop .35s ease; }
.ag-toast-emoji { font-size: 2rem; }
.ag-toast-close { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--ink); min-width: 32px; min-height: 32px; }
@keyframes ag-pop { from { transform: scale(.8) rotate(-4deg); opacity: 0; } }

.ag-quiz { border: 2px solid var(--ink); border-radius: 12px; padding: 12px 14px 14px; margin: 12px 0 0; background: var(--paper); }
.ag-quiz legend { font-weight: 800; padding: 0 6px; }
.ag-quiz-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.ag-quiz-option { background: #fff; text-align: left; }
.ag-quiz-option.is-correct { background: var(--teal); color: #fff; }
.ag-quiz-option.is-wrong { background: #ffe9ea; text-decoration: line-through; }

/* ---- Dashboard ---- */
.ag-hero { text-align: center; }
.ag-hero-title { font-size: clamp(2.4rem, 10vw, 4rem); margin: 0; line-height: 1; letter-spacing: -1px; }
.ag-hero-title > span > span { color: var(--coral); }
.ag-hero-sub { font-size: 1.1rem; font-weight: 600; margin: 8px 0 14px; }
.ag-loop { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 0; margin: 0; counter-reset: loop; }
.ag-loop li { background: var(--ink); color: var(--yellow); border-radius: 999px; padding: 4px 12px; font: 700 0.8rem "Baloo 2", sans-serif; }
.ag-loop li + li::before { content: "→ "; color: #fff; }
.ag-overview h2, .ag-category h2, .ag-achievements h2, .ag-sync h2 { margin: 0 0 6px; }
.ag-category-bars { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 10px; }
.ag-category-bars li { display: grid; grid-template-columns: minmax(130px, 200px) 1fr; align-items: center; gap: 12px; font-weight: 700; }
.ag-category-bars a { color: var(--ink); text-decoration: none; }
.ag-category { padding-top: 12px; }
.ag-grid { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.ag-game-card { display: flex; flex-direction: column; padding: 20px; }
.ag-game-card:nth-child(odd) { transform: rotate(-0.6deg); }
.ag-game-card:nth-child(even) { transform: rotate(0.6deg); }
.ag-game-card.is-completed { background: #f1fbf9; }
.ag-game-card h3 { margin: 4px 0 0; font-size: 1.35rem; line-height: 1.15; }
.ag-game-card .btn { margin-top: auto; }
.ag-card-top { display: flex; justify-content: space-between; font-size: 0.78rem; font-weight: 800; }
.ag-number { background: var(--ink); color: var(--yellow); border-radius: 6px; padding: 1px 7px; }
.ag-card-subtitle { margin: 0; color: var(--coral-dark); font-weight: 700; }
.ag-card-desc { font-size: 0.9rem; margin: 8px 0; flex-grow: 0; }
.ag-card-progress { display: flex; align-items: center; gap: 10px; margin: 12px 0 14px; }
.ag-best { font: 800 0.85rem "Baloo 2", sans-serif; color: var(--teal-dark); white-space: nowrap; }
.ag-ach-grid { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ag-ach { display: flex; gap: 10px; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.ag-ach.is-unlocked { border-color: var(--ink); background: #fff8e3; box-shadow: 3px 3px 0 var(--ink); }
.ag-ach.is-locked { opacity: 0.7; }
.ag-ach-emoji { font-size: 1.7rem; }
.ag-ach .muted { font-size: 0.8rem; }
.ag-reset { margin-top: 12px; }

/* ---- Shared game building blocks ---- */
.ag-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.ag-row.center { justify-content: center; }
.ag-col { display: flex; flex-direction: column; gap: 8px; }
.ag-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; align-items: start; }
.ag-panel { border: 2px solid var(--ink); border-radius: 12px; padding: 12px; background: var(--paper); }
.ag-panel h3, .ag-panel h4 { margin: 0 0 8px; }
.ag-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1.2px; font-weight: 800; color: var(--graphite); }
.ag-cells { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ag-cell {
  position: relative; min-width: 58px; min-height: 64px; padding: 16px 6px 6px; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; background: #fff; border: 2.5px solid var(--ink); border-radius: 10px; cursor: pointer; color: var(--ink);
  font-family: inherit; transition: transform .15s ease, background .2s ease;
}
button.ag-cell:hover:not(:disabled) { transform: translateY(-2px); }
.ag-cell:disabled { cursor: default; }
.ag-cell .ag-index { position: absolute; top: 2px; left: 0; right: 0; text-align: center; font: 700 0.7rem ui-monospace, Menlo, monospace; color: var(--graphite); }
.ag-cell.is-empty { background: var(--paper-dark); border-style: dashed; }
.ag-cell.is-hl { background: var(--yellow); }
.ag-cell.is-good { background: #d8f3ee; border-color: var(--teal-dark); }
.ag-cell.is-bad { background: #ffe0e1; border-color: var(--coral-dark); }
.ag-cell.is-dim { opacity: 0.35; }
.ag-cell.is-selected { outline: 3px solid var(--coral); outline-offset: 2px; }
.ag-cell.small { min-width: 44px; min-height: 50px; font-size: 1.1rem; }
.ag-num { font: 800 1.2rem "Baloo 2", sans-serif; }
.ag-code { font: 0.88rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--ink); color: #f5f3ee; border-radius: 10px; padding: 10px 14px; overflow-x: auto; white-space: pre; margin: 8px 0; }
.ag-code .is-hl { background: rgba(255,201,71,0.35); display: inline-block; width: 100%; }
.ag-log { list-style: none; padding: 0; margin: 8px 0 0; max-height: 180px; overflow-y: auto; font: 0.82rem/1.4 ui-monospace, Menlo, monospace; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; }
.ag-log li { padding: 3px 8px; border-bottom: 1px solid var(--line); }
.ag-log li.is-bad { background: #ffe9ea; }
.ag-log li.is-good { background: #e6f7f4; }
.ag-bigstat { font: 800 2rem "Baloo 2", sans-serif; line-height: 1; }
.ag-kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 0.9rem; }
.ag-kv dt { font-weight: 700; color: var(--graphite); }
.ag-kv dd { margin: 0; font-weight: 700; }
.ag-arrow { font-size: 1.3rem; font-weight: 800; color: var(--ink); }
.ag-worker { border: 2.5px solid var(--ink); border-radius: 12px; background: #fff; padding: 10px; min-width: 120px; text-align: center; transition: background .25s ease, transform .25s ease; }
.ag-worker .ag-emoji { font-size: 1.8rem; display: block; }
.ag-worker.is-active { background: #d8f3ee; }
.ag-worker.is-waiting { background: #fff3cd; }
.ag-worker.is-blocked { background: #ffe0e1; }
.ag-worker.is-done { background: var(--paper-dark); }
.ag-state { display: inline-block; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; padding: 1px 6px; border-radius: 6px; background: var(--ink); color: #fff; }
.ag-table-wrap { overflow-x: auto; }
.ag-table { border-collapse: collapse; font: 0.85rem ui-monospace, Menlo, monospace; }
.ag-table th, .ag-table td { border: 1.5px solid var(--ink); padding: 5px 8px; text-align: center; min-width: 34px; }
.ag-table th { background: var(--paper-dark); }
.ag-table td.is-hl { background: var(--yellow); font-weight: 800; }
.ag-table td.is-good { background: #d8f3ee; }
.ag-table td.is-path { background: var(--teal); color: #fff; font-weight: 800; }
.ag-slider { display: grid; grid-template-columns: minmax(120px, auto) 1fr 3ch; gap: 10px; align-items: center; font-weight: 700; font-size: 0.9rem; }
.ag-slider input { width: 100%; accent-color: var(--coral); }
.ag-bars { display: flex; align-items: flex-end; gap: 3px; height: 180px; padding: 4px; border-bottom: 2.5px solid var(--ink); }
.ag-bar { flex: 1; min-width: 6px; background: var(--ink); border-radius: 4px 4px 0 0; transition: height .15s ease, background .15s ease; }
.ag-bar.is-compare { background: var(--yellow); }
.ag-bar.is-swap { background: var(--coral); }
.ag-bar.is-sorted { background: var(--teal); }
.ag-race { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.ag-race li { display: grid; grid-template-columns: 110px 1fr 90px; align-items: center; gap: 8px; font-weight: 700; font-size: 0.85rem; }
.ag-race-track { height: 20px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; }
.ag-race-fill { height: 100%; background: var(--coral); width: 0; }
.ag-race li.is-winner .ag-race-fill { background: var(--teal); }
/* Diagrams keep a minimum size so labels stay legible on phones; .ag-stage scrolls horizontally instead of the page. */
.ag-svg { width: 100%; min-width: 460px; height: auto; display: block; margin: 0 auto; overflow: visible; }
.ag-svg .edge { stroke: var(--ink); stroke-width: 3; }
.ag-svg .edge.is-hl { stroke: var(--coral); stroke-width: 6; }
.ag-svg .edge.is-good { stroke: var(--teal); stroke-width: 6; }
.ag-svg .edge-label { font: 800 13px "Baloo 2", sans-serif; fill: var(--ink); paint-order: stroke; stroke: #fff; stroke-width: 4px; }
.ag-svg .node { cursor: pointer; }
.ag-svg .node circle { fill: #fff; stroke: var(--ink); stroke-width: 3; transition: fill .2s ease; }
.ag-svg .node text { font: 700 18px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.ag-svg .node .node-label { font: 800 14px "Baloo 2", sans-serif; fill: var(--ink); }
.ag-svg .node.is-hl circle { fill: var(--yellow); }
.ag-svg .node.is-good circle { fill: #bfeee6; stroke: var(--teal-dark); }
.ag-svg .node.is-bad circle { fill: #ffd0d2; stroke: var(--coral-dark); }
.ag-svg .node.is-dim { opacity: 0.4; }
.ag-svg .node:focus-visible circle { stroke: var(--coral); stroke-width: 5; }
.ag-svg .node:focus { outline: none; }
.ag-svg .msg { fill: var(--coral); stroke: var(--ink); stroke-width: 2; }
.ag-maze { display: grid; gap: 2px; width: min(100%, 420px); margin: 0 auto; }
.ag-maze > div { aspect-ratio: 1; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: clamp(0.8rem, 3.5vw, 1.2rem); }
.ag-maze .wall { background: var(--ink); }
.ag-maze .open { background: #fff; border: 1px solid var(--line); }
.ag-maze .visited { background: #fde7a7; }
.ag-maze .path { background: #bfeee6; }
.ag-maze .dead { background: #ffd0d2; }
.ag-board { display: grid; gap: 4px; width: min(100%, 300px); margin: 0 auto; }
.ag-board button { aspect-ratio: 1; font-size: 1.6rem; border: 2px solid var(--ink); border-radius: 6px; cursor: pointer; background: #fff; }
.ag-board button:nth-child(odd) { background: var(--paper-dark); }
.ag-board button.is-attacked { background: #ffe0e1; }
.ag-stackframes { display: flex; flex-direction: column-reverse; gap: 6px; min-height: 60px; }
.ag-frame { border: 2px solid var(--ink); border-radius: 8px; background: #fff; padding: 6px 10px; font: 0.9rem ui-monospace, Menlo, monospace; }
.ag-frame.is-top { background: var(--yellow); }
.ag-timeline { position: relative; border: 2px solid var(--ink); border-radius: 10px; background: #fff; padding: 8px; }
.ag-timeline-row { position: relative; height: 34px; margin: 4px 0; }
.ag-timeline-item { position: absolute; top: 0; height: 30px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; font-size: 0.78rem; font-weight: 700; cursor: pointer; padding: 0 4px; overflow: hidden; white-space: nowrap; }
.ag-timeline-item[aria-pressed="true"] { background: var(--teal); color: #fff; }
.ag-timeline-axis { display: flex; justify-content: space-between; font: 0.7rem ui-monospace, Menlo, monospace; color: var(--graphite); }

@media (max-width: 560px) {
  .ag-stage { padding: 14px 10px; }
  .ag-category-bars li { grid-template-columns: 1fr; gap: 4px; }
  .ag-race li { grid-template-columns: 80px 1fr 64px; font-size: 0.75rem; }
  .ag-cell { min-width: 48px; min-height: 58px; font-size: 1.35rem; }
  .ag-top { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .ag-game-card, .ag-learn, .ag-toast { transform: none !important; }
  .ag-toast { animation: none; }
  .ag-page *, .ag-page *::before, .ag-page *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
.ag-svg .edge.is-dim { stroke-dasharray: 4 6; opacity: 0.45; stroke-width: 2; }
