/* =========================================================
   KidTyping VN – Kid-friendly stylesheet
   ========================================================= */

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --sky:    #38bdf8;
  --sun:    #fbbf24;
  --green:  #22c55e;
  --red:    #ef4444;
  --bg:     #f0f9ff;
  --card:   #ffffff;
  --text:   #1e293b;
  --muted:  #64748b;
  --radius: 1.25rem;
  --shadow: 0 4px 24px rgba(0,0,0,.08);
  --font:   'Nunito', 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 1rem;
}

/* ---------- Header (app navigation bar) ---------- */
.app-header {
  width: min(960px, calc(100vw - 2rem));
  max-width: min(960px, calc(100vw - 2rem));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  position: relative;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--sky);
  white-space: nowrap;
}
.brand-name { letter-spacing: -.3px; }
.header-nav {
  display: flex;
  gap: .5rem;
}
.nav-btn {
  padding: .4rem 1rem;
  border: 2px solid transparent;
  border-radius: 99px;
  background: transparent;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: all .18s;
}
.nav-btn.active,
.nav-btn:hover {
  border-color: var(--sky);
  color: var(--sky);
}
.header-user { position: relative; display: flex; align-items: center; gap: .5rem; }
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 2px solid var(--sky);
  border-radius: 12px;
  background: transparent;
  color: var(--sky);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font);
  transition: all .18s;
}
.nav-toggle:hover { background: var(--sky); color: #fff; }
.nav-toggle.open { background: var(--sky); color: #fff; }
.user-pill {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .4rem 1rem;
  background: var(--sky);
  color: #fff;
  border: none;
  border-radius: 99px;
  font-size: .9rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: filter .15s;
  max-width: 200px;
}
.user-pill:hover { filter: brightness(1.1); }
.user-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 110px;
}
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
  padding: .5rem;
  min-width: 200px;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.user-menu button {
  width: 100%;
  padding: .55rem 1rem;
  background: transparent;
  border: none;
  border-radius: .5rem;
  text-align: left;
  font-size: .9rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s;
  color: var(--text);
}
.user-menu button:hover { background: #f0f9ff; }
.menu-divider { height: 1px; background: #e2e8f0; margin: .3rem 0; }

/* ---------- Level selector ---------- */
.levels {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 1.75rem;
}
.levels button {
  padding: .55rem 1.4rem;
  border: 2px solid var(--sky);
  border-radius: 99px;
  background: transparent;
  color: var(--sky);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .18s, color .18s, transform .1s;
}
.levels button.active,
.levels button:hover {
  background: var(--sky);
  color: #fff;
}
.levels button:active { transform: scale(.96); }

/* ---------- Main card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  width: min(960px, calc(100vw - 2rem));
  max-width: min(960px, calc(100vw - 2rem));
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ---------- Target display ---------- */
.target-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: .4rem;
}
#target-text {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--text);
  min-height: 3.5rem;
  word-break: break-word;
  transition: opacity .3s;
}
#target-text.fade-out { opacity: 0; }
#target-text.fade-in  { opacity: 1; }

/* ---------- Input area ---------- */
#typing-input {
  width: 100%;
  min-height: 110px;
  resize: none;
  font-size: 1.6rem;
  font-family: var(--font);
  font-weight: 600;
  padding: 1rem 1.2rem;
  border: 3px solid #cbd5e1;
  border-radius: var(--radius);
  background: #f8fafc;
  color: var(--text);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#typing-input:focus           { border-color: var(--sky); box-shadow: 0 0 0 4px #bae6fd55; }
#typing-input.correct         { border-color: var(--green); box-shadow: 0 0 0 4px #bbf7d055; }
#typing-input.incorrect       { border-color: var(--red);   box-shadow: 0 0 0 4px #fecaca55; }

/* ---------- Feedback message ---------- */
#feedback {
  min-height: 2rem;
  font-size: 1.3rem;
  font-weight: 800;
  text-align: center;
  transition: opacity .25s;
}
#feedback.correct   { color: var(--green); }
#feedback.incorrect { color: var(--red);   }
#feedback.hidden    { opacity: 0; }

/* ---------- Action buttons ---------- */
.actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.btn {
  padding: .75rem 2rem;
  border: none;
  border-radius: 99px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.96); }
