:root {
  --bg: #0d0e18;
  --panel: #1a1c2c;
  --panel2: #29366f;
  --card: #333c57;
  --card-hi: #566c86;
  --txt: #f4f4f4;
  --muted: #94b0c2;
  --gold: #ffcd75;
  --ok: #38b764;
  --bad: #b13e53;
  --blue: #3b5dc9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--txt);
  font-family: 'Press Start 2P', 'Courier New', monospace;
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
}

#app {
  max-width: 900px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Нижняя зона: доска слов + меню/победа. Бой сверху всегда виден. */
#stage {
  position: relative;
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

/* ---------- Бой ---------- */
#battle {
  position: relative;
  width: min(100%, calc(40dvh * 320 / 150));
  max-height: 40dvh;
  aspect-ratio: 320 / 150;
  margin: 0 auto;
  flex: 0 0 auto;
  overflow: hidden;
  box-shadow: 0 4px 0 #000;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#hud {
  position: absolute;
  inset: 0;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  font-size: 9px;
  text-shadow: 2px 2px 0 #000;
}

.side { display: flex; flex-direction: column; gap: 4px; width: 34%; }
.side.mon { align-items: flex-end; text-align: right; }
.side.mon.off { visibility: hidden; }
.center { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.menu-adv { margin: 0 0 8px !important; }
.menu-meta { margin: 6px 0 4px !important; }
.menu-warn { color: #ff5a6e !important; }

.bar {
  width: 100%;
  max-width: 170px;
  height: 10px;
  background: #1a1c2c;
  box-shadow: 0 0 0 2px #000;
}
.bar > i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--ok);
  transition: width .2s steps(6);
}
.side.mon .bar.hp > i { background: var(--bad); margin-left: auto; }
.bar.atk { height: 5px; max-width: 110px; }
.bar.atk > i { background: var(--gold); width: 0; transition: none; margin-left: auto; }
.val { font-size: 8px; color: var(--muted); }
#combo { color: var(--gold); font-size: 9px; min-height: 9px; }

.hud-acts { display: flex; gap: 6px; justify-content: center; pointer-events: auto; }
#menu-btn, #settings-btn {
  pointer-events: auto;
  font: inherit;
  font-size: 8px;
  color: var(--txt);
  background: var(--card);
  border: none;
  padding: 5px 7px;
  cursor: pointer;
  box-shadow: 0 0 0 2px #000, inset -2px -2px 0 #1a1c2c, inset 2px 2px 0 var(--card-hi);
  line-height: 1;
}
#settings-btn { font-size: 11px; padding: 4px 7px; }
#streak-label {
  font-size: 7px;
  color: var(--gold);
  text-align: center;
  line-height: 1.35;
  max-width: 42vw;
  text-shadow: 1px 1px 0 #000;
}
#pause-tag {
  margin-top: 4px;
  font-size: 7px;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
}
#pause-tag.hidden { display: none; }

