/* Tower Defense page. Colors, buttons and panels come from style.css */

body.td {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---------- Top bar ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.6rem 1rem;
  background: rgba(7, 11, 31, 0.9);
  border-bottom: 2px solid var(--cyan-dim);
}
.stats { display: flex; gap: 1.4rem; flex-wrap: wrap; font-weight: 700; }
.stat strong { font-family: var(--pixel); font-size: 0.85rem; color: var(--gold); margin-left: 0.3rem; }
.stat.low strong { color: var(--pink); }
.controls { display: flex; gap: 0.5rem; }

.btn-small { font-size: 0.65rem; padding: 0.6rem 0.8rem; text-decoration: none; }
.btn-primary.btn-small { font-size: 0.7rem; box-shadow: 0 3px 0 #b38a00; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Board ---------- */
.board {
  flex: 1;
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem;
}
#board {
  max-width: 100%;
  max-height: 100%;
  border: 2px solid var(--cyan-dim);
  border-radius: 6px;
  background: #0a1030;
  box-shadow: 0 0 30px rgba(46, 230, 255, 0.15);
}
#board.placing { cursor: crosshair; }

/* ---------- Tower bar ---------- */
.tower-bar {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.6rem 1rem 0.8rem;
  background: rgba(7, 11, 31, 0.9);
  border-top: 2px solid var(--cyan-dim);
}
.tool {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "emoji name" "emoji cost" "beats beats";
  column-gap: 0.6rem;
  align-items: center;
  min-width: 170px;
  padding: 0.55rem 0.8rem;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--bg-2);
  border: 3px solid var(--cyan-dim);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s, box-shadow 0.1s;
}
.tool:hover:not(:disabled), .tool:focus-visible { border-color: var(--cyan); outline: none; transform: translateY(-2px); }
.tool.selected { border-color: var(--gold); box-shadow: 0 0 16px rgba(255, 210, 63, 0.6); }
.tool:disabled { opacity: 0.45; cursor: not-allowed; }
.tool-emoji { grid-area: emoji; font-size: 1.9rem; line-height: 1; }
.tool-name { grid-area: name; font-weight: 800; font-size: 0.95rem; }
.tool-cost { grid-area: cost; font-size: 0.85rem; color: var(--gold); font-weight: 700; }
.tool-beats { grid-area: beats; margin-top: 0.3rem; font-size: 0.78rem; color: var(--text-dim); }
.tool-key {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--text-dim);
}

.tool.locked { border-style: dashed; }
.tool.locked .tool-emoji { filter: grayscale(1); opacity: 0.6; }
.tool.locked .tool-cost { color: var(--pink); }

/* ---------- Lesson pop-ups (scan, quiz, challenges) ---------- */
.panel.lesson { width: min(620px, 94vw); }
.panel.lesson h2 { margin-bottom: 0.4rem; }
.progress { margin: 0 0 0.8rem; text-align: center; font-size: 0.9rem; color: var(--text-dim); }