.btn-sky    { background: var(--sky); color: #fff; }
.btn-sky:hover { filter: brightness(1.08); }
.btn-sun    { background: var(--sun); color: #1e293b; }
.btn-sun:hover { filter: brightness(1.08); }

/* ---------- Score counter ---------- */
.score-row {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem;
  font-size: .9rem;
  color: var(--muted);
  font-weight: 600;
}
.score-row span { color: var(--text); }
.score-wpm-highlight { color: var(--green) !important; font-weight: 800; }

/* ---------- Hint (inline progress bar) ---------- */
.progress-bar-wrap {
  height: 6px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--sky), var(--green));
  border-radius: 99px;
  transition: width .2s ease;
}

/* ---------- Footer ---------- */
footer {
  margin-top: 2.5rem;
  color: var(--muted);
  font-size: .8rem;
}

/* ---------- Page containers ---------- */
#page-home {
  width: min(960px, calc(100vw - 2rem));
  max-width: min(960px, calc(100vw - 2rem));
}
#page-rank {
  width: min(960px, calc(100vw - 2rem));
  max-width: min(960px, calc(100vw - 2rem));
}

/* ---------- Modal ---------- */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem;
  width: 90%;
  max-width: 400px;
  position: relative;
  box-shadow: 0 16px 48px rgba(0,0,0,.2);
}
.modal-close {
  position: absolute;
  top: .9rem;
  right: .9rem;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: .3rem .5rem;
  border-radius: 50%;
  line-height: 1;
  transition: background .15s;
}
.modal-close:hover { background: #f1f5f9; }
.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 1.1rem;
  color: var(--text);
}
.modal-field {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: .85rem;
}
.modal-field label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.modal-field input {
  padding: .65rem 1rem;
  border: 2px solid #cbd5e1;
  border-radius: .75rem;
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color .2s;
}
.modal-field input:focus { border-color: var(--sky); }
.modal-error {
  color: var(--red);
  font-size: .88rem;
  font-weight: 600;
  margin-bottom: .7rem;
  min-height: 1.2rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
}
.modal-hint {
  font-size: .82rem;
  color: var(--muted);
  margin-top: .8rem;
  text-align: center;
}
.modal-hint a {
  color: var(--sky);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}
.modal-hint a:hover { text-decoration: underline; }

/* ---------- Ranking page ---------- */
.rank-game-switch {
  display: flex;
  gap: .4rem;
  justify-content: center;
  background: #eef2f7;
  border-radius: 999px;
  padding: .3rem;
  width: fit-content;
  margin: 0 auto 1rem;
}
.rank-game-btn {
  padding: .42rem 1.2rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: .9rem;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  transition: all .18s;
}
.rank-game-btn.active {
  background: #fff;
  color: var(--sky);
  box-shadow: 0 2px 8px rgba(15,23,42,.12);
}
.rank-tabs {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 1.25rem;
}
.rank-tab {
  padding: .42rem 1.1rem;
  border: 2px solid var(--sky);
  border-radius: 99px;
  background: transparent;
  color: var(--sky);
  font-size: .88rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: all .18s;
}
.rank-tab.active {
  background: var(--sky);
  color: #fff;
}
.rank-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.rank-table {
  width: 100%;
  border-collapse: collapse;
}
.rank-table th {
  padding: .7rem 1.2rem;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  text-align: left;
}
.rank-table td {
  padding: .8rem 1.2rem;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid #f1f5f9;
}
.rank-table tr:last-child td { border-bottom: none; }
.rank-table tr.current-user  { background: #f0f9ff; }
.rank-medal  { font-size: 1.1rem; }
.rank-score  { font-weight: 800; color: var(--sky); }
.rank-empty  { text-align: center; padding: 3rem 1rem; color: var(--muted); font-size: 1rem; }

/* ---------- Firework overlay ---------- */
#firework-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  display: none;
}

/* ---------- Shake animation (incorrect answer) ---------- */
@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  15%       { transform: translateX(-8px) rotate(-2deg); }
  35%       { transform: translateX(8px)  rotate(2deg); }
  55%       { transform: translateX(-5px) rotate(-1deg); }
  75%       { transform: translateX(5px)  rotate(1deg); }
}
.shake { animation: shake .45s ease; }

.bow-game-topbar {
  display: flex;
  gap: .75rem;
  align-self: flex-start;
}
.bow-miss-msg {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--red);
  text-align: center;
  animation: fadeInOut 1.5s ease forwards;
}
@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateY(-6px); }
  20%  { opacity: 1; transform: translateY(0); }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Games nav dropdown ---------- */