/* ---------- Босс и уведомления ---------- */
#boss-warning {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  background: rgba(40, 0, 10, 0.72);
  pointer-events: auto;
}
#boss-warning.hidden { display: none; }
.bw-title {
  font-size: clamp(18px, 5vw, 36px);
  color: #ff004d;
  text-align: center;
  text-shadow: 4px 4px 0 #000, -2px -2px 0 #000;
  animation: bossBlink .5s steps(2) infinite, bossZoom .6s steps(6);
}
.bw-name { font-size: clamp(10px, 2vw, 16px); color: var(--gold); text-shadow: 3px 3px 0 #000; text-align: center; }
.bw-hint {
  margin: 0;
  max-width: 320px;
  padding: 0 8px;
  font-size: clamp(7px, 1.8vw, 9px);
  line-height: 1.6;
  color: #a6f0ff;
  text-align: center;
  text-shadow: 2px 2px 0 #000;
}
.bw-acts {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: min(280px, 90%);
  margin-top: 6px;
}
.bw-acts .btn { width: 100%; min-width: 0; font-size: 9px; padding: 10px 12px; }
@keyframes bossBlink { 50% { color: #ffcd75; } }
@keyframes bossZoom { from { transform: scale(2.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#toast {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translate(-50%, 20px);
  z-index: 12;
  max-width: calc(100% - 16px);
  padding: 8px 12px;
  font-size: 9px;
  line-height: 1.5;
  color: var(--gold);
  background: #1a1c2c;
  box-shadow: 0 0 0 3px #000, inset 2px 2px 0 #333c57;
  opacity: 0;
  pointer-events: none;
  white-space: normal;
  text-align: center;
  transition: opacity .2s steps(3), transform .2s steps(3);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.hidden { display: none; }

.pips { position: absolute; left: 7px; bottom: 5px; display: flex; gap: 3px; }
.pips i { width: 6px; height: 6px; background: #1a1c2c; box-shadow: 0 0 0 1px #000; }
.pips i.on { background: #a7f070; }
.pips.done i { background: var(--gold); }
.pips.review i.on { background: #73eff7; }
.pips.review.done i { background: #41a6f6; }

.mastery { margin: 10px auto; max-width: 320px; font-size: 8px; color: var(--muted); }
.mastery .mbar { height: 8px; margin-top: 6px; background: #0d0e18; box-shadow: 0 0 0 2px #000; }
.mastery .mbar i { display: block; height: 100%; background: var(--gold); }
.boss-next {
  color: #ff5a6e;
  font-size: 12px;
  margin: 8px 0 4px;
  text-shadow: 2px 2px 0 #000;
  line-height: 1.45;
}

/* ---------- Обучение ---------- */
#train-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  font-size: 8px;
  line-height: 1.6;
  color: #a6f0ff;
  background: #29366f;
  box-shadow: inset 0 -3px 0 #1a1c2c;
  flex: none;
}
#train-bar.hidden { display: none; }

#mode-bar {
  padding: 6px 14px;
  font-size: 8px;
  line-height: 1.6;
  text-align: center;
  color: var(--muted);
  background: #1a1c2c;
  box-shadow: inset 0 3px 0 #0d0e18;
  flex: none;
}
#mode-bar.hidden { display: none; }

.toggles { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 12px; }
.btn.toggle { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; }
.btn.toggle .box {
  flex: none;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #1a1c2c;
  background: #0d0e18;
  box-shadow: 0 0 0 2px #000;
}
.btn.toggle.on .box { background: #a7f070; }
.btn.toggle .tl { display: flex; flex-direction: column; gap: 4px; }
.btn.toggle small { font-size: 7px; color: var(--muted); }

.col.quiz { display: none; }
#board.quiz-mode #col-bg, #board.quiz-mode #col-ru { display: none; }
#board.quiz-mode .col.quiz { display: flex; min-height: 0; height: 100%; }
#board.quiz-mode #quiz-opts {
  height: 100%;
}
#board.quiz-mode #quiz-opts .card {
  flex: 1 1 0%;
  max-height: none;
  min-height: 0;
}
#board.quiz-mode #quiz-left {
  height: 100%;
}
.card.prompt {
  flex: 1 1 0%;
  max-height: none;
  min-height: 0;
  font-size: 20px;
  cursor: default;
  background: #29366f;
}
.card.prompt .lang { position: absolute; top: 7px; left: 9px; font-size: 7px; color: #a6f0ff; }
#train-bar b { color: var(--gold); font-weight: normal; }
#train-bar .btn { min-width: 0; flex: none; }

.teacher-portrait { width: 96px; height: 96px; image-rendering: pixelated; }
.quote { font-style: normal; color: #a6f0ff; }

/* ---------- Доска слов ---------- */
#board {
  flex: 1 1 0%;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
  background: var(--panel);
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.02) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.02) 75%),
    linear-gradient(45deg, rgba(255,255,255,.02) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.02) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}

.col { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.col h3 {
  margin: 0 0 2px;
  font-size: 9px;
  font-weight: normal;
  text-align: center;
  color: var(--muted);
  letter-spacing: 1px;
}

.card {
  flex: 1;
  min-height: 44px;
  max-height: 72px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
  color: var(--txt);
  background: var(--card);
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 0 0 3px #000, inset -4px -4px 0 #1a1c2c, inset 4px 4px 0 var(--card-hi);
}
.card .w { text-align: center; word-break: break-word; }
.card:hover { background: #3f4a6b; }
@media (hover: none) {
  .card:hover { background: var(--card); }
  .card.sel:hover { background: var(--blue); }
  .btn:hover:not(:disabled) { background: var(--card); }
  .btn.primary:hover { background: var(--ok); }
  .tile:hover:not(:disabled) { background: #0d0e18; }
}
.card:active { transform: translateY(2px); }
.card.sel {
  background: var(--blue);
  box-shadow: 0 0 0 3px #fff, inset -4px -4px 0 #29366f, inset 4px 4px 0 #41a6f6;
}
.card.ok {
  background: var(--ok);
  box-shadow: 0 0 0 3px #000, inset -4px -4px 0 #257179, inset 4px 4px 0 #a7f070;
  animation: fadeOut .35s steps(4) forwards;
}
.card.bad {
  background: var(--bad);
  box-shadow: 0 0 0 3px #000, inset -4px -4px 0 #5d275d, inset 4px 4px 0 #ef7d57;
  animation: shake .3s steps(6);
}
.card.empty {
  background: transparent;
  box-shadow: inset 0 0 0 2px #29366f;
  cursor: default;
}
.card.appear { animation: pop .25s steps(4); }

.pow {
  position: absolute;
  top: 5px;
  right: 7px;
  font-size: 7px;
  color: var(--muted);
}
.pow.new { color: var(--gold); }
.pow.mid { color: #ef7d57; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; transform: scale(0.9); }
}

/* ---------- Экраны (нижняя зона под боем) ---------- */
#overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
  background: rgba(13, 14, 24, 0.94);
}
#overlay.hidden { display: none; }
#overlay.full {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: rgba(13, 14, 24, 0.82);
}

.panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: none;
  max-height: none;
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 14px;
  text-align: center;
  background: var(--panel);
  box-shadow: inset -3px -3px 0 #0d0e18, inset 3px 3px 0 var(--panel2);
}
#overlay:not(.full) .panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
}
#overlay:not(.full) .panel .btns {
  margin-top: 12px;
  margin-bottom: 8px;
  width: 100%;
  max-width: 420px;
  align-self: center;
}
#overlay.full .panel {
  width: 92%;
  height: auto;
  flex: none;
  max-width: 540px;
  max-height: min(92vh, 92dvh);
  padding: 22px 20px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  box-shadow: 0 0 0 4px #000, inset -4px -4px 0 #0d0e18, inset 4px 4px 0 var(--panel2);
}
#overlay:not(.full) .overlay-footer {
  flex: none;
  z-index: 2;
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  background: var(--panel);
  box-shadow: 0 -3px 0 #000;
}
#overlay:not(.full) .overlay-footer .btns {
  margin: 0;
}
.overlay-footer.hidden { display: none; }
#overlay.full .overlay-footer { display: none !important; }
.panel h1 { font-size: 20px; margin: 4px 0 14px; color: var(--gold); text-shadow: 3px 3px 0 #000; }
#overlay:not(.full) .panel h1 { font-size: 16px; margin: 4px 0 10px; text-shadow: 2px 2px 0 #000; }
.panel h1.win { color: #a7f070; }
.panel h1.lose { color: #ff5a6e; }
.panel h2 { font-size: 16px; margin: 4px 0 12px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
#overlay:not(.full) .panel h2 { font-size: 14px; margin: 4px 0 10px; }
.panel p { font-size: 10px; line-height: 1.7; margin: 8px 0; }
#overlay:not(.full) .panel p { font-size: 9px; line-height: 1.55; margin: 6px 0; }
.panel .sub { color: var(--muted); }
.panel .hint { font-size: 8px; color: var(--muted); }
#overlay:not(.full) .panel .hint { font-size: 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0;
  font-size: 7px;
  color: var(--muted);
}
#overlay:not(.full) .stats { gap: 4px; margin: 6px 0; font-size: 6px; }
.stats > div { background: #0d0e18; padding: 8px 4px; box-shadow: 0 0 0 2px #000; }
#overlay:not(.full) .stats > div { padding: 5px 3px; }
.stats b { display: block; margin-top: 6px; font-size: 11px; color: var(--txt); font-weight: normal; }
#overlay:not(.full) .stats b { margin-top: 4px; font-size: 9px; }

.btns { display: flex; flex-direction: column; gap: 10px; align-items: center; margin: 16px 0 8px; }
#overlay:not(.full) .btns { gap: 8px; margin: 10px 0 6px; }

.btn {
  min-width: min(220px, 100%);
  width: min(320px, 100%);
  padding: 12px 14px;
  font: inherit;
  font-size: 10px;
  color: var(--txt);
  background: var(--card);
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 0 0 3px #000, inset -3px -3px 0 #1a1c2c, inset 3px 3px 0 var(--card-hi);
}
#overlay:not(.full) .btn {
  min-width: 0;
  width: 100%;
  padding: 12px 10px;
  font-size: 10px;
  box-shadow: 0 0 0 3px #000, inset -3px -3px 0 #1a1c2c, inset 3px 3px 0 var(--card-hi);
}
.btn:hover:not(:disabled) { background: #3f4a6b; }
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn.primary { background: var(--ok); box-shadow: 0 0 0 3px #000, inset -3px -3px 0 #257179, inset 3px 3px 0 #a7f070; }
#overlay:not(.full) .btn.primary { box-shadow: 0 0 0 3px #000, inset -3px -3px 0 #257179, inset 3px 3px 0 #a7f070; }
.btn.primary:hover { background: #45c872; }
.btn.small { min-width: 0; font-size: 9px; padding: 8px 10px; }
#overlay:not(.full) .btn.small { font-size: 9px; padding: 8px 10px; }
.btn.ghost { background: transparent; box-shadow: none; color: #566c86; margin-top: 6px; }
#overlay:not(.full) .btn.ghost { margin-top: 4px; }
.btn:disabled { opacity: .45; cursor: default; }

.coin {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 4px;
  vertical-align: -1px;
  background: var(--gold);
  box-shadow: inset -2px -2px 0 #ef7d57, 0 0 0 1px #000;
}

.list { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #0d0e18;
  box-shadow: 0 0 0 2px #000;
}
.row .t { font-size: 10px; margin-bottom: 6px; }
.row .lvl { font-size: 7px; color: var(--muted); }
.row .d { font-size: 8px; color: var(--muted); line-height: 1.5; }
.row .d b { color: #a7f070; font-weight: normal; }

.reward { font-size: 18px; color: var(--gold); margin: 14px 0; }
#overlay:not(.full) .reward { font-size: 12px; margin: 6px 0; }
.unlock {
  font-size: 10px;
  padding: 10px;
  margin: 8px auto;
  max-width: 360px;
  line-height: 1.5;
  background: #5d275d;
  box-shadow: 0 0 0 3px #000;
}
#overlay:not(.full) .unlock {
  font-size: 7px;
  padding: 6px;
  margin: 4px auto;
  line-height: 1.4;
  box-shadow: 0 0 0 2px #000;
}
.unlock b { color: var(--gold); font-weight: normal; }

/* ---------- Персонаж ---------- */
.panel.wide { max-width: 860px; }

.char {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 16px;
  text-align: left;
}

.char-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  background: #0d0e18;
  box-shadow: 0 0 0 2px #000;
  align-self: start;
}
.char-left .preview { width: 192px; height: 108px; image-rendering: pixelated; }
.fname { font-size: 12px; color: var(--gold); }
.fbonus { font-size: 7px; color: #a7f070; text-align: center; line-height: 1.5; }
.fbonus.pet { color: #a6f0ff; }
.statlist { width: 100%; display: flex; flex-direction: column; gap: 5px; margin-top: 6px; font-size: 8px; }
.statlist > div { display: flex; justify-content: space-between; color: var(--muted); }
.statlist b { color: var(--txt); font-weight: normal; }
.goldline { font-size: 12px; color: var(--gold); margin-top: 6px; }

.char-right { display: flex; flex-direction: column; min-width: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tab {
  font: inherit;
  font-size: 8px;
  color: var(--muted);
  background: #0d0e18;
  border: none;
  padding: 8px 10px;
  cursor: pointer;
  box-shadow: 0 0 0 2px #000;
}
.tab.on { color: var(--txt); background: var(--blue); box-shadow: 0 0 0 2px #000, inset 2px 2px 0 #41a6f6; }

.char-body { max-height: 56vh; overflow-y: auto; padding: 3px 6px 6px 3px; }
.char-body h4 { font-size: 9px; font-weight: normal; color: var(--gold); margin: 14px 0 8px; }
.char-body h4:first-child { margin-top: 2px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tiles.small { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
.tile {
  font: inherit;
  color: var(--txt);
  background: #0d0e18;
  border: none;
  padding: 8px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  box-shadow: 0 0 0 2px #000;
}
.tile:hover:not(:disabled) { background: #1f2238; }
.tile canvas { image-rendering: pixelated; }
.tile canvas.body { width: 54px; height: 54px; }
.tile canvas.head { width: 48px; height: 48px; }
.tile .tn { font-size: 7px; line-height: 1.4; text-align: center; }
.tile .ts { font-size: 6px; color: #a7f070; line-height: 1.4; text-align: center; }
.tile .st { font-size: 7px; color: var(--muted); }
.tile.equipped { box-shadow: 0 0 0 3px var(--gold); }
.tile.equipped .st { color: var(--gold); }
.tile.locked canvas, .tile.locked .swatch { opacity: .55; }
.tile.trying { box-shadow: 0 0 0 3px #73eff7; }
.tile.trying canvas, .tile.trying .swatch { opacity: 1; }
.tile.trying .st { color: #73eff7; }
.tile.buyable .st { color: var(--gold); }
.tryline { display: flex; align-items: center; gap: 8px; font-size: 8px; color: #73eff7; }
.tile:disabled { cursor: default; opacity: .6; }

.swatch { display: block; width: 28px; height: 28px; margin: 4px 0; }

.row.pet canvas { width: 40px; height: 40px; image-rendering: pixelated; flex: none; }
.row.pet .info { flex: 1; }
.row.pet .d { margin-top: 3px; }
.row.pet.active { box-shadow: 0 0 0 3px var(--gold); }
.row.pet.unmet { opacity: .78; }
.row.pet.unmet .acts .btn { white-space: nowrap; }
.row .acts { display: flex; flex-direction: column; gap: 6px; }
.row.pet { flex-wrap: wrap; }
.tiles.petskins { flex-basis: 100%; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 6px; }
.tile.petskin canvas { width: 30px; height: 30px; }
.btn.on { background: var(--gold); color: #1a1c2c; box-shadow: 0 0 0 3px #000, inset -3px -3px 0 #ef7d57, inset 3px 3px 0 #fff3c4; }

.btn.toggle.on { background: #29366f; color: var(--txt); box-shadow: 0 0 0 3px #000, inset -3px -3px 0 #1a1c2c, inset 3px 3px 0 #3b5dc9; }
.btn.toggle:disabled { opacity: 1; cursor: default; }

input, textarea, .codebox {
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
}

.acc-extra {
  text-align: left;
  margin: 10px 0;
  font-size: 8px;
  color: var(--muted);
}
.acc-extra summary { cursor: pointer; margin-bottom: 8px; }
.acc-extra textarea {
  width: 100%;
  margin-top: 6px;
  font: inherit;
  font-size: 9px;
}
.form { display: flex; flex-direction: column; gap: 10px; text-align: left; margin: 12px 0; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 8px; color: var(--muted); }
.form input, .form textarea, .codebox {
  font: inherit;
  font-size: 10px;
  color: var(--txt);
  background: #0d0e18;
  border: none;
  padding: 10px;
  box-shadow: 0 0 0 2px #000;
  width: 100%;
}
.form textarea, .codebox { resize: vertical; line-height: 1.5; word-break: break-all; }
.codebox { min-height: 90px; text-align: left; margin: 10px 0; }
.acc-msg { color: #ff5a6e !important; min-height: 1.2em; }
a.btn {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  box-sizing: border-box;
}

.btns.inline { flex-direction: row; justify-content: center; flex-wrap: wrap; }
.btns.inline .btn { width: auto; min-width: 140px; flex: 1 1 140px; }
#overlay:not(.full) .btns.inline .btn { min-width: 0; flex: 1 1 80px; font-size: 7px; padding: 6px; }

@media (max-width: 700px) {
  .char { grid-template-columns: 1fr; }
  .char-left {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 16px;
    padding: 10px;
  }
  .char-left .preview { width: 144px; height: 81px; }
  .statlist { width: auto; min-width: 120px; margin-top: 0; }
  .char-body { max-height: none; overflow: visible; }
  .panel.wide { max-height: min(94vh, 94dvh); }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
}

@media (max-width: 560px) {
  #battle {
    width: 100%;
    max-height: 34dvh;
  }
  #board {
    gap: 8px;
    padding: 8px;
  }
  .col { gap: 6px; }
  .col h3 { font-size: 7px; margin: 0; }
  .card {
    font-size: 10px;
    min-height: 48px;
    max-height: none;
    padding: 8px 6px;
  }
  .card.prompt { font-size: 16px; }
  .pips { left: 5px; bottom: 4px; gap: 2px; }
  .pips i { width: 5px; height: 5px; }
  #hud { font-size: 7px; padding: 5px 6px; }
  #level-label { max-width: 38vw; text-align: center; line-height: 1.4; }
  #streak-label { max-width: 38vw; font-size: 6px; }
  #menu-btn, #settings-btn { padding: 8px 10px; font-size: 9px; }
  #settings-btn { font-size: 12px; }
  #train-bar, #mode-bar {
    flex-wrap: wrap;
    padding: 6px 8px;
    font-size: 7px;
    gap: 6px;
  }
  #train-bar .btn { width: 100%; }
  #overlay.full .panel {
    width: 100%;
    max-width: none;
    max-height: min(100vh, 100dvh);
    height: min(100vh, 100dvh);
    border-radius: 0;
    padding: 16px 12px max(16px, env(safe-area-inset-bottom));
  }
  #overlay.full .panel h1 { font-size: 16px; }
  #overlay.full .panel h2 { font-size: 14px; }
  #overlay.full .panel p { font-size: 9px; }
  #overlay.full .stats { grid-template-columns: repeat(2, 1fr); }
  #overlay.full .btn { width: 100%; min-width: 0; }
  #overlay.full .btns { width: 100%; }
  #overlay.full .btns.inline .btn { min-width: 0; }
  .row {
    flex-wrap: wrap;
    padding: 8px;
  }
  .row .acts { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .row .acts .btn { flex: 1 1 auto; }
  .teacher-portrait { width: 48px; height: 48px; }
  #overlay.full .teacher-portrait { width: 72px; height: 72px; }
  .bw-title { font-size: clamp(16px, 7vw, 28px); text-align: center; padding: 0 8px; }
}

@media (max-width: 380px) {
  .card { font-size: 9px; min-height: 44px; }
  .card.prompt { font-size: 14px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #battle {
    width: min(42vw, calc(48dvh * 320 / 150));
    max-height: 48dvh;
  }
  #board { padding: 6px; gap: 6px; }
  .card { min-height: 36px; font-size: 9px; padding: 4px 6px; }
  #overlay.full .panel { padding: 12px 16px; }
  .char-body { max-height: 55dvh; overflow-y: auto; }
}

@media (min-width: 701px) {
  #battle {
    width: min(100%, calc(44dvh * 320 / 150));
    max-height: 44dvh;
  }
}
