:root {
  color-scheme: light;
  --ink: #18202b;
  --muted: #617086;
  --paper: #fffdf8;
  --line: #d8dee9;
  --red: #d83b4c;
  --blue: #2176d2;
  --gold: #e6a21a;
  --green: #16845f;
  --bg: #f3f5f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans TC", "Segoe UI", sans-serif;
  background:
    linear-gradient(120deg, rgba(216, 59, 76, .10), transparent 34%),
    linear-gradient(240deg, rgba(33, 118, 210, .12), transparent 36%),
    var(--bg);
  color: var(--ink);
}

button, input { font: inherit; }
button { cursor: pointer; }

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.battle-active .app {
  width: min(1120px, 100%);
  padding: 136px 10px 10px;
}

.battle-active .topbar {
  display: none;
}

.topbar, .fight-stage, .panel, .home-grid > section {
  background: rgba(255, 253, 248, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(24, 32, 43, .08);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
}

.back-link {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.brand { font-weight: 900; font-size: clamp(1.3rem, 3vw, 2.2rem); }
.sub { color: var(--muted); font-size: .95rem; }
.badge { padding: 6px 10px; border-radius: 999px; background: #18202b; color: white; font-weight: 800; }

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.home-grid > section, .panel { padding: 16px; }
.hero-panel,
.lobby-panel {
  grid-column: 1 / -1;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 18px;
  align-items: center;
}

.hero-panel h2 {
  font-size: clamp(1.35rem, 3vw, 2.2rem);
}

.home-qr-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid #c8d6e8;
  border-radius: 8px;
  background: #eef5ff;
}

.home-qr-title {
  color: var(--blue);
  font-weight: 900;
}

.home-qr-canvas {
  width: 160px;
  height: 160px;
  padding: 6px;
  border-radius: 8px;
  background: white;
}

.home-qr-canvas canvas {
  display: block;
  width: 148px;
  height: 148px;
}

.home-qr-url {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-align: center;
}
h1, h2, h3, p { margin-top: 0; }
h2 { font-size: 1.15rem; }

.battle-active .panel { padding: 10px; }
.battle-active h2 { font-size: 1rem; margin-bottom: 8px; }
.battle-active h3 { font-size: .96rem; margin: 8px 0 6px; }

.field-row, .mode-row, .join-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}

.field-row input { flex: 1 1 180px; }

.btn, .mode-btn {
  border: 0;
  border-radius: 6px;
  min-height: 42px;
  padding: 9px 13px;
  background: #e9eef7;
  color: var(--ink);
  font-weight: 800;
}

.btn.primary { background: var(--ink); color: white; }
.btn.red { background: var(--red); color: white; }
.btn.blue { background: var(--blue); color: white; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.mode-btn.active { outline: 3px solid rgba(230, 162, 26, .35); background: #fff0c9; }

.notice {
  min-height: 28px;
  margin-top: 10px;
  color: var(--muted);
  font-weight: 700;
}

.teacher-panel {
  grid-column: 1 / -1;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.teacher-create-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 110px auto auto;
  gap: 10px;
  align-items: end;
}

.teacher-create-row label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 900;
}

.teacher-create-row label,
#createBatchRooms {
  display: none;
}

select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  font: inherit;
}