/* A message that looks like a phone notification */
.message {
  margin: 0.8rem 0 1rem;
  padding: 0.9rem 1rem;
  color: #1b2030;
  background: #f3f5fb;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.msg-from { font-weight: 800; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; }
.msg-meta { font-weight: 400; font-size: 0.82rem; color: #5b6478; }
.msg-note { margin: 0.4rem 0 0; font-size: 0.85rem; font-style: italic; color: #5b6478; }
.msg-text { margin: 0.45rem 0 0; }
.msg-link {
  margin-top: 0.5rem;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.95rem;
  color: #1a56db;
  text-decoration: underline;
  word-break: break-all;
}

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
#ch-options { grid-template-columns: 1fr; }
@media (max-width: 520px) { .choices { grid-template-columns: 1fr; } }

.choice {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  text-align: left;
  background: var(--bg-2);
  border: 2px solid var(--cyan-dim);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}
.choice span { font-size: 0.82rem; color: var(--text-dim); }
.choice:hover:not(:disabled), .choice:focus-visible { border-color: var(--cyan); outline: none; transform: translateY(-1px); }
.choice:disabled { cursor: default; opacity: 0.55; }
.choice.big { align-items: center; font-family: var(--pixel); font-size: 0.85rem; padding: 1rem; }
.choice.right { border-color: #7cff6b; background: rgba(124, 255, 107, 0.15); opacity: 1; }
.choice.wrong { border-color: var(--pink); background: rgba(255, 61, 139, 0.15); opacity: 1; }

.result {
  margin-top: 1rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  border-left: 5px solid;
}
.result p { margin: 0.35rem 0; }
.result.good { background: rgba(124, 255, 107, 0.1); border-color: #7cff6b; }
.result.bad { background: rgba(255, 61, 139, 0.1); border-color: var(--pink); }
.result .verdict { font-weight: 800; font-size: 1.05rem; }
.result .reward { color: var(--gold); font-weight: 700; }
.result .penalty { color: #ffb3cf; font-weight: 700; }
.index-entry {
  margin-top: 0.7rem;
  padding: 0.6rem 0.8rem;
  background: rgba(46, 230, 255, 0.08);
  border: 1px dashed var(--cyan);
  border-radius: 6px;
}
.index-tag { font-weight: 800; color: var(--cyan); }

.tip { margin: 0.8rem 0 0; font-size: 0.92rem; color: var(--text-dim); font-style: italic; }

/* Password challenge */
.pw-label { display: block; font-weight: 700; margin-bottom: 0.3rem; }
#ch-pw {
  width: 100%;
  padding: 0.7rem 0.8rem;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--cyan-dim);
  border-radius: 6px;
}
#ch-pw:focus { outline: none; border-color: var(--cyan); }
.meter { height: 10px; margin-top: 0.6rem; background: var(--bg); border-radius: 5px; overflow: hidden; }
#ch-meter { height: 100%; width: 0; transition: width 0.2s, background 0.2s; }
#ch-meter.weak { background: var(--pink); }
#ch-meter.ok { background: var(--gold); }
#ch-meter.strong { background: #7cff6b; }
.meter-label { margin: 0.3rem 0 0.4rem; font-size: 0.85rem; font-weight: 700; color: var(--text-dim); }
.rules { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.3rem; font-size: 0.92rem; }
.rules li::before { content: '✖ '; color: var(--pink); font-weight: 800; }
.rules li.ok::before { content: '✔ '; color: #7cff6b; }
.rules label { cursor: pointer; }

/* ---------- Study tab ---------- */
.study-tool { border-color: var(--gold); border-style: solid; }
.study-tool .tool-cost { color: var(--cyan); }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; border-bottom: 2px solid var(--cyan-dim); }
.tab {
  flex: 1;
  padding: 0.7rem;
  font: inherit;
  font-weight: 800;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--gold); border-bottom-color: var(--gold); }
.tab:hover, .tab:focus-visible { color: var(--text); outline: none; }
.badge {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.4em;
  margin-left: 0.3rem;
  font-size: 0.8rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-dim);
}
.badge.has-missed { background: var(--pink); color: #fff; }

/* Flip card */
.flashcard {
  display: block;
  width: 100%;
  height: 240px;
  padding: 0;
  font: inherit;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  perspective: 1000px;
}
.flashcard:focus-visible { outline: 3px solid var(--cyan); outline-offset: 4px; border-radius: 12px; }
.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform 0.45s;
  transform-style: preserve-3d;
}
.flashcard.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.2rem 1.5rem;
  text-align: center;
  border: 3px solid var(--cyan);
  border-radius: 12px;
  backface-visibility: hidden;
}
.card-front { background: linear-gradient(160deg, #16205a, #0e1538); }
.card-back { background: #f3f5fb; color: #1b2030; border-color: var(--gold); transform: rotateY(180deg); }
.card-emoji { font-size: 3.2rem; line-height: 1; }
.card-term { font-family: var(--pixel); font-size: 1.1rem; color: var(--gold); line-height: 1.4; }
.card-term.small { font-family: var(--body); font-weight: 800; font-size: 1.05rem; color: #1b2030; }
.card-hint { font-size: 0.85rem; color: var(--text-dim); }
.card-def { font-size: 1.05rem; line-height: 1.5; }
.card-example { font-size: 0.9rem; font-style: italic; color: #5b6478; }
.card-nav { display: flex; align-items: center; justify-content: center; gap: 1.2rem; margin-top: 1rem; font-weight: 800; }
.tip.center { text-align: center; }

@media (prefers-reduced-motion: reduce) { .card-inner { transition: none; } }

/* Missed list */
#missed-list { display: grid; gap: 1rem; max-height: 50vh; overflow-y: auto; padding-right: 0.3rem; }
.empty { text-align: center; font-size: 1.1rem; color: var(--text-dim); padding: 2rem 0; }
.missed-item { padding: 0.8rem 1rem; background: rgba(7, 11, 31, 0.6); border: 1px solid var(--cyan-dim); border-radius: 8px; }
.missed-item .message { margin: 0.4rem 0 0.6rem; }
.missed-kind { margin: 0; font-weight: 800; color: var(--cyan); font-size: 0.9rem; }
.missed-answers { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; margin: 0.3rem 0; font-weight: 700; }
.missed-answers .yours { color: #ffb3cf; }
.missed-answers .right { color: #7cff6b; }
.missed-why { margin: 0.3rem 0 0; }

/* ---------- End screen ---------- */
.end-stats { text-align: center; font-weight: 700; color: var(--cyan); }
.new-tag {
  margin: 0;
  text-align: center;
  font-weight: 800;
  color: var(--pink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.intro-emoji { font-size: 3.5rem; text-align: center; line-height: 1.2; }
#dlg-end h3 { font-size: 1rem; color: var(--cyan); margin-bottom: 0.4rem; }
#end-summary { text-align: center; }
.lessons { padding-left: 1.2rem; display: grid; gap: 0.5rem; }
.lessons .leaked { color: #ffb3cf; }
.end-buttons { display: flex; justify-content: center; gap: 0.8rem; margin-top: 1.2rem; }
.end-buttons .btn { text-decoration: none; }

/* ---------- Streak and Firewall Blast (rewards.js) ---------- */
.stat.streak.hot strong { color: #ff7a3d; text-shadow: 0 0 8px #ff7a3d; }
.blast { position: relative; padding-bottom: 0.9rem; }
.charge {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 4px;
  height: 5px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}
#charge-fill { display: block; height: 100%; width: 0; background: var(--pink); transition: width 0.3s; }
.blast.ready { border-color: var(--pink); color: #fff; box-shadow: 0 0 14px rgba(255, 61, 139, 0.8); animation: pulse 0.9s infinite alternate; }
.blast.ready:disabled { animation: none; box-shadow: none; }
@keyframes pulse { to { box-shadow: 0 0 24px rgba(255, 61, 139, 1); } }

#btn-wave.boss { background: var(--pink); color: #fff; box-shadow: 0 3px 0 #a3134f; }

/* ---------- Live DMs (dm.js) ---------- */
.dm {
  position: absolute;
  z-index: 2;
  top: 1rem;
  right: 1rem;
  width: min(340px, 90vw);
  padding: 0.8rem;
  background: var(--panel);
  border: 3px solid var(--pink);
  border-radius: 12px;
  box-shadow: 0 0 24px rgba(255, 61, 139, 0.5);
  animation: slide-in 0.3s ease-out;
}
.dm-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; color: var(--pink); }
.dm-close { font: inherit; color: var(--text-dim); background: none; border: none; cursor: pointer; padding: 0.2rem 0.4rem; }
.dm-close:hover, .dm-close:focus-visible { color: var(--text); }
.dm .message { margin: 0.5rem 0; padding: 0.6rem 0.8rem; font-size: 0.92rem; }
.dm-timer { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-bottom: 0.5rem; }
#dm-timer-fill { height: 100%; width: 100%; background: var(--gold); }
.dm-replies { display: grid; gap: 0.4rem; }
.dm-replies .choice { font-size: 0.88rem; padding: 0.5rem 0.7rem; }
.dm .result { margin-top: 0.5rem; font-size: 0.88rem; }
.dm .result .verdict { font-size: 0.95rem; }
.dm .result:not(.good):not(.bad) { border-color: var(--gold); background: rgba(255, 210, 63, 0.08); }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }

/* ---------- Tower menu (upgrade.js) ---------- */
.up-stars { margin: 0; text-align: center; font-weight: 800; color: var(--gold); }
.up-habit { text-align: center; color: var(--text-dim); }
.up-stats { margin: 0 auto; border-collapse: collapse; font-weight: 700; }
.up-stats th, .up-stats td { padding: 0.3rem 1rem; text-align: center; }
.up-stats th { color: var(--text-dim); font-size: 0.85rem; }
.up-stats td:first-child { text-align: left; }
.up-stats .up-next { color: #7cff6b; }
#dlg-upgrade .end-buttons { flex-wrap: wrap; }

/* ---------- Badges (rewards.js) ---------- */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.7rem; max-height: 50vh; overflow-y: auto; }
.badge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.8rem 0.6rem;
  text-align: center;
  background: rgba(7, 11, 31, 0.6);
  border: 2px dashed var(--cyan-dim);
  border-radius: 10px;
  opacity: 0.6;
}
.badge-card.earned { border: 2px solid var(--gold); opacity: 1; box-shadow: 0 0 12px rgba(255, 210, 63, 0.35); }
.badge-emoji { font-size: 2rem; line-height: 1.2; }
.badge-card strong { font-size: 0.95rem; }
.badge-how { font-size: 0.78rem; color: var(--text-dim); }
.end-badges { text-align: center; font-weight: 800; color: var(--gold); }

.badge-pop {
  position: fixed;
  inset: 1.2rem auto auto 50%;
  transform: translateX(-50%);
  margin: 0;
  display: none;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1.2rem;
  color: var(--text);
  background: var(--panel);
  border: 3px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 0 30px rgba(255, 210, 63, 0.6);
}
.badge-pop:popover-open, .badge-pop:not([popover]):not([hidden]) { display: flex; animation: pop 0.3s ease-out; }
.badge-pop > span:last-child { display: flex; flex-direction: column; }
.badge-pop-emoji { font-size: 2.4rem; }
.badge-pop-tag { font-size: 0.75rem; font-weight: 800; color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; }
.badge-pop-how { font-size: 0.85rem; color: var(--text-dim); }

@media (prefers-reduced-motion: reduce) {
  .dm, .badge-pop:popover-open, .blast.ready { animation: none; }
}

/* ---------- Login checks (password.js) ---------- */
.login-row { display: flex; gap: 0.5rem; }
#login-pw, #login-code {
  flex: 1;
  width: 100%;
  padding: 0.7rem 0.8rem;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--cyan-dim);
  border-radius: 6px;
}
#login-code { letter-spacing: 0.3em; font-size: 1.3rem; text-align: center; }
#login-pw:focus, #login-code:focus { outline: none; border-color: var(--cyan); }
.login-error { min-height: 1.4em; margin: 0.4rem 0 0; color: #ffb3cf; font-weight: 700; }
.phone {
  margin: 0.8rem auto 1rem;
  max-width: 320px;
  padding: 0.8rem 1rem;
  color: #1b2030;
  background: #f3f5fb;
  border: 6px solid #1b2030;
  border-radius: 22px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.phone p { margin: 0.2rem 0; }
.phone-from { font-weight: 800; }
#login-phone-code { font-family: Consolas, 'Courier New', monospace; font-size: 1.2rem; letter-spacing: 0.15em; }

/* ---------- Level map (levels.js) ---------- */
.levels-panel { width: min(720px, 94vw); }
.levels-key { text-align: center; font-size: 0.85rem; color: var(--text-dim); margin: 0 0 0.8rem; }
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 0.5rem;
  max-height: 46vh;
  overflow-y: auto;
  padding: 0.3rem;
}
.level {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 62px;
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 2px solid var(--cyan-dim);
  border-radius: 50%;
  box-shadow: 0 4px 0 #0b1235;
  cursor: pointer;
  transition: transform 0.1s;
}
.level:hover, .level:focus-visible { border-color: var(--cyan); outline: none; transform: translateY(-2px); }
.level-num { font-family: var(--pixel); font-size: 0.75rem; }
.level-icon { font-size: 0.9rem; line-height: 1.2; min-height: 1.1em; }
.level.cleared { border-color: #58cc02; }
.level.boss { border-color: var(--pink); background: rgba(255, 61, 139, 0.15); }
.level.current { border-color: var(--gold); background: rgba(255, 210, 63, 0.18); box-shadow: 0 0 14px rgba(255, 210, 63, 0.6); }
.center { text-align: center; }

.level.locked { opacity: 0.55; border-style: dashed; box-shadow: none; }
.level.locked.boss { opacity: 0.7; }
.levels-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
.level { height: 74px; border-radius: 12px; gap: 0.1rem; }
.level-stars { font-size: 0.95rem; letter-spacing: 0.02em; color: #3a4a8a; line-height: 1; }
.level-stars .on { color: var(--gold); text-shadow: 0 0 6px rgba(255, 210, 63, 0.7); }
.level.final .level-stars { font-size: 1.05rem; margin-top: 0.2rem; }

/* ---------- Security Clearance test (levels.js) ---------- */
.skip-panel {
  position: relative;
  width: min(660px, 96vw);
  font-family: var(--body);
  border-color: var(--pink);
  box-shadow: 0 0 40px rgba(255, 61, 139, 0.35);
  /* faint scanlines, like an old monitor */
  background-image: repeating-linear-gradient(0deg, rgba(46, 230, 255, 0.035) 0 2px, transparent 2px 4px);
}
.sq-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.sq-target { margin: 0; font-family: var(--pixel); font-size: 0.7rem; color: var(--pink); letter-spacing: 0.06em; }
.sq-quit { font: inherit; font-size: 1.2rem; color: var(--text-dim); background: none; border: none; cursor: pointer; }
.sq-quit:hover, .sq-quit:focus-visible { color: var(--text); }

.sq-status { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin: 0.9rem 0 0.4rem; }
.sq-status > div:first-child { flex: 1; }
.sq-decrypt { display: flex; gap: 4px; }
.sq-decrypt span { flex: 1; height: 12px; background: var(--bg); border: 1px solid var(--cyan-dim); transform: skewX(-20deg); }
.sq-decrypt span.done { background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.sq-decrypt span.now { border-color: var(--gold); animation: blink 0.9s steps(2) infinite; }
.sq-count { margin: 0.35rem 0 0; font-family: Consolas, 'Courier New', monospace; font-size: 0.75rem; color: var(--text-dim); letter-spacing: 0.1em; }
.sq-shields-box { text-align: right; }
.sq-shields { font-size: 1.25rem; letter-spacing: 0.15em; }
.sq-shields .down { filter: grayscale(0.3); opacity: 0.8; }
.sq-shields.hit { display: inline-block; animation: shake 0.4s; }

.panel h2.sq-label { margin: 0.6rem 0 0.8rem; text-align: left; font-family: var(--body); font-weight: 800; font-size: 1.15rem; color: var(--cyan); }
.sq-body { min-height: 200px; }
.sq-prompt { font-size: 1.08rem; font-weight: 700; margin: 0 0 1rem; }
.sq-hint { margin: 0.6rem 0 0; text-align: center; font-size: 0.78rem; color: var(--text-dim); }

.sq-choices { display: grid; gap: 0.55rem; }
.sq-choices.two { grid-template-columns: 1fr 1fr; }
.sq-choices.links .sq-choice span:last-child { font-family: Consolas, 'Courier New', monospace; word-break: break-all; }
.sq-choice, .sq-tile {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.9rem;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  text-align: left;
  background: rgba(7, 11, 31, 0.75);
  border: 2px solid var(--cyan-dim);
  border-radius: 4px;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  cursor: pointer;
  transition: border-color 0.1s, box-shadow 0.1s, background 0.1s;
}
.sq-choice:hover:not(:disabled), .sq-tile:hover:not(:disabled) { border-color: var(--cyan); background: rgba(46, 230, 255, 0.08); }
.sq-choice:focus-visible, .sq-tile:focus-visible { outline: none; border-color: var(--gold); background: rgba(255, 210, 63, 0.08); }
.sq-choice.picked, .sq-tile.picked { border-color: var(--gold); background: rgba(255, 210, 63, 0.14); }
.sq-choice:disabled, .sq-tile:disabled { cursor: default; }
.sq-choice.right { border-color: #7cff6b; background: rgba(124, 255, 107, 0.15); }
.sq-choice.wrong { border-color: var(--pink); background: rgba(255, 61, 139, 0.15); }
.sq-key {
  flex-shrink: 0;
  font-family: var(--pixel);
  font-size: 0.65rem;
  color: var(--bg);
  background: var(--cyan);
  padding: 0.3rem 0.4rem;
}

.sq-answer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 3.4rem;
  padding: 0.6rem;
  margin-bottom: 0.9rem;
  font-family: Consolas, 'Courier New', monospace;
  background: rgba(0, 0, 0, 0.35);
  border: 1px dashed var(--cyan-dim);
}
.sq-answer::before { content: '>'; color: var(--cyan); font-weight: 800; align-self: center; }
.sq-bank { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.sq-tile { padding: 0.5rem 0.9rem; font-family: Consolas, 'Courier New', monospace; }

.sq-match { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }
.sq-match > div { display: grid; gap: 0.5rem; align-content: start; }
.sq-match .sq-tile { justify-content: center; text-align: center; min-height: 3.2rem; font-family: var(--body); font-size: 0.9rem; }
.sq-match > div:first-child .sq-tile::after { content: '●'; margin-left: auto; color: var(--cyan-dim); }
.sq-match > div:last-child .sq-tile::before { content: '●'; margin-right: auto; color: var(--cyan-dim); }
.sq-tile.matched { border-color: #7cff6b; opacity: 0.5; }
.sq-tile.matched::before, .sq-tile.matched::after { color: #7cff6b !important; }
.sq-tile.nope { border-color: var(--pink); background: rgba(255, 61, 139, 0.15); animation: shake 0.35s; }

.sq-terminal {
  margin-top: 1rem;
  padding: 0.7rem 0.9rem;
  font-family: Consolas, 'Courier New', monospace;
  background: #02040c;
  border: 1px solid var(--cyan-dim);
  border-left: 4px solid;
}
.sq-terminal p { margin: 0.2rem 0; }
.sq-terminal .sq-line { font-weight: 800; letter-spacing: 0.04em; }
.sq-terminal .sq-why { font-family: var(--body); color: var(--text); }
.sq-terminal.good { border-left-color: #7cff6b; }
.sq-terminal.good .sq-line { color: #7cff6b; }
.sq-terminal.bad { border-left-color: var(--pink); }
.sq-terminal.bad .sq-line { color: var(--pink); }
.sq-terminal.bad .sq-solution { color: var(--gold); }
.sq-chain { margin-left: 0.5rem; color: var(--gold); }

@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes blink { 50% { background: rgba(255, 210, 63, 0.4); } }
@media (prefers-reduced-motion: reduce) {
  .sq-shields.hit, .sq-tile.nope, .sq-decrypt span.now { animation: none; }
}
@media (max-width: 520px) { .sq-choices.two, .sq-match { grid-template-columns: 1fr 1fr; gap: 0.6rem; } }

/* ---------- Level 100: the final boss (levels.js, boss.js) ---------- */
.level.final {
  grid-column: 1 / -1;
  justify-self: center;
  flex-direction: row;
  gap: 1rem;
  width: min(360px, 100%);
  height: 84px;
  margin-top: 0.6rem;
  border: 3px solid transparent;
  border-radius: 14px;
  /* animated rainbow-ish border: a gradient behind a dark inner fill */
  background:
    linear-gradient(#12081f, #12081f) padding-box,
    linear-gradient(120deg, #ff2020, #ff3d8b, #c58bff, #ff2020) border-box;
  background-size: 100% 100%, 300% 300%;
  box-shadow: 0 0 24px rgba(255, 32, 80, 0.6), inset 0 0 20px rgba(255, 32, 80, 0.25);
  animation: final-border 3s linear infinite, final-pulse 1.6s ease-in-out infinite;
}
.level.final.locked { opacity: 1; border-style: solid; }
.level.final:hover, .level.final:focus-visible { transform: translateY(-2px) scale(1.03); }
.final-skull { font-size: 2rem; }
.final-text { display: flex; flex-direction: column; align-items: center; }
.final-tag { font-size: 0.72rem; font-weight: 800; color: #ffb3cf; text-transform: uppercase; letter-spacing: 0.1em; }
.final-name {
  font-family: var(--pixel);
  font-size: 1.3rem;
  color: #fff;
  text-shadow: 0 0 10px #ff3d8b, 0 0 22px #ff2020;
  letter-spacing: 0.15em;
}
@keyframes final-border { to { background-position: 0 0, 300% 0; } }
@keyframes final-pulse { 50% { box-shadow: 0 0 40px rgba(255, 32, 80, 0.9), inset 0 0 26px rgba(255, 32, 80, 0.4); } }

.final-confirm h2 { color: #ff3d8b; text-shadow: 0 0 12px rgba(255, 61, 139, 0.7); }
.final-confirm .intro-emoji { animation: final-throb 1.2s ease-in-out infinite; }
@keyframes final-throb { 50% { transform: scale(1.15); } }

#btn-wave.final {
  color: #fff;
  background: linear-gradient(90deg, #ff2020, #ff3d8b, #c58bff);
  box-shadow: 0 3px 0 #7a0f3a, 0 0 18px rgba(255, 32, 80, 0.8);
  animation: final-pulse 1.6s ease-in-out infinite;
}

#board.shake { animation: board-shake 0.5s; }
@keyframes board-shake {
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(6px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 2px); }
}

@media (prefers-reduced-motion: reduce) {
  .level.final, #btn-wave.final, .final-confirm .intro-emoji, #board.shake { animation: none; }
}

/* ---------- Between levels: cleared, new skill, briefing (briefing.js) ---------- */
.cleared-panel { position: relative; overflow: hidden; border-color: var(--gold); box-shadow: 0 0 40px rgba(255, 210, 63, 0.45); }
.cleared-stars { margin: 0; text-align: center; font-size: 2.6rem; letter-spacing: 0.2em; color: #2a3570; }
.cleared-stars .on { color: var(--gold); text-shadow: 0 0 14px rgba(255, 210, 63, 0.8); }
.cleared-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-top: 0.8rem; }
.cleared-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.6rem 0.3rem;
  background: rgba(7, 11, 31, 0.6);
  border: 1px solid var(--cyan-dim);
  border-radius: 8px;
  text-align: center;
}
.cleared-stats strong { font-family: var(--pixel); font-size: 0.9rem; color: var(--cyan); }
.cleared-stats span { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.3rem; }
@media (max-width: 520px) { .cleared-stats { grid-template-columns: 1fr 1fr; } }

.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti span {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall 2s ease-in forwards;
}
@keyframes confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0); }
  100% { opacity: 0; transform: translateY(520px) rotate(540deg); }
}

.skill-panel { border-color: #7cff6b; box-shadow: 0 0 40px rgba(124, 255, 107, 0.3); }
.skill-panel .new-tag { color: #7cff6b; }
.skill-tips { display: grid; gap: 0.35rem; padding-left: 1.2rem; }
.skill-tips li::marker { content: '✔  '; color: #7cff6b; }

.brief-panel { width: min(680px, 94vw); }
.brief-tag {
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.brief-head {
  margin: 1.1rem 0 0.5rem;
  padding-bottom: 0.3rem;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  border-bottom: 1px solid var(--cyan-dim);
}
.brief-vocab { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
@media (max-width: 560px) { .brief-vocab { grid-template-columns: 1fr; } }
.vocab {
  padding: 0.55rem 0.75rem;
  background: rgba(7, 11, 31, 0.6);
  border: 1px solid var(--cyan-dim);
  border-left: 3px solid var(--gold);
  border-radius: 6px;
}
.vocab p { margin: 0; }
.vocab-term { font-weight: 800; color: var(--gold); }
.vocab-def { margin-top: 0.15rem !important; font-size: 0.86rem; color: var(--text-dim); line-height: 1.4; }
.new-word {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--bg);
  background: #7cff6b;
  border-radius: 3px;
  vertical-align: middle;
}

.brief-intel { display: grid; gap: 0.5rem; }
.intel-row {
  padding: 0.55rem 0.8rem;
  background: rgba(7, 11, 31, 0.6);
  border: 1px solid var(--cyan-dim);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
}
.intel-row p { margin: 0; }
.intel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.intel-name { font-weight: 800; color: var(--accent); }
.intel-count { font-family: var(--pixel); font-size: 0.7rem; color: var(--text); }
.intel-row.boss .intel-count { color: var(--pink); }
.intel-counter { font-size: 0.88rem; margin-top: 0.15rem !important; }
.intel-lock {
  margin-left: 0.3rem;
  padding: 0.05rem 0.35rem;
  font-size: 0.68rem;
  font-weight: 800;
  color: #ffb3cf;
  border: 1px solid #ffb3cf;
  border-radius: 3px;
}
.intel-spot { font-size: 0.84rem; color: var(--text-dim); margin-top: 0.15rem !important; line-height: 1.4; }

.brief-know { display: grid; gap: 0.3rem; padding-left: 1.1rem; margin: 0.8rem 0 0; font-size: 0.9rem; color: var(--text-dim); }
.brief-know li::marker { color: var(--cyan); }

@media (prefers-reduced-motion: reduce) { .confetti span { display: none; } }

/* Star breakdown on the Level Cleared screen */
.cleared-stats.scores { display: grid; grid-template-columns: 1fr; gap: 0.45rem; }
.cleared-stats .score-row { display: grid; padding: 0; background: none; border: none; text-align: left; grid-template-columns: 9rem 1fr 5.5rem; align-items: center; gap: 0.7rem; }
.score-label { font-weight: 700; font-size: 0.9rem; }
.score-bar { height: 10px; background: var(--bg); border: 1px solid var(--cyan-dim); border-radius: 5px; overflow: hidden; }
.score-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--gold)); }
.score-detail { font-size: 0.85rem; color: var(--text-dim); text-align: right; }
.score-bytes { margin: 0.3rem 0 0; text-align: center; font-weight: 700; color: var(--gold); }
@media (max-width: 520px) { .score-row { grid-template-columns: 1fr 5rem; } .score-bar { grid-column: 1 / -1; grid-row: 2; } }

/* ---------- Your coder (avatar.js) ---------- */
.hud-left { display: flex; align-items: center; gap: 0.6rem; }
.hud-coder {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--cyan-dim);
  transition: transform 0.12s, border-color 0.12s;
}
.hud-coder:hover, .hud-coder:focus-visible { border-color: var(--gold); transform: translateY(-2px); outline: none; }
.cleared-coder {
  width: 96px;
  height: 96px;
  margin: 0 auto 0.4rem;
  border-radius: 20px;
  overflow: hidden;
  border: 3px solid var(--gold);
  animation: coder-cheer 0.6s ease-in-out 3;
}
@keyframes coder-cheer {
  0%, 100% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(-10px) rotate(-4deg); }
  60% { transform: translateY(0) rotate(4deg); }
}
.score-bank { margin: 0.2rem 0 0; text-align: center; font-size: 0.9rem; color: var(--text-dim); }
.cleared-stats .score-bank strong { font-family: var(--body); font-size: 1rem; color: var(--gold); }
@media (prefers-reduced-motion: reduce) { .cleared-coder { animation: none; } }


/* ---------- Feedback that makes the game feel alive (juice.js) ---------- */
.stat { position: relative; display: inline-block; }
.stat strong { display: inline-block; transition: color 0.2s; }
.stat.gain strong { animation: stat-pop 0.35s ease-out; }
.stat.loss strong { animation: stat-hit 0.35s ease-out; }
@keyframes stat-pop { 40% { transform: scale(1.35); color: #7cff6b; } }
@keyframes stat-hit { 25% { transform: translateX(-3px); color: var(--pink); } 75% { transform: translateX(3px); color: var(--pink); } }
.stat-chip {
  position: absolute;
  right: -0.4rem;
  top: 0;
  font-family: var(--pixel);
  font-size: 0.6rem;
  pointer-events: none;
  animation: chip-float 0.9s ease-out forwards;
}
.stat-chip.gain { color: #7cff6b; }
.stat-chip.loss { color: var(--pink); }
@keyframes chip-float { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-22px); } }

.hud-coder.cheer { animation: coder-hop 0.5s ease-out; border-color: #7cff6b; }
.hud-coder.oops { animation: coder-wobble 0.45s ease-in-out; border-color: var(--pink); }
@keyframes coder-hop { 40% { transform: translateY(-8px) scale(1.12); } }
@keyframes coder-wobble { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

/* The next thing to click glows so new players always know what to do */
.tool.nudge { animation: nudge-glow 1.4s ease-in-out infinite; }
#btn-wave.nudge { animation: nudge-glow-gold 1.2s ease-in-out infinite; }
@keyframes nudge-glow { 50% { border-color: var(--cyan); box-shadow: 0 0 18px rgba(46, 230, 255, 0.7); } }
@keyframes nudge-glow-gold { 50% { box-shadow: 0 3px 0 #b38a00, 0 0 26px rgba(255, 210, 63, 0.9); transform: translateY(-2px); } }

/* A tower bursting open when you unlock it */
.tool.unlocking { animation: unlock-burst 0.8s ease-out; z-index: 1; }
.tool.unlocking .tool-emoji { animation: unlock-spin 0.8s ease-out; }
@keyframes unlock-burst {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(124, 255, 107, 0); }
  30% { transform: scale(1.12); border-color: #7cff6b; box-shadow: 0 0 30px rgba(124, 255, 107, 0.9); }
  100% { transform: scale(1); }
}
@keyframes unlock-spin { 30% { transform: scale(1.4) rotate(-15deg); } 60% { transform: scale(1.2) rotate(10deg); } }

/* Smoother interface: everything eases instead of snapping */
.tool { transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, opacity 0.25s ease; }
.tool-emoji { transition: filter 0.3s ease, opacity 0.3s ease; }
.btn { transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.2s ease; }
.panel::backdrop { animation: backdrop-in 0.2s ease-out; }
@keyframes backdrop-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .stat.gain strong, .stat.loss strong, .stat-chip, .hud-coder.cheer, .hud-coder.oops,
  .tool.nudge, #btn-wave.nudge, .tool.unlocking, .tool.unlocking .tool-emoji { animation: none; }
}

/* Which stars count: your best run on each level (briefing.js) */
.cleared-best {
  margin: 0.4rem auto 0;
  padding: 0.55rem 0.9rem;
  max-width: 30rem;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.5;
  border-radius: 8px;
}
.cleared-best.up { background: rgba(124, 255, 107, 0.1); border: 2px solid rgba(124, 255, 107, 0.5); }
.cleared-best.same { background: rgba(159, 176, 216, 0.08); border: 2px solid #2a3570; color: var(--text-dim); }
.cleared-best strong { color: var(--gold); }
.mini-stars { white-space: nowrap; letter-spacing: 0.05em; color: #3a4a8a; }
.mini-stars .on { color: var(--gold); }

/* Double damage from a secret message (bonus.js) */
.stat.boost {
  padding: 0.1rem 0.6rem;
  color: var(--bg);
  background: var(--gold);
  border-radius: 999px;
  animation: boost-glow 1.2s ease-in-out infinite;
}
@keyframes boost-glow { 50% { box-shadow: 0 0 14px rgba(255, 210, 63, 0.9); } }
@media (prefers-reduced-motion: reduce) { .stat.boost { animation: none; } }

/* ---------- Phones and narrow windows ----------
   The full top bar wrapped onto 5+ rows and pushed the towers off screen.
   Here it packs into 3 short rows: small buttons, then the stats, then Blast / Levels / Start Wave.
   The towers sit in one row you swipe sideways, so the whole game fits on a phone screen.
   The page can still scroll if a window is very short (like a phone turned sideways). */
@media (max-width: 700px), (max-height: 560px) {
  .controls { flex-wrap: wrap; justify-content: flex-end; }
  html:has(body.td) { overflow: auto; }
  body.td { height: auto; min-height: 100vh; min-height: 100dvh; }
  body.td .hud { gap: 0.35rem; padding: 0.4rem 0.5rem; justify-content: flex-start; }
  body.td .hud-left, body.td .controls { display: contents; }
  body.td .hud .btn-small { padding: 0.45rem 0.55rem; font-size: 0.6rem; }
  body.td .hud-coder { width: 32px; height: 32px; }
  /* Row 1: Menu, coder, then the small icon buttons on the right */
  body.td #btn-how { margin-left: auto; }
  /* Row 2: stats */
  body.td .stats { order: 1; flex-basis: 100%; justify-content: center; gap: 0.2rem 0.8rem; font-size: 0.8rem; }
  body.td .stat strong { font-size: 0.7rem; margin-left: 0.2rem; }
  /* Row 3: the big actions */
  body.td #btn-blast, body.td #btn-levels, body.td #btn-wave { order: 2; }
  body.td #btn-wave { flex: 1; white-space: normal; line-height: 1.4; }
  body.td .board { flex: none; padding: 0.4rem; }
  body.td #board { width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 1.2rem); }
  body.td .tower-bar { flex-wrap: nowrap; justify-content: flex-start; gap: 0.4rem; padding: 0.5rem; overflow-x: auto; scroll-snap-type: x proximity; }
  body.td .tool { flex: 0 0 auto; width: 158px; min-width: 0; padding: 0.4rem 0.5rem; scroll-snap-align: start; }
  body.td .tool-emoji { font-size: 1.4rem; }
  body.td .tool-name { font-size: 0.82rem; }
  body.td .tool-cost { font-size: 0.78rem; }
  body.td .tool-beats { font-size: 0.7rem; }
}
