/* ============================================================
   FROM ZERO TO GAME — game.css
   The stage: canvas, empty state, touch controls, console,
   code reveal, level-complete choreography, certificate.
   ============================================================ */

.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.stage__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.stage__eyebrow {
  font-family: var(--mono); font-size: 10px; letter-spacing: .15em;
  color: var(--accent); text-transform: uppercase; display: block; margin-bottom: 5px;
}
.stage__title h2 {
  font-size: clamp(19px, 2.4vw, 26px); font-weight: 800; letter-spacing: -.025em; line-height: 1.1;
}
.stage__controls { display: flex; align-items: center; gap: 8px; }
.fps {
  font-family: var(--mono); font-size: 10px; color: var(--muted-2);
  letter-spacing: .06em; min-width: 54px; text-align: right;
}

/* ---------- canvas ---------- */
.canvas-wrap {
  position: relative;
  aspect-ratio: 16 / 10;
  width: 100%;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, #0B1017, #06080C 75%);
  overflow: hidden;
  box-shadow: var(--shadow-2), inset 0 0 60px rgba(0,0,0,.5);
  touch-action: none;
}
.canvas-wrap::after {
  /* subtle screen vignette + scanline texture, purely decorative */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.014) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse 90% 80% at 50% 50%, transparent 55%, rgba(0,0,0,.5));
  mix-blend-mode: screen; opacity: .5;
}
.canvas-wrap.is-shaking { animation: shake .32s var(--ease); }
@keyframes shake {
  10%,90% { transform: translate3d(-1px,1px,0); }
  30%,70% { transform: translate3d(3px,-2px,0); }
  50%     { transform: translate3d(-3px,2px,0); }
}
#gameCanvas { width: 100%; height: 100%; display: block; }

