:root {
  --ink: #251a3e;
  --purple: #6d45b8;
  --purple-dark: #3f276e;
  --pink: #ef5fa7;
  --yellow: #ffd25f;
  --cream: #fff9ef;
  --green: #45b96f;
  --danger: #d95366;
  --shadow: 0 18px 50px rgba(37, 26, 62, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(239, 95, 167, 0.18), transparent 34%),
    radial-gradient(circle at bottom right, rgba(109, 69, 184, 0.22), transparent 38%),
    #efe9fb;
  color: var(--ink);
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

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

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.school-name {
  margin: 0 0 3px;
  color: var(--purple);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  line-height: 1;
}

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

.small-button {
  border: 0;
  border-radius: 12px;
  background: white;
  color: var(--purple-dark);
  padding: 10px 14px;
  font-weight: 900;
  box-shadow: 0 6px 18px rgba(37, 26, 62, 0.14);
  cursor: pointer;
}

.small-button:active,
.primary-button:active,
.control:active {
  transform: translateY(2px) scale(0.98);
}

.small-button.danger {
  color: var(--danger);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.hud-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 10px 14px;
  border: 2px solid rgba(109, 69, 184, 0.12);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 24px rgba(37, 26, 62, 0.08);
}

.hud-item span {
  color: #6d6680;
  font-size: 0.83rem;
  font-weight: 800;
}

.hud-item strong {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-frame {
  position: relative;
  overflow: hidden;
  border: 5px solid var(--ink);
  border-radius: 24px;
  background: #d9c49d;
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(25, 15, 45, 0.78);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.panel {
  width: min(520px, 100%);
  padding: clamp(24px, 5vw, 38px);
  border: 4px solid white;
  border-radius: 26px;
  background: var(--cream);
  text-align: center;
  box-shadow: var(--shadow);
}

.character-badge {
  display: grid;
  width: 66px;
  height: 66px;
  margin: -56px auto 14px;
  place-items: center;
  border: 5px solid white;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--pink), var(--purple));
  color: white;
  font-size: 2rem;
  font-weight: 1000;
  box-shadow: 0 10px 26px rgba(37, 26, 62, 0.25);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--purple);
  font-size: 0.82rem;
  font-weight: 1000;
  letter-spacing: 0.14em;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1;
}

.panel p {
  line-height: 1.55;
}

.instructions {
  display: grid;
  gap: 8px;
  margin: 20px 0;
  text-align: left;
}

.instructions div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f0e7ff;
}

.instructions span {
  color: #675d78;
  text-align: right;
}

.primary-button {
  width: 100%;
  border: 0;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
  padding: 14px 20px;
  font-size: 1.05rem;
  font-weight: 1000;
  box-shadow: 0 10px 24px rgba(109, 69, 184, 0.28);
  cursor: pointer;
}

.final-score {
  font-size: 1.2rem;
  font-weight: 1000;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 3;
  max-width: calc(100% - 32px);
  transform: translate(-50%, 20px);
  border-radius: 999px;
  background: rgba(37, 26, 62, 0.92);
  color: white;
  padding: 10px 16px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
}

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

.mobile-controls {
  display: none;
  justify-content: center;
  margin-top: 14px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(2, 58px);
  gap: 8px;
}

.control {
  border: 0;
  border-radius: 18px;
  background: linear-gradient(145deg, #7b54c8, #4d2c88);
  color: white;
  font-size: 1.4rem;
  font-weight: 1000;
  box-shadow: 0 8px 20px rgba(37, 26, 62, 0.24);
  touch-action: none;
  user-select: none;
}

.control.up {
  grid-column: 2;
  grid-row: 1;
}

.control.left {
  grid-column: 1;
  grid-row: 2;
}

.control.down {
  grid-column: 2;
  grid-row: 2;
}

.control.right {
  grid-column: 3;
  grid-row: 2;
}

.footer-note {
  margin: 12px 0 0;
  color: #625972;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 800;
}

@media (max-width: 760px), (pointer: coarse) {
  .app-shell {
    padding: 10px;
  }

  .game-header {
    align-items: flex-start;
  }

  .header-actions {
    flex-direction: column;
  }

  .small-button {
    padding: 8px 11px;
    font-size: 0.82rem;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .hud-item {
    padding: 8px 10px;
  }

  .mobile-controls {
    display: flex;
  }

  .overlay {
    padding: 12px;
  }

  .panel {
    padding: 22px 18px;
  }

  .panel p {
    font-size: 0.92rem;
  }

  .instructions {
    margin: 14px 0;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: 1.34rem;
  }

  .school-name {
    font-size: 0.64rem;
  }

  .hud-item span {
    font-size: 0.74rem;
  }

  .hud-item strong {
    font-size: 0.88rem;
  }

  .dpad {
    grid-template-columns: repeat(3, 62px);
  }
}