.nav-games-wrap {
  position: relative;
}
.games-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
  padding: .5rem;
  min-width: 180px;
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.games-dd-item {
  width: 100%;
  padding: .6rem 1.1rem;
  background: transparent;
  border: none;
  border-radius: .5rem;
  text-align: left;
  font-size: .95rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s;
  color: var(--text);
}
.games-dd-item:hover { background: #f0f9ff; color: var(--sky); }

/* ---------- TELEX guide ---------- */
.telex-guide {
  width: min(960px, calc(100vw - 2rem));
  max-width: min(960px, calc(100vw - 2rem));
  margin: 1.25rem auto 0;
  background: var(--card);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: .25rem 1.25rem;
}
.telex-guide > summary {
  cursor: pointer;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  padding: .85rem .25rem;
  list-style: none;
  user-select: none;
}
.telex-guide > summary::-webkit-details-marker { display: none; }
.telex-guide > summary::before { content: '▸ '; color: var(--sky); }
.telex-guide[open] > summary::before { content: '▾ '; }
.telex-hint { font-weight: 600; font-size: .82rem; color: var(--muted); }
.telex-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: .25rem 0 .75rem;
}
.telex-card { background: var(--bg, #f1f5ff); border-radius: .75rem; padding: .75rem 1rem; }
.telex-card h4 { margin: 0 0 .5rem; font-size: .92rem; color: var(--text); }
.telex-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.telex-table th {
  text-align: left;
  font-size: .76rem;
  color: var(--muted);
  font-weight: 700;
  padding: .2rem .4rem;
  border-bottom: 2px solid #e2e8f0;
}
.telex-table td { padding: .28rem .4rem; color: var(--text); border-bottom: 1px solid #eef2f7; }
.telex-table kbd {
  display: inline-block;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-bottom-width: 2px;
  border-radius: .35rem;
  padding: .05rem .4rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .82rem;
  color: var(--sky);
  font-weight: 700;
}
.telex-examples { font-size: .9rem; color: var(--text); margin: .25rem 0; line-height: 1.7; }
.telex-note { font-size: .82rem; color: var(--muted); margin: .25rem 0 .75rem; }
@media (max-width: 560px) {
  .telex-grid { grid-template-columns: 1fr; }
}

/* ---------- Bow game page ---------- */
#page-bowgame {
  width: min(1060px, calc(100vw - 2rem));
  max-width: min(1060px, calc(100vw - 2rem));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.game-back-btn {
  align-self: flex-start;
  padding: .4rem 1.1rem;
  border: 2px solid var(--sky);
  border-radius: 99px;
  background: transparent;
  color: var(--sky);
  font-size: .88rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: all .18s;
}
.game-back-btn:hover { background: var(--sky); color: #fff; }
.game-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
}
#bow-game-canvas {
  border-radius: 1rem;
  box-shadow: var(--shadow);
  display: block;
  max-width: 100%;
  background: #1a1a2e;
}
.bow-ui-panel {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
  font-size: .95rem;
  font-weight: 700;
  color: var(--muted);
  width: 100%;
}
.bow-ui-panel span { color: var(--text); }
.power-bar-wrap {
  flex: 1;
  min-width: 160px;
  max-width: 280px;
  height: 16px;
  background: #e2e8f0;
  border-radius: 99px;
  overflow: hidden;
}
#bow-power-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 99px;
  transition: background .1s;
}
.bow-controls-hint {
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}

/* ---------- Bow game on-screen touch controls ---------- */
.bow-touch-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: .6rem 1.1rem;
  width: 100%;
  touch-action: none;
}
.bow-touch-cluster {
  display: flex;
  gap: .5rem;
}
.bow-touch-btn,
.bow-touch-fire {
  font-family: var(--font);
  font-weight: 800;
  border-radius: 99px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: transform .08s, background .15s, color .15s;
}
.bow-touch-btn {
  min-width: 64px;
  padding: .7rem 1rem;
  font-size: 1.1rem;
  border: 2px solid var(--sky);
  background: #fff;
  color: var(--sky);
}
.bow-touch-btn:hover { background: var(--sky); color: #fff; }
.bow-touch-btn:active { transform: scale(.92); background: var(--sky); color: #fff; }
.bow-touch-fire {
  padding: .8rem 1.6rem;
  font-size: 1.2rem;
  border: none;
  background: var(--sun, #fbbf24);
  color: #1e293b;
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.bow-touch-fire:active,
.bow-touch-fire.charging {
  transform: scale(.95) translateY(2px);
  background: #ef4444;
  color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.18);
}

/* ---------- Bow Game v2 (Math Quest) ---------- */
#page-bowgame2 {
  width: min(1060px, calc(100vw - 2rem));
  max-width: min(1060px, calc(100vw - 2rem));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  position: relative;
}
#bow2-game-canvas {
  border-radius: 1rem;
  box-shadow: var(--shadow);
  display: block;
  max-width: 100%;
  background: #1a1a2e;
}
.bow2-play-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.bow2-math-panel {
  width: 100%;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .85rem;
}
.bow2-question-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.bow2-q-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}
.bow2-question-text {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: .5px;
  min-width: 220px;
  text-align: center;
}
.bow2-input-row {
  display: flex;
  gap: .75rem;
  align-items: center;
}
.bow2-answer-input {
  width: 130px;
  padding: .55rem 1rem;
  font-size: 1.6rem;
  font-weight: 800;
  font-family: var(--font);
  border: 3px solid var(--sky);
  border-radius: .75rem;
  text-align: center;
  color: var(--text);
  outline: none;
  transition: border-color .15s, background .15s;
  -moz-appearance: textfield;
}
.bow2-answer-input::-webkit-inner-spin-button,
.bow2-answer-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.bow2-answer-input:focus { border-color: var(--sun); }
.bow2-answer-input.correct { border-color: var(--green); background: #f0fdf4; }
.bow2-answer-input.incorrect { border-color: var(--red); background: #fff1f2; }
.bow2-feedback {
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 1.6rem;
  text-align: center;
}
.bow2-feedback.correct   { color: var(--green); }
.bow2-feedback.incorrect { color: var(--red);   }
.bow2-stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
  font-size: .9rem;
  font-weight: 700;
  color: var(--muted);
}
.bow2-stats span { color: var(--text); }

/* ---------- Bow Game v2 on-screen numeric keypad (touch) ---------- */
.bow2-keypad { display: none; }
body.kt-touch .bow2-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  width: min(330px, 94%);
  margin: .7rem auto 0;
}
.bow2-key {
  font-family: var(--font);
  font-weight: 800;
  font-size: 1.5rem;
  border: 2px solid #cbd5e1;
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  padding: .5rem 0;
  min-height: 54px;
  cursor: pointer;
  box-shadow: 0 3px 0 #cbd5e1;
  transition: transform .06s, box-shadow .06s, background .1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.bow2-key:active { transform: translateY(3px); box-shadow: 0 0 0 #cbd5e1; background: #e0f2fe; }
.bow2-key-del { color: var(--red); border-color: #fecaca; box-shadow: 0 3px 0 #fecaca; }
.bow2-key-fire { background: var(--green); border-color: var(--green); color: #fff; box-shadow: 0 3px 0 #15803d; }
.bow2-key-fire:active { background: #16a34a; box-shadow: 0 0 0 #15803d; }
.bow2-key:disabled { opacity: .45; box-shadow: none; cursor: default; }
/* On touch the keypad is the input method: hide the standalone button, tame the field */
body.kt-touch #bow2-submit-btn { display: none; }
body.kt-touch .bow2-answer-input { text-align: center; caret-color: transparent; width: 150px; }

/* ---------- Bow Game v2 stats collapse (mobile) ---------- */
.bow2-stats-toggle { display: none; }
@media (max-width: 640px) {
  .bow2-stats-toggle {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    margin: .6rem auto 0;
    border: 2px solid #cbd5e1;
    background: var(--card);
    color: var(--text);
    border-radius: 999px;
    padding: .4rem 1rem;
    font-family: var(--font);
    font-weight: 700;
    font-size: .9rem;
    cursor: pointer;
  }
  .bow2-stats { display: none; }
  .bow2-stats.show { display: flex; }
}

/* ---------- Bow Game v2 landscape: canvas + keypad side-by-side ---------- */
@media (orientation: landscape) and (max-height: 600px) {
  /* Reclaim vertical space while playing v2: hide the global chrome */
  body.kt-bow2-active > header,
  body.kt-bow2-active > footer { display: none; }
  body.kt-bow2-active { padding: 0; }

  #page-bowgame2 { width: 100vw; max-width: 100vw; gap: .3rem; padding: .3rem .4rem 0; }
  #page-bowgame2 > .game-title,
  #page-bowgame2 > .bow2-diffpanel { display: none; }
  .bow-game-topbar { align-self: center; }
  .game-back-btn { padding: .3rem .7rem; font-size: .85rem; }
  .bow2-play-area {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: .7rem;
  }
  #bow2-game-canvas {
    flex: 0 1 auto;
    width: auto;
    height: auto;
    max-width: 56%;
    max-height: calc(100dvh - 52px);
  }
  .bow2-math-panel {
    flex: 1 1 0;
    min-width: 0;
    padding: .45rem .6rem;
    gap: .25rem;
    max-height: calc(100dvh - 52px);
    overflow-y: auto;
  }
  .bow2-question-text { font-size: 1.25rem; }
  .bow2-q-label { font-size: .8rem; }
  .bow2-feedback { font-size: .85rem; min-height: .9rem; }
  body.kt-touch .bow2-keypad { width: 100%; gap: .3rem; margin-top: .3rem; }
  .bow2-key { min-height: 34px; font-size: 1.05rem; padding: .2rem 0; box-shadow: 0 2px 0 #cbd5e1; }
  .bow2-key-del { box-shadow: 0 2px 0 #fecaca; }
  .bow2-key-fire { box-shadow: 0 2px 0 #15803d; }
  .bow2-stats-toggle, .bow2-stats { display: none; }
}

/* ---------- Bow Game v2 per-operation difficulty panel ---------- */
.bow2-diffpanel {
  width: min(640px, 96%);
  background: var(--card);
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  padding: .35rem .9rem;
}
.bow2-diffpanel > summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
  list-style: none;
  padding: .35rem 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem .6rem;
}
.bow2-diffpanel > summary::-webkit-details-marker { display: none; }
.bow2-diffpanel > summary::before { content: '▸'; color: var(--sky); transition: transform .15s; }
.bow2-diffpanel[open] > summary::before { transform: rotate(90deg); }
.bow2-diff-summary { font-weight: 600; font-size: .8rem; color: var(--muted); }
.bow2-diff-presets {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: .4rem .5rem; margin: .5rem 0;
}
.bow2-diff-label { font-weight: 800; color: var(--text); font-size: .9rem; }
.bow2-preset-btn {
  border: 2px solid #cbd5e1; background: var(--bg); color: var(--text);
  border-radius: 999px; padding: .3rem .8rem;
  font-family: var(--font); font-weight: 700; font-size: .85rem; cursor: pointer;
  transition: transform .1s, border-color .1s, background .1s;
}
.bow2-preset-btn:hover { transform: translateY(-1px); border-color: var(--sun); }
.bow2-op-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .5rem;
}
.bow2-op-card {
  border: 2px solid #e2e8f0; border-radius: 12px;
  padding: .4rem .5rem;
  display: flex; flex-direction: column; gap: .35rem;
  background: var(--bg);
  transition: border-color .12s, opacity .12s;
}
.bow2-op-card.off { opacity: .5; }
.bow2-op-toggle {
  border: 2px solid var(--green); background: var(--green); color: #fff;
  border-radius: 999px; padding: .25rem .6rem;
  font-family: var(--font); font-weight: 800; font-size: .92rem; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.bow2-op-card.off .bow2-op-toggle {
  background: var(--card); color: var(--muted); border-color: #cbd5e1;
  text-decoration: line-through;
}
.bow2-op-levels { display: flex; gap: .3rem; }
.bow2-op-lvl {
  flex: 1; border: 2px solid #cbd5e1; background: var(--card); color: var(--text);
  border-radius: 8px; padding: .25rem 0;
  font-family: var(--font); font-weight: 700; font-size: .82rem; cursor: pointer;
  transition: background .1s, border-color .1s, color .1s;
}
.bow2-op-lvl:hover { border-color: var(--sky); }
.bow2-op-lvl.active {
  background: var(--sky); border-color: var(--sky); color: #fff;
  box-shadow: 0 2px 8px rgba(56,189,248,.3);
}
.bow2-diff-hint { margin: .55rem 0 .2rem; font-size: .78rem; color: var(--muted); text-align: center; }
@media (max-width: 560px) {
  .bow2-op-grid { grid-template-columns: 1fr; }
  .bow2-op-toggle { font-size: .85rem; }
}

/* ---------- Bow Game v2 upgrade overlay (Archero-style) ---------- */
.bow2-upgrade-overlay {
  position: absolute;
  top: 0; left: 0; right: 0;
  /* cover the canvas area (canvas is 500px tall, scales down responsively) */
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  background: rgba(6, 10, 25, 0.82);
  backdrop-filter: blur(3px);
  border-radius: 1rem;
  z-index: 30;
}
.bow2-upgrade-overlay.hidden { display: none; }
.bow2-upgrade-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: #fde68a;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.bow2-upgrade-cards {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.bow2-upgrade-card {
  width: 180px;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 1.2rem 1rem;
  border-radius: 1rem;
  border: 3px solid rgba(255,255,255,.18);
  background: linear-gradient(160deg, #1e293b, #0f172a);
  color: #fff;
  cursor: pointer;
  font-family: var(--font);
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.bow2-upgrade-card:hover,
.bow2-upgrade-card:focus-visible {
  transform: translateY(-6px) scale(1.04);
  border-color: #fbbf24;
  box-shadow: 0 10px 28px rgba(251,191,36,.35);
  outline: none;
}
.bow2-upgrade-card.up-power   { border-color: rgba(248,113,113,.5); }
.bow2-upgrade-card.up-crit    { border-color: rgba(250,204,21,.5); }
.bow2-upgrade-card.up-critdmg { border-color: rgba(168,85,247,.5); }
.bow2-upgrade-card .uc-icon { font-size: 2.6rem; line-height: 1; }
.bow2-upgrade-card .uc-name { font-size: 1.05rem; font-weight: 800; text-align: center; }
.bow2-upgrade-card .uc-desc { font-size: .85rem; color: #cbd5e1; text-align: center; }
@media (max-width: 560px) {
  .bow2-upgrade-overlay { padding: .75rem; gap: .6rem; }
  .bow2-upgrade-title { font-size: 1rem; }
  .bow2-upgrade-cards { gap: .5rem; }
  .bow2-upgrade-card { width: 30%; min-width: 92px; min-height: 120px; padding: .6rem .35rem; border-width: 2px; }
  .bow2-upgrade-card .uc-icon { font-size: 1.7rem; }
  .bow2-upgrade-card .uc-name { font-size: .8rem; }
  .bow2-upgrade-card .uc-desc { font-size: .68rem; }
}

/* ---------- Responsive tweaks ---------- */
@media (max-width: 560px) {
  .card { padding: 1.5rem 1rem; }
  #typing-input { font-size: 1.2rem; }
  .app-header { gap: .5rem; flex-wrap: nowrap; margin-bottom: 1rem; }
  .brand-name { display: inline; font-size: 1.05rem; }

  /* Collapse the nav behind a hamburger to declutter the portrait header */
  .nav-toggle { display: inline-flex; }
  .header-nav {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: .25rem;
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 8px 32px rgba(0,0,0,.16);
    padding: .5rem;
    min-width: 210px;
    z-index: 120;
    display: none;
  }
  .header-nav.open { display: flex; }
  .header-nav .nav-btn {
    width: 100%;
    text-align: left;
    border-radius: .6rem;
    padding: .6rem .9rem;
    font-size: .95rem;
  }
  .header-nav .nav-btn.active,
  .header-nav .nav-btn:hover { background: #f0f9ff; border-color: transparent; }
  /* Games submenu renders inline inside the panel (no floating dropdown) */
  .nav-games-wrap { position: static; width: 100%; }
  .games-dropdown {
    position: static;
    box-shadow: none;
    padding: .15rem 0 .15rem .75rem;
    min-width: 0;
    background: transparent;
  }
  .games-dropdown.hidden { display: none; }

  #bow-game-canvas { width: 100%; height: auto; }
  #bow2-game-canvas { width: 100%; height: auto; }
  .bow2-question-text { font-size: 1.6rem; }
  .bow2-answer-input { width: 100px; font-size: 1.3rem; }
  .bow-touch-controls { gap: .5rem .7rem; }
  .bow-touch-btn { min-width: 56px; padding: .65rem .7rem; font-size: 1rem; }
  .bow-touch-fire { width: 100%; padding: .9rem; font-size: 1.15rem; }
}