/* ---------- empty state ---------- */
.empty-state {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  text-align: center; padding: 20px;
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}
.empty-state.is-gone { opacity: 0; transform: scale(.98); pointer-events: none; }
.empty-state__ascii {
  font-family: var(--mono); font-size: clamp(11px, 1.6vw, 14px);
  letter-spacing: .32em; color: #3A4453; line-height: 2.1;
}
.empty-state__lines { font-family: var(--mono); font-size: 12px; color: #4C5766; line-height: 2; letter-spacing: .06em; }
.empty-state__nothing {
  font-size: 12px; color: var(--muted-2); letter-spacing: .18em; text-transform: uppercase;
  border-top: 1px solid var(--border-soft); padding-top: 14px; margin-top: 4px;
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { opacity: .45; } 50% { opacity: .95; } }

/* ---------- objective badge ---------- */
.objective {
  position: absolute; top: 12px; left: 12px; z-index: 4;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 13px; border-radius: 22px;
  background: rgba(9,13,19,.82); backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  font-size: 11.5px; animation: fadeUp .4s var(--ease);
  max-width: calc(100% - 24px);
}
.objective__label {
  font-family: var(--mono); font-size: 9px; letter-spacing: .14em; color: var(--accent);
}
.objective__text { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.objective__meter {
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  padding-left: 9px; border-left: 1px solid var(--border);
}
.objective.is-complete { border-color: rgba(61,220,132,.45); }
.objective.is-complete .objective__label { color: var(--success); }

/* ---------- in-canvas toast ---------- */
.canvas-toast {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
  z-index: 6; padding: 10px 18px; border-radius: 24px;
  background: rgba(9,13,19,.9); border: 1px solid rgba(53,224,255,.4);
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; color: var(--accent);
  box-shadow: 0 0 34px -10px var(--accent);
  animation: canvasToast 2.6s var(--ease) forwards;
  white-space: nowrap;
}
@keyframes canvasToast {
  0%   { opacity: 0; transform: translate(-50%, -10px); }
  12%  { opacity: 1; transform: translate(-50%, 0); }
  82%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

/* ---------- mobile tool action ----------
   Hidden on desktop, where the panel sits beside the canvas. */
.mobile-tool { display: none; }
.mobile-tool__hint {
  margin-top: 7px; text-align: center;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.5;
  color: var(--muted-2);
}

/* ---------- touch controls ----------
   A control deck under the canvas — it never covers the play area.
   Rendered only where useful: touch devices and small screens. The
   [hidden] attribute still gates it on the movement system existing. */
.touch-controls {
  display: none;
  align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  /* A thumb dragging the stick must never select text or scroll the page. */
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
@media (hover: none) and (pointer: coarse) { .touch-controls { display: flex; } }
@media (max-width: 900px) { .touch-controls { display: flex; } }
.touch-controls__hint {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .14em;
  color: var(--muted-2); text-transform: uppercase; text-align: center;
}
.joystick {
  position: relative; flex: none;
  width: 116px; height: 116px; touch-action: none;
}
.joystick__base {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, rgba(53,224,255,.09), rgba(10,14,20,.55));
  border: 1px solid rgba(53,224,255,.22);
  backdrop-filter: blur(4px);
}
.joystick__knob {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px;
  margin: -23px 0 0 -23px; border-radius: 50%;
  background: linear-gradient(180deg, #2A3644, #151C25);
  border: 1px solid rgba(53,224,255,.45);
  box-shadow: 0 6px 16px rgba(0,0,0,.55), 0 0 18px -6px var(--accent);
  transition: transform .12s var(--ease);
}
.joystick.is-active .joystick__knob { transition: none; }

.dpad {
  position: relative; flex: none;
  width: 128px; height: 128px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 4px;
}
.dpad__btn {
  border-radius: 12px; font-size: 13px; color: var(--muted);
  background: rgba(15,20,27,.72); border: 1px solid rgba(53,224,255,.18);
  backdrop-filter: blur(4px); touch-action: none;
  display: grid; place-items: center;
  transition: background .12s, color .12s, transform .1s;
}
.dpad__btn:active, .dpad__btn.is-down {
  background: rgba(53,224,255,.2); color: var(--text); transform: scale(.94);
}
.dpad__btn--up    { grid-area: 1 / 2; }
.dpad__btn--left  { grid-area: 2 / 1; }
.dpad__btn--right { grid-area: 2 / 3; }
.dpad__btn--down  { grid-area: 3 / 2; }

/* ============================================================
   CONSOLE
   ============================================================ */
.console {
  background: var(--panel); border: 1px solid var(--border-soft);
  border-radius: var(--r-lg); overflow: hidden;
}
.console__head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--panel-2);
  border-bottom: 1px solid var(--border-soft);
}
.console__title { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; color: var(--muted); }
.console__meta { font-family: var(--mono); font-size: 10px; color: var(--muted-2); margin-left: auto; }
.console__chevron { color: var(--muted-2); transition: transform .25s var(--ease); font-size: 11px; }
.console__head[aria-expanded="false"] .console__chevron { transform: rotate(-90deg); }
.console__body {
  height: 132px; overflow-y: auto; padding: 9px 14px;
  font-family: var(--mono); font-size: 11px; line-height: 1.85;
  background:
    linear-gradient(180deg, rgba(53,224,255,.02), transparent 40px);
  transition: height .3s var(--ease), padding .3s var(--ease);
}
.console__body.is-collapsed { height: 0; padding-top: 0; padding-bottom: 0; }
.console__line { display: flex; gap: 10px; animation: fadeIn .25s var(--ease); }
.console__time { color: #3E4757; flex: none; }
.console__msg { color: #94A0B0; word-break: break-word; }
.console__line--ok    .console__msg { color: var(--success); }
.console__line--warn  .console__msg { color: var(--warn); }
.console__line--err   .console__msg { color: var(--danger); }
.console__line--sys   .console__msg { color: var(--accent); }

/* ============================================================
   LEVEL COMPLETE
   ============================================================ */
.lc__badge { display: grid; place-items: center; margin-bottom: 14px; }
.lc__ring { stroke: rgba(61,220,132,.28); }
.lc__check { stroke: var(--success); stroke-dasharray: 40; stroke-dashoffset: 40; animation: drawCheck .5s var(--ease) .18s forwards; }
@keyframes drawCheck { to { stroke-dashoffset: 0; } }
.lc__eyebrow {
  text-align: center; font-family: var(--mono); font-size: 10px;
  letter-spacing: .2em; color: var(--success);
}
.lc__title { text-align: center; font-size: 27px; font-weight: 850; letter-spacing: -.02em; margin-top: 6px; }
.lc__flow {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 20px 0 6px; font-family: var(--mono); font-size: 11px; letter-spacing: .14em;
}
.lc__from { color: var(--muted-2); }
.lc__arrow { color: var(--accent); animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 0%,100% { transform: translateX(0); } 50% { transform: translateX(4px); } }
.lc__to {
  color: var(--accent); padding: 4px 11px; border-radius: 20px;
  border: 1px solid rgba(53,224,255,.35); background: rgba(53,224,255,.08);
}
.lc__hint { text-align: center; color: var(--muted); font-size: 12.5px; }
.lc__insight {
  margin: 18px 0 0; padding: 12px 14px; border-radius: var(--r-md);
  background: rgba(167,139,250,.07); border: 1px solid rgba(167,139,250,.24);
  font-size: 12.5px; color: #D6CCFF; text-align: center; line-height: 1.6;
}
.lc__actions { display: flex; justify-content: center; margin-top: 20px; }

/* ============================================================
   CODE REVEAL / EDITOR
   ============================================================ */
.code-reveal { margin-top: 18px; animation: fadeUp .5s var(--ease) .12s both; }
.code-reveal__head {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; background: var(--panel-2);
  border: 1px solid var(--border-soft); border-bottom: 0;
  border-radius: var(--r-md) var(--r-md) 0 0;
}
.code-reveal__label { font-family: var(--mono); font-size: 9.5px; letter-spacing: .16em; color: var(--muted); }
.code-reveal__lang {
  margin-left: auto; font-family: var(--mono); font-size: 9.5px; color: var(--accent);
  padding: 2px 8px; border-radius: 20px; background: rgba(53,224,255,.1);
  border: 1px solid rgba(53,224,255,.24);
}
.code-editor {
  background: #080B10; border: 1px solid var(--border-soft);
  border-radius: 0 0 var(--r-md) var(--r-md);
  overflow-x: auto; padding: 12px 0;
  max-height: 260px; overflow-y: auto;
}
.code-line { display: grid; grid-template-columns: 40px 1fr; gap: 0; }
.code-line:hover { background: rgba(255,255,255,.022); }
.code-line__n {
  font-family: var(--mono); font-size: 11px; color: #333C4A;
  text-align: right; padding-right: 12px; user-select: none;
}
.code-line__c {
  font-family: var(--mono); font-size: 12px; line-height: 1.75;
  color: #C7D2E0; white-space: pre; padding-right: 16px;
}
/* syntax colours */
.tok-key   { color: #FF7BC4; }
.tok-str   { color: #9CE88B; }
.tok-num   { color: #FFC46B; }
.tok-com   { color: #4A5566; font-style: italic; }
.tok-fn    { color: #7FD4FF; }
.tok-prop  { color: #B9A5FF; }
.tok-op    { color: #8FA0B4; }
.tok-punct { color: #6C7A8C; }

.code-explain { margin-top: 12px; }
.code-explain summary {
  cursor: pointer; font-size: 11.5px; color: var(--accent);
  letter-spacing: .04em; list-style: none; display: flex; align-items: center; gap: 7px;
}
.code-explain summary::-webkit-details-marker { display: none; }
.code-explain summary::before { content: "▸"; transition: transform .2s var(--ease); }
.code-explain[open] summary::before { transform: rotate(90deg); }
.code-explain p { margin-top: 9px; font-size: 12.5px; color: var(--muted); line-height: 1.65; }

/* ============================================================
   FINAL SCREEN
   ============================================================ */
.overlay--final .overlay__card { text-align: center; }
.final__eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: .3em;
  color: var(--muted); animation: fadeUp .6s var(--ease) both;
}
.final__title {
  margin-top: 12px; font-size: clamp(26px, 5vw, 42px); font-weight: 850; letter-spacing: -.03em;
  background: linear-gradient(180deg, #fff 35%, #9FB0C2);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: fadeUp .6s var(--ease) .12s both;
}
.final__title .brand-star { -webkit-text-fill-color: var(--accent); color: var(--accent); }
.final__sub { color: var(--muted); margin-top: 8px; animation: fadeUp .6s var(--ease) .2s both; }
.final__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 24px; }

/* ============================================================
   LEARNED / OBJECTIVES LISTS
   ============================================================ */
.learned-list { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.learned-item {
  display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start;
  padding: 12px; border-radius: var(--r-md);
  background: var(--bg-2); border: 1px solid var(--border-soft);
}
.learned-item__n { font-family: var(--mono); font-size: 11px; color: var(--accent); padding-top: 2px; }
.learned-item h4 { font-size: 13px; margin-bottom: 4px; }
.learned-item p { font-size: 12px; color: var(--muted); line-height: 1.6; }
.learned-item code {
  font-family: var(--mono); font-size: 11px; color: var(--accent);
  background: rgba(53,224,255,.08); padding: 1px 5px; border-radius: 4px;
}

/* ============================================================
   CERTIFICATE (screen + print)
   ============================================================ */
.certificate {
  background: #080B11; border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 30px; text-align: center;
  position: relative; overflow: hidden;
}
.certificate::before {
  content: ""; position: absolute; inset: 10px; border: 1px solid rgba(53,224,255,.16);
  border-radius: 12px; pointer-events: none;
}
.cert__brand { font-family: var(--mono); font-size: 10px; letter-spacing: .3em; color: var(--accent); }
.cert__title { font-size: 30px; font-weight: 850; letter-spacing: -.02em; margin: 10px 0 4px; }
.cert__status { font-family: var(--mono); font-size: 11px; letter-spacing: .24em; color: var(--success); }
.cert__body { color: var(--muted); font-size: 12.5px; margin: 16px auto 0; max-width: 420px; line-height: 1.7; }
.cert__name {
  margin-top: 18px; font-size: 18px; font-weight: 700;
  border-bottom: 1px dashed var(--border); display: inline-block; padding: 0 20px 6px;
}
/* The .modal__body list rules are generic, so these override them explicitly. */
.modal__body .cert__systems, .cert__systems {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px; margin-top: 22px; text-align: left;
}
.modal__body .cert__systems li, .cert__systems li {
  font-size: 12px; padding: 8px 10px; border-radius: var(--r-sm);
  background: rgba(61,220,132,.06); border: 1px solid rgba(61,220,132,.2); color: #C8F5DC;
}
.cert__systems li::before {
  content: "✓"; color: var(--success); font-weight: 800; margin-right: 7px; position: static;
}
.cert__meta {
  margin-top: 22px; display: flex; justify-content: center; gap: 24px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 10px; letter-spacing: .1em; color: var(--muted-2);
}
.cert__name-input {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 9px 12px; color: var(--text); font-size: 13px; font-family: var(--font); width: 100%;
}

@media print {
  body { background: #fff; color: #000; }
  body > *:not(.modal-root) { display: none !important; }
  .modal-root, .modal__card { position: static; background: #fff; border: 0; box-shadow: none; padding: 0; max-height: none; overflow: visible; }
  .modal__scrim, .modal__head, .modal__foot, .cert__name-input, .cert-name-field { display: none !important; }
  .certificate { background: #fff; border: 2px solid #111; color: #111; page-break-inside: avoid; }
  .certificate::before { border-color: #999; }
  .cert__brand { color: #0A7EA4; }
  .cert__status { color: #12844A; }
  .cert__body, .cert__meta { color: #444; }
  .cert__systems li { background: #F3FBF6; border-color: #BFE6CE; color: #14532D; }
}

/* ============================================================
   INSTRUCTOR PANEL
   ============================================================ */
.instructor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.objective-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.objective-list li {
  padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--bg-2); border: 1px solid var(--border-soft);
  font-size: 12px; color: var(--muted); padding-left: 12px;
}
.objective-list li::before { content: none; }
.objective-list b { color: var(--text); display: block; font-size: 11px; letter-spacing: .1em; margin-bottom: 3px; font-family: var(--mono); }
