:root {
  --ink: #172033;
  --muted: #637083;
  --line: #d7deeb;
  --panel: #ffffff;
  --blue: #2f7df6;
  --green: #159a6b;
  --amber: #f1ad2b;
  --coral: #e95d55;
  --violet: #7457d6;
  --stage: #202b3b;
  --shadow: 0 18px 44px rgba(23, 32, 51, .13);
  --radius: 8px;
}

* { box-sizing: border-box; }

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  touch-action: manipulation;
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: ui-rounded, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(23, 32, 51, .045) 1px, transparent 1px),
    linear-gradient(rgba(23, 32, 51, .045) 1px, transparent 1px),
    linear-gradient(135deg, #f8fbff 0%, #eef8f5 46%, #fff7df 100%);
  background-size: 34px 34px, 34px 34px, auto;
}

button, input {
  font: inherit;
  touch-action: manipulation;
}

a { touch-action: manipulation; }
button { -webkit-tap-highlight-color: transparent; }

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

.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}

.series {
  color: var(--muted);
  font-weight: 1000;
  margin-bottom: 8px;
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-size: clamp(30px, 5vw, 58px);
  line-height: 1.02;
  letter-spacing: 0;
}

.subtitle {
  margin-top: 10px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
  font-weight: 800;
  max-width: 900px;
}

.top-actions, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  cursor: pointer;
  color: var(--ink);
  background: white;
  font-weight: 1000;
  text-decoration: none;
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}

.btn:hover { transform: translateY(-1px); filter: brightness(1.02); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { color: white; background: var(--blue); border-color: var(--blue); }
.btn.good { color: white; background: var(--green); border-color: var(--green); }
.btn.warn { color: white; background: var(--coral); border-color: var(--coral); }
.btn.violet { color: white; background: var(--violet); border-color: var(--violet); }

.status {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) minmax(210px, 1.1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.panel, .stat, .nickname {
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat {
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 900;
}

.stat b {
  color: var(--ink);
  font-size: 23px;
  line-height: 1;
}

.nickname {
  display: grid;
  gap: 6px;
  min-height: 72px;
  padding: 10px 12px;
  color: #765915;
  background: #fff7dc;
  font-weight: 1000;
}

.nickname input, .jump-field input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--ink);
  background: white;
  outline: none;
  font-weight: 1000;
}

.nickname input:focus, .jump-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 125, 246, .14);
}

.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.panel { padding: 14px; }

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-title h2 {
  font-size: 20px;
  line-height: 1.2;
}

.small-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 800;
}

.jump-field {
  display: grid;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 1000;
}

.tower-map {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.tower-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fbff;
  font-weight: 900;
}

.tower-row.current {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 125, 246, .12);
}

.tower-row.done {
  color: #083d2e;
  background: #e6faef;
  border-color: #a7e7c8;
}

.tower-row small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 800;
}

.arena-wrap {
  display: grid;
  gap: 12px;
}

.arena-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid #d8e5f6;
  border-radius: var(--radius);
  background: #f3f8ff;
}

.arena-head h2 {
  font-size: 22px;
  line-height: 1.2;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: var(--radius);
  padding: 6px 9px;
  background: #e9f8f0;
  color: #0a5a40;
  font-weight: 1000;
  white-space: nowrap;
}

.stage {
  position: relative;
  min-height: 520px;
  border: 1px solid #1c2533;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--stage);
}

canvas {
  display: block;
  width: 100%;
  height: 520px;
  touch-action: none;
  cursor: crosshair;
  background: #202b3b;
}

.question-panel {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 5;
  width: min(640px, calc(100% - 24px));
  transform: translateX(-50%);
  display: none;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--radius);
  color: white;
  background: rgba(18, 26, 39, .94);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .28);
}

.question-panel.show { display: grid; }

.question-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.problem {
  min-height: 56px;
  display: grid;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .1);
  font-size: clamp(24px, 4vw, 40px);
  font-weight: 1000;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.timer {
  min-width: 74px;
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #3b2a05;
  background: #ffe28a;
  font-weight: 1000;
}

.answer-display {
  min-height: 48px;
  display: grid;
  align-items: center;
  padding: 8px 10px;
  border: 2px solid rgba(255, 255, 255, .24);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .12);
  color: #fff8df;
  font-size: 28px;
  font-weight: 1000;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
}

.key {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: var(--radius);
  color: var(--ink);
  background: #f8fbff;
  cursor: pointer;
  font-weight: 1000;
}

.key.submit {
  grid-column: span 2;
  color: white;
  background: var(--green);
  border-color: var(--green);
}

.key.clear, .key.back {
  color: white;
  background: var(--coral);
  border-color: var(--coral);
}

.shot-track {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.shot-dot {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbff;
  color: var(--muted);
  font-weight: 1000;
}

.shot-dot.active {
  color: #5a4208;
  background: #fff1ba;
  border-color: #e3bf52;
}

.shot-dot.done {
  color: #083d2e;
  background: #dff8ec;
  border-color: #9ee5c3;
}

.message {
  min-height: 48px;
  display: grid;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid #d8e5fa;
  background: #eef5ff;
  color: #27466f;
  font-weight: 900;
  line-height: 1.4;
}

.message.good { background: #e5faef; border-color: #a7e7c8; color: #0b5b40; }
.message.warn { background: #fff0ee; border-color: #f3bbb4; color: #8c2c25; }

.summary {
  display: grid;
  gap: 9px;
}

.summary-row, .leader-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fbff;
  font-weight: 900;
}

.leader-row {
  grid-template-columns: 30px minmax(0, 1fr) auto;
}

.leader-row small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 800;
}

.meter {
  height: 12px;
  border-radius: 999px;
  background: #e7edf7;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--violet));
  transition: width .22s ease;
}

.leaderboard-title {
  margin-top: 14px;
}

.empty {
  padding: 14px;
  border: 2px dashed #c9d4e6;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  font-weight: 900;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 130px);
  z-index: 20;
  width: min(720px, calc(100vw - 28px));
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .2);
  background: #1f2937;
  color: white;
  text-align: center;
  font-weight: 1000;
  box-shadow: 0 18px 44px rgba(31, 41, 55, .28);
  transition: transform .18s ease;
}

.toast.show { transform: translate(-50%, 0); }

@media (max-width: 1180px) {
  .top, .layout { grid-template-columns: 1fr; }
  .status { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tower-panel { order: 2; }
}

@media (max-width: 720px) {
  .app { padding: 10px; }
  .status { grid-template-columns: 1fr; }
  .top-actions, .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .btn { width: 100%; }
  canvas { height: 430px; }
  .stage { min-height: 430px; }
  .keypad { grid-template-columns: repeat(3, 1fr); }
  .key.submit { grid-column: span 2; }
  .question-top, .arena-head { grid-template-columns: 1fr; }
  .tower-row { grid-template-columns: 48px minmax(0, 1fr); }
  .tower-row b:last-child { grid-column: 2; }
}