.teacher-room-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.student-room-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.student-create-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.student-create-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.room-size.one { background: #e9f7ef; color: #0b6b4c; }
.room-size.two { background: #eef5ff; color: #145ca9; }
.room-size.three { background: #fff4df; color: #8a5200; }

.student-room-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.student-room-card.size-1,
.teacher-room-card.size-1 {
  border-left: 8px solid #16845f;
}

.student-room-card.size-2,
.teacher-room-card.size-2 {
  border-left: 8px solid #2176d2;
}

.student-room-card.size-3,
.teacher-room-card.size-3 {
  border-left: 8px solid #e6a21a;
}

.student-room-code {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.student-room-actions {
  display: flex;
  gap: 8px;
}

.student-room-actions .btn {
  min-width: 70px;
}

.teacher-room-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.teacher-room-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.teacher-room-code {
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.teacher-room-meta {
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 5px;
}

.teacher-room-card a {
  color: var(--blue);
  font-size: .78rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.teacher-qr {
  width: 104px;
  height: 104px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  background: #fff;
}

.teacher-qr canvas {
  display: block;
  width: 94px;
  height: 94px;
}

.teacher-room-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.teacher-dashboard {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 14px;
}

.stat-card {
  display: grid;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stat-card b {
  font-size: 1.5rem;
}

.stat-card span {
  color: var(--muted);
  font-weight: 800;
}

.leaderboard-table {
  overflow-x: auto;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.leaderboard-table table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.leaderboard-table th {
  background: #f2f5f9;
  color: var(--muted);
  font-size: .86rem;
}

.leaderboard-table tr:last-child td {
  border-bottom: 0;
}

.btn.danger {
  color: #b91c1c;
  border-color: #f0b9b9;
}

.waiting-banner {
  margin: 8px 0;
  padding: 9px 10px;
  border: 1px solid #f1c76f;
  border-radius: 8px;
  background: #fff6d8;
  color: #7a4c00;
  font-weight: 900;
}

.room-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
  min-height: 48px;
  margin: 8px 0;
  border: 2px dashed var(--gold);
  border-radius: 8px;
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.room-qr {
  width: 132px;
  height: 132px;
  margin: 10px auto 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.room-qr canvas {
  display: block;
  width: 120px;
  height: 120px;
}

.room-join-url {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.fight-stage {
  position: fixed;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 30;
  width: auto;
  margin-top: 0;
  padding: 8px;
  background-image: linear-gradient(rgba(255, 253, 248, .86), rgba(255, 253, 248, .9)), url("images/battle-bg.svg");
  background-size: cover;
  background-position: center 42%;
}

.hp-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.hp-card { min-width: 0; }
.hp-label { display: flex; justify-content: space-between; font-weight: 900; font-size: .9rem; }
.hp-bar { height: 12px; background: #dfe5ee; border-radius: 999px; overflow: hidden; }
.hp-fill { height: 100%; width: 100%; transition: width .25s ease; }
.hp-fill.red { background: linear-gradient(90deg, #ad2030, var(--red)); }
.hp-fill.blue { background: linear-gradient(90deg, #145ca9, var(--blue)); }
.versus { font-weight: 900; font-size: 1.05rem; color: var(--muted); white-space: nowrap; }

.fighters {
  position: relative;
  min-height: 118px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 10px;
  padding: 4px 12px 0;
  background:
    linear-gradient(#ffffffaa, #ffffff44),
    repeating-linear-gradient(90deg, transparent 0 42px, rgba(24, 32, 43, .06) 42px 43px);
  border-radius: 8px;
  margin-top: 6px;
  overflow: hidden;
}

.fighter {
  position: relative;
  min-height: 106px;
  display: flex;
  align-items: end;
  justify-content: center;
  transition: transform .18s ease;
}

.fighter.attack-red { transform: translateX(92px) scale(1.08); }
.fighter.attack-blue { transform: translateX(-92px) scale(1.08); }
.fighter.hit { animation: hit .28s ease; }
.fighter.hit::after {
  content: "";
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 236, 149, .95) 0 22%, rgba(238, 78, 92, .55) 35%, transparent 68%);
  transform: translateY(-28px);
  animation: impact-flash .32s ease;
  pointer-events: none;
}

.avatar {
  width: 96px;
  height: 118px;
  position: relative;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center bottom;
  filter: drop-shadow(0 10px 8px rgba(24, 32, 43, .2));
}

.avatar::before,
.avatar::after { content: none; }

.avatar.red { background-image: url("images/red-fighter.png"); }
.avatar.blue { background-image: url("images/blue-fighter.png"); }

@keyframes hit {
  30% { transform: translateX(10px) rotate(2deg); filter: brightness(1.2); }
  60% { transform: translateX(-8px) rotate(-2deg); }
}

@keyframes impact-flash {
  0% { opacity: 0; transform: translateY(-28px) scale(.55); }
  45% { opacity: 1; transform: translateY(-28px) scale(1.12); }
  100% { opacity: 0; transform: translateY(-28px) scale(1.35); }
}

.attack-effect {
  position: absolute;
  left: 50%;
  bottom: 34px;
  z-index: 2;
  width: 124px;
  height: 92px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0;
  border-radius: 0;
  background: url("images/attack-frame-1.svg") center / contain no-repeat;
  border: 0;
  color: #7a4b00;
  font-weight: 900;
  text-shadow: 0 2px 0 #fff;
  opacity: 0;
  transform: translate(-50%, 10px) scale(.9);
  pointer-events: none;
}

.attack-effect.effect-red { animation: blast-red .62s steps(1, end); }
.attack-effect.effect-blue { animation: blast-blue .62s steps(1, end); }
.attack-effect.effect-heal {
  animation: heal-pop .72s steps(1, end);
  background: url("images/heal-frame-1.svg") center / contain no-repeat;
  color: var(--green);
}
.attack-effect.effect-penalty { animation: penalty-pop .42s ease; background: #fff1f2; color: var(--red); border-color: var(--red); }

@keyframes blast-red {
  0% { opacity: 0; transform: translate(-128%, 12px) scale(.78); background-image: url("images/attack-frame-1.svg"); }
  18% { opacity: 1; transform: translate(-94%, 2px) scale(.9); background-image: url("images/attack-frame-1.svg"); }
  38% { opacity: 1; transform: translate(-68%, -8px) scale(1); background-image: url("images/attack-frame-2.svg"); }
  58% { opacity: 1; transform: translate(-46%, -12px) scale(1.1); background-image: url("images/attack-frame-3.svg"); }
  78% { opacity: 1; transform: translate(-30%, -10px) scale(1.2); background-image: url("images/attack-frame-4.svg"); }
  100% { opacity: 0; transform: translate(12%, 0) scale(1.08); background-image: url("images/attack-frame-5.svg"); }
}

@keyframes blast-blue {
  0% { opacity: 0; transform: translate(28%, 12px) scale(.78) scaleX(-1); background-image: url("images/attack-frame-1.svg"); }
  18% { opacity: 1; transform: translate(-6%, 2px) scale(.9) scaleX(-1); background-image: url("images/attack-frame-1.svg"); }
  38% { opacity: 1; transform: translate(-32%, -8px) scale(1) scaleX(-1); background-image: url("images/attack-frame-2.svg"); }
  58% { opacity: 1; transform: translate(-54%, -12px) scale(1.1) scaleX(-1); background-image: url("images/attack-frame-3.svg"); }
  78% { opacity: 1; transform: translate(-70%, -10px) scale(1.2) scaleX(-1); background-image: url("images/attack-frame-4.svg"); }
  100% { opacity: 0; transform: translate(-112%, 0) scale(1.08) scaleX(-1); background-image: url("images/attack-frame-5.svg"); }
}

@keyframes heal-pop {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(.7); background-image: url("images/heal-frame-1.svg"); }
  20% { opacity: 1; transform: translate(-50%, 4px) scale(.86); background-image: url("images/heal-frame-1.svg"); }
  40% { opacity: 1; transform: translate(-50%, -6px) scale(1); background-image: url("images/heal-frame-2.svg"); }
  60% { opacity: 1; transform: translate(-50%, -14px) scale(1.16); background-image: url("images/heal-frame-3.svg"); }
  80% { opacity: .85; transform: translate(-50%, -18px) scale(1.28); background-image: url("images/heal-frame-4.svg"); }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(1.42); background-image: url("images/heal-frame-5.svg"); }
}

@keyframes penalty-pop {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(.8) rotate(-4deg); }
  45% { opacity: 1; transform: translate(-50%, -8px) scale(1.12) rotate(3deg); }
  100% { opacity: 0; transform: translate(-50%, 0) scale(.95); }
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 32, 43, .46);
}

.result-dialog {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 0 24px 60px rgba(24, 32, 43, .22);
  padding: 20px;
}

.result-title {
  font-size: 1.8rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 14px;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.result-title::before {
  content: "";
  width: 76px;
  height: 76px;
  background: url("images/mvp-badge.svg") center / contain no-repeat;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.result-grid > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-weight: 900;
  font-size: .82rem;
}

.result-grid b {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.result-stats {
  max-height: 220px;
  overflow: auto;
}

.result-stats table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.result-stats th,
.result-stats td {
  padding: 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
}

.play-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 10px;
  margin-top: 0;
}

.play-grid > * {
  min-width: 0;
}

.problem {
  font-size: clamp(1.3rem, 3vw, 2.1rem);
  font-weight: 900;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border-radius: 8px;
  background: #f7f0df;
}

.steps, .choices, .point-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.step-btn, .choice-btn, .point-btn, .move-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 9px 11px;
  font-weight: 800;
}

.step-btn.done { background: #e4f6ed; color: var(--green); }
.choice-btn.selected, .point-btn.active, .move-card.selected { border-color: var(--gold); background: #fff1cc; }

.equation-board {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.equation-step {
  display: grid;
  gap: 5px;
}

.equation-row {
  display: grid;
  grid-template-columns: 70px minmax(118px, .32fr) minmax(220px, 1fr) minmax(118px, .32fr);
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.equation-row.locked {
  color: #9099a8;
  background: #f0f2f5;
}

.equation-row.current {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(230, 162, 26, .18);
}

.row-meta {
  grid-column: 1;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 900;
}

.equation-line {
  grid-column: 3;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.1rem, 2.6vw, 1.65rem);
  font-weight: 900;
  overflow-wrap: anywhere;
  white-space: nowrap;
  overflow: hidden;
}

.math-expression {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .18em;
  white-space: nowrap;
}

.math-symbol {
  display: inline-block;
  min-width: 1.05em;
  text-align: center;
  font-family: "Cambria Math", "Times New Roman", serif;
  font-weight: 900;
  line-height: 1;
}

.math-frac {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  min-width: 1.05em;
  margin: 0 .05em;
  font-family: "Cambria Math", "Times New Roman", serif;
  font-weight: 900;
  line-height: .9;
  vertical-align: middle;
}

.math-frac .num {
  display: block;
  width: 100%;
  padding: 0 .15em .08em;
  border-bottom: .08em solid currentColor;
  text-align: center;
}

.math-frac .den {
  display: block;
  padding-top: .08em;
  text-align: center;
}

.drop-zone {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 2px dashed #d8b04d;
  border-radius: 8px;
  color: #7a4b00;
  background: #fff8df;
  font-weight: 900;
}

.side-drop-row {
  display: contents;
}

.side-zone {
  min-height: 48px;
  font-size: .82rem;
  padding: 6px 5px;
}

.left-zone { grid-column: 2; grid-row: 1; }
.right-zone { grid-column: 4; grid-row: 1; }

.left-zone {
  background: #eef5ff;
  border-color: #8fb8e8;
  color: #164c86;
}

.right-zone {
  background: #fff8df;
  border-color: #d8b04d;
  color: #7a4b00;
}

.choose-direct {
  grid-column: 4;
  min-height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef7f2;
  color: var(--green);
  font-weight: 900;
  font-size: .9rem;
}

.drop-zone.over {
  background: #ffe99d;
  transform: translateY(-1px);
}

.drop-zone.done {
  background: #e4f6ed;
  border-color: var(--green);
  color: var(--green);
}

.move-card {
  box-shadow: 0 5px 0 rgba(24, 32, 43, .12);
  touch-action: manipulation;
}

.step-choice-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  background: #f7f0df;
}

.step-choice-row.waiting {
  display: block;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.term-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 32px;
  margin: 0 4px;
  padding: 4px 10px;
  border: 2px solid #d8b04d;
  border-radius: 8px;
  background: #fff1aa;
  color: #5b3a00;
  font: inherit;
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(122, 75, 0, .18);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.term-chip.selected {
  outline: 3px solid rgba(230, 162, 26, .45);
  background: #ffe37a;
}

.touch-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.08);
  opacity: .94;
  box-shadow: 0 10px 24px rgba(24, 32, 43, .28);
}

.static-chip {
  cursor: default;
  box-shadow: none;
}

.move-card:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 rgba(24, 32, 43, .12);
}

.move-done {
  color: var(--green);
  font-weight: 900;
}

.solution-stage.locked {
  opacity: .42;
  pointer-events: none;
  filter: grayscale(.2);
}

.numberline {
  position: relative;
  height: 136px;
  margin: 8px 0 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

.axis {
  position: absolute;
  left: 36px;
  right: 36px;
  top: 70px;
  height: 4px;
  background: #283241;
}

.tick {
  position: absolute;
  top: 56px;
  width: 2px;
  height: 28px;
  background: #283241;
}

.tick span {
  position: absolute;
  top: 30px;
  transform: translateX(-50%);
  font-size: .75rem;
  color: var(--muted);
}

.solution-ray {
  position: absolute;
  top: 64px;
  height: 16px;
  border-radius: 999px;
  background: rgba(22, 132, 95, .32);
  display: none;
}

.point {
  position: absolute;
  top: 56px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 4px solid var(--green);
  background: #fff;
  transform: translate(-50%, 0);
  touch-action: none;
}

.point.closed { background: var(--green); }

.direction-band {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 8px;
  height: 42px;
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) 86px;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  border-radius: 8px;
  background: #eef7f2;
  touch-action: none;
}

.direction-btn {
  min-height: 32px;
  border: 1px solid #b8d9ca;
  border-radius: 6px;
  background: #fff;
  color: var(--green);
  font-weight: 900;
}

.direction-btn.active {
  background: var(--green);
  color: white;
}

.direction-band span {
  text-align: center;
  color: var(--green);
  font-weight: 900;
}

.direction-ray {
  position: absolute;
  top: 26px;
  height: 10px;
  border-radius: 999px;
  background: rgba(22, 132, 95, .42);
  display: none;
  pointer-events: none;
}

.vertical-ray {
  position: absolute;
  top: 26px;
  width: 8px;
  height: 42px;
  border-radius: 999px;
  background: rgba(22, 132, 95, .42);
  display: none;
  transform: translateX(-50%);
  pointer-events: none;
}

.drag-hint {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 0;
}

.log {
  max-height: 150px;
  overflow: auto;
  padding: 0;
  margin: 0;
  list-style: none;
}

.log li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.member {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  background: #fff;
}

.hidden { display: none !important; }

@media (max-width: 820px) {
  .home-grid, .play-grid { grid-template-columns: 1fr; }
  .hero-panel { grid-template-columns: 1fr; }
  .home-qr-card { justify-self: center; width: min(100%, 260px); }
  .student-room-card { grid-template-columns: 1fr; }
  .student-room-actions { justify-content: stretch; }
  .student-room-actions .btn { flex: 1; }
  .student-create-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .teacher-create-row { grid-template-columns: 1fr 1fr; }
  .battle-active .app { padding: 128px 8px 8px; }
  .hp-row { grid-template-columns: 1fr auto 1fr; }
  .versus { text-align: center; }
  .fighters { min-height: 102px; padding-inline: 6px; }
  .fighter { min-height: 96px; }
  .avatar { width: 78px; height: 96px; }
  .avatar::before { left: 8px; }
  .equation-row { grid-template-columns: 1fr 1fr; }
  .row-meta { grid-column: 1 / -1; }
  .equation-line { grid-column: 1 / -1; }
  .left-zone { grid-column: 1; grid-row: auto; }
  .right-zone { grid-column: 2; grid-row: auto; }
  .step-choice-row { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .battle-active .app { padding-top: 132px; }
  .play-grid { grid-template-columns: minmax(0, 1fr) 240px; }
  .equation-row { grid-template-columns: 58px minmax(96px, .28fr) minmax(190px, 1fr) minmax(96px, .28fr); gap: 5px; }
  .equation-line { font-size: clamp(1rem, 2.4vw, 1.45rem); }
  .term-chip { min-width: 36px; padding: 3px 7px; }
  .side-zone { font-size: .76rem; min-height: 42px; }
  .room-code { min-height: 38px; font-size: 1.35rem; }
  .member-grid { grid-template-columns: 1fr; }
}

@media print {
  body { background: white; }
  .topbar,
  .home-grid > section:not(.teacher-panel),
  .section-head,
  .teacher-create-row,
  .teacherNotice,
  .teacher-room-actions {
    display: none !important;
  }
  .app {
    width: 100%;
    padding: 0;
  }
  .teacher-panel {
    border: 0;
    box-shadow: none;
    padding: 0;
  }
  .teacher-room-list {
    grid-template-columns: repeat(2, 1fr);
    gap: 14mm;
  }
  .teacher-room-card {
    break-inside: avoid;
    border: 2px solid #111;
    min-height: 120mm;
    display: grid;
    align-content: center;
    text-align: center;
  }
  .teacher-room-main {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .teacher-room-code {
    font-size: 3rem;
  }
  .teacher-qr,
  .teacher-qr canvas {
    width: 52mm !important;
    height: 52mm !important;
  }
}
