.mg {
  --mg-ink: #f4f8ff;
  --mg-deep: #081327;
  --mg-panel: #121f3d;
  --mg-line: #53739e;
  --mg-muted: #c0cceb;
  --mg-lime: #d8f65b;
  --mg-cyan: #62e7ff;
  --mg-goal: #a7def7;
  display: grid;
  gap: 13px;
  padding: clamp(13px, 2.8vw, 30px);
  border: 1px solid var(--mg-line);
  border-top: 4px solid var(--mg-cyan);
  background: linear-gradient(150deg, #172b50 0, var(--mg-deep) 52%);
  box-shadow: 6px 6px #040a1a;
  color: var(--mg-ink);
  min-width: 0;
}

.mg .mg-heading { display: grid; gap: 7px; }
.mg .mg-heading h2 { color: var(--mg-ink); }
.mg .mg-heading p, .mg .mg-note { color: var(--mg-muted); }
.mg .mg-note { font-size: .94rem; max-width: 76ch; }
.mg :focus-visible { outline: 3px solid var(--mg-cyan); outline-offset: 3px; }
.mg[data-difficulty="medium"] { --mg-goal: #bbefac; }
.mg[data-difficulty="hard"] { --mg-goal: #ffda93; }
.mg .mg-goal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px 20px;
  flex-wrap: wrap;
  color: var(--mg-goal);
}
.mg .mg-progress {
  appearance: none;
  display: block;
  flex: 1 1 6rem;
  max-inline-size: 14rem;
  block-size: .46rem;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #304364;
  accent-color: var(--mg-goal);
}
.mg .mg-progress::-webkit-progress-bar { background: #304364; }
.mg .mg-progress::-webkit-progress-value { background: var(--mg-goal); }
.mg .mg-progress::-moz-progress-bar { background: var(--mg-goal); }

.mg .mg-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.mg .mg-hud {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  min-height: 49px;
  padding: 8px 12px;
  border: 1px solid var(--mg-line);
  border-left: 4px solid var(--mg-cyan);
  background: #0b182e;
}
.mg .mg-count, .mg .mg-clock {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}
.mg .mg-clock { color: var(--mg-cyan); }
.mg[data-phase="running"] .mg-clock, .mg[data-phase="done"] .mg-count { color: var(--mg-lime); }
.mg .mg-mode { color: var(--mg-muted); font-weight: 750; }

.mg .mg-field {
  position: relative;
  min-width: 0;
  border: 1px solid var(--mg-line);
  background:
    radial-gradient(circle at 14% 28%, #9be7ff 1px, transparent 2px),
    radial-gradient(circle at 76% 60%, #c3dce9 1px, transparent 1.7px),
    radial-gradient(circle at 58% 10%, #4ba9de 1px, transparent 2px),
    linear-gradient(176deg, #182e56, #091426 68%);
  background-size: 90px 120px, 110px 89px, 70px 79px, 100% 100%;
  overflow: hidden;
}
.mg .mg-balloons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr));
  gap: 8px;
  padding: 11px;
  align-items: center;
  margin: 0;
  list-style: none;
}
.mg .mg-balloon {
  --mg-bladder: #46d9f4;
  --mg-bladder-dark: #237bab;
  position: relative;
  min-height: 119px;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: 5px 3px 27px;
  transform-origin: 50% 44%;
}
.mg .mg-balloon:nth-child(4n + 2) { --mg-bladder: #f8a0dc; --mg-bladder-dark: #a7428a; }
.mg .mg-balloon:nth-child(4n + 3) { --mg-bladder: #f3d976; --mg-bladder-dark: #c77939; }
.mg .mg-balloon:nth-child(4n + 4) { --mg-bladder: #b7ee80; --mg-bladder-dark: #578e57; }
.mg .mg-balloon > span {
  width: 100%;
  min-height: 86px;
  display: grid;
  place-items: center;
  padding: 14px 10px;
  border: 2px solid #b2d9e9;
  border-radius: 50% 48% 50% 52% / 49% 48% 52% 51%;
  background:
    radial-gradient(ellipse at 22% 29%, #ffffff92 0 7%, transparent 9%),
    linear-gradient(148deg, var(--mg-bladder), var(--mg-bladder-dark));
  box-shadow: inset 0 -8px #0a244a34, 3px 4px #060d2a83;
  color: #061b31;
  font-size: clamp(1rem, 2.2vw, 1.3rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.12;
  overflow-wrap: anywhere;
}
.mg .mg-balloon:not(.is-target, .is-hit) > span {
  background:
    radial-gradient(ellipse at 22% 29%, #ffffff35 0 7%, transparent 9%),
    linear-gradient(148deg, #284d73, #193557);
  color: #e7f0ff;
  border-color: #648ab7;
}
.mg .mg-balloon > i {
  position: absolute;
  top: 89px;
  width: 7px;
  height: 20px;
  border-top: 4px solid #73a6c5;
  border-left: 1px solid #c8def1;
  border-bottom-left-radius: 100%;
  transform: rotate(12deg);
}
.mg .mg-balloon.is-target > span {
  background:
    radial-gradient(ellipse at 22% 29%, #ffffffc7 0 7%, transparent 9%),
    linear-gradient(148deg, #eeff9a, #bcdf3c);
  border-color: #f6ffbf;
  box-shadow: inset 0 -7px #728e283c, 0 0 0 2px #d8f646, 0 0 20px #d8f66ea0;
  animation: mg-float 2.3s ease-in-out infinite;
}
.mg[data-phase="paused"] .mg-balloon.is-target > span { animation-play-state: paused; }
.mg .mg-balloon.is-hit > span, .mg .mg-balloon.is-hit > i {
  opacity: 0;
  animation: mg-pop .48s ease-out both;
}
.mg .mg-balloon.is-hit::after {
  content: "✓";
  position: absolute;
  inset: 13px auto auto;
  display: grid;
  place-items: center;
  width: 57px;
  aspect-ratio: 1;
  border: 1px dashed #93b653;
  border-radius: 50%;
  color: var(--mg-lime);
  font: 900 1.65rem/1 system-ui;
}
@keyframes mg-float { 50% { transform: translateY(-4px) rotate(-2deg); } }
@keyframes mg-pop { from { opacity: 1; } 60% { opacity: .4; transform: scale(1.19); } to { opacity: 0; transform: scale(1.42); } }

.mg .mg-ship-scene {
  position: relative;
  display: grid;
  justify-items: center;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 4px 10px 10px;
  background: radial-gradient(ellipse at 50% 62%, #5545c359 0, #2c62a123 42%, transparent 75%);
}
.mg .mg-ship { width: min(100%, 290px); height: auto; overflow: visible; }
.mg .mg-ship-shield { fill: #3bcaf416; stroke: #62e7ff; stroke-width: 2; stroke-dasharray: 17 7; opacity: .75; }
.mg .mg-ship-hull { fill: #5581cf; stroke: #ced8f5; stroke-width: 3; stroke-linejoin: round; }
.mg .mg-ship-wing { fill: #2e417e; stroke: #9cbbf2; stroke-width: 2; }
.mg .mg-ship-cockpit { fill: #62e7ff; stroke: #172d6c; stroke-width: 3; }
.mg .mg-ship-line { stroke: #142c61; stroke-width: 3; fill: none; }
.mg .mg-ship-light { fill: #e5f89c; stroke: var(--mg-lime); stroke-width: 3; }
.mg[data-phase="running"] .mg-ship-shield { animation: mg-shield 2.5s linear infinite; }
@keyframes mg-shield { to { stroke-dashoffset: 96; } }
.mg .mg-beams {
  position: absolute;
  z-index: 1;
  bottom: 25px;
  left: 50%;
  width: 138px;
  height: 90px;
  transform: translateX(-50%);
  pointer-events: none;
  overflow: visible;
}
.mg .mg-beams path {
  fill: none;
  stroke: #f5ffce;
  stroke-width: 5px;
  stroke-linecap: round;
  opacity: 0;
  filter: drop-shadow(0 0 3px #d8f65b) drop-shadow(0 0 6px #62e7ff);
}
.mg .mg-beams path.is-fired { animation: mg-light-pulse .65s ease-out both; }
@keyframes mg-light-pulse {
  from { opacity: 1; stroke-dasharray: 39 100; stroke-dashoffset: 39; }
  68% { opacity: 1; stroke-dasharray: 39 100; stroke-dashoffset: -62; }
  to { opacity: 0; stroke-dasharray: 39 100; stroke-dashoffset: -100; }
}
.mg .mg-shields {
  display: flex;
  gap: 13px;
}
.mg .mg-shields svg {
  width: 33px;
  fill: #121e36;
  stroke: #7898c3;
  stroke-width: 2;
}
.mg .mg-shields svg path + path { fill: none; opacity: 0; }
.mg .mg-shields .is-target { stroke: var(--mg-cyan); filter: drop-shadow(0 0 6px #62e7ff9a); }
.mg .mg-shields .is-hit {
  fill: #3d5423;
  stroke: var(--mg-lime);
  filter: drop-shadow(0 0 7px #d8f65599);
}
.mg .mg-shields .is-hit path + path { opacity: 1; }
.mg .mg-balloons .mg-message, .mg.mg-balloons .mg-message { display: none; }
.mg .mg-message:has(> .mg-target[hidden]) { display: none; }
.mg .mg-message {
  padding: 10px 14px;
  border: 1px solid var(--mg-line);
  border-left: 4px solid var(--mg-cyan);
  background: #172a4b;
}
.mg .mg-target {
  display: block;
  font-size: clamp(1.2rem, 3vw, 1.75rem);
  line-height: 1.32;
  overflow-wrap: anywhere;
}
.mg .mg-heard-word {
  color: var(--mg-cyan);
  text-decoration: underline;
  text-decoration-thickness: .1em;
  text-underline-offset: .16em;
}
.mg .mg-intonation { color: var(--mg-cyan); margin-top: 5px; }

.mg .mg-sheet {
  display: grid;
  gap: 9px;
  max-height: clamp(230px, 51vh, 490px);
  padding: clamp(9px, 2vw, 20px);
  background: #fffdf4;
  color: #111c2b;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #75a9b1 #e5ecee;
}
.mg .mg-karaoke-line {
  border-left: 4px solid #ccd4da;
  padding: 4px 7px;
  color: #354257;
  font-family: "Atkinson Hyperlegible Next", "Avenir Next", system-ui, sans-serif;
  font-size: clamp(1.52rem, 3.6vw, 2.13rem);
  font-weight: 600;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.mg .mg-karaoke-line.is-current { color: #101d2b; border-color: #2f7a7c; background: #e4f6ef; }
.mg[data-difficulty="easy"] .mg-karaoke-line {
  font-size: clamp(1.7rem, 3.8vw, 2.36rem);
  line-height: 1.63;
}
.mg .mg-karaoke-word.is-current {
  color: #09132b;
  background: #def767;
  box-shadow: 0 0 0 2px #def767;
  text-decoration: underline;
  text-decoration-thickness: .09em;
  text-underline-offset: .14em;
  box-decoration-break: clone;
}
.mg .mg-actions, .mg .mg-entry {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 9px;
}
.mg.mg-karaoke .mg-actions {
  position: sticky;
  z-index: 2;
  top: var(--site-header-height, 0px);
  padding-block: 8px;
  background: #101e39;
}
.mg .mg-actions label, .mg .mg-entry label {
  display: grid;
  gap: 4px;
  color: var(--mg-muted);
  font-weight: 750;
}
.mg .mg-entry label { flex: 1 1 240px; }
.mg .mg-actions select, .mg .mg-entry input {
  width: 100%;
  min-height: 44px;
  padding: 7px 9px;
  border: 1px solid #7696c6;
  border-radius: 0;
  background: #0d1b33;
  color: var(--mg-ink);
  color-scheme: dark;
}
.mg .mg-entry input { font-size: 1.12rem; }
.mg .mg-button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #809cc5;
  border-radius: 0;
  background: #192a50;
  color: var(--mg-ink);
  font-size: .96rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
}
.mg .mg-button:hover:not(:disabled) { border-color: var(--mg-cyan); background: #263e6c; }
.mg .mg-button.mg-primary { border-color: var(--mg-lime); background: var(--mg-lime); color: var(--mg-deep); box-shadow: inset 0 -3px #9ebc37; }
.mg .mg-button.mg-primary:hover:not(:disabled) { border-color: #f2ffb5; background: #ebff99; }
.mg .mg-button:disabled { cursor: default; opacity: .52; }
.mg .mg-status {
  margin: 0;
  border-left: 3px solid var(--mg-cyan);
  padding: 8px 10px;
  background: #15324a;
  color: var(--mg-ink);
  overflow-wrap: anywhere;
}
.mg .mg-status:empty { display: none; }
.mg[data-phase="done"] .mg-status {
  border-color: var(--mg-lime);
  background: #213c34;
}

@media (max-width: 580px) {
  .mg { gap: 10px; }
  .mg.mg-karaoke .mg-actions { position: static; }
  .mg .mg-balloons { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 5px; padding: 8px; }
  .mg .mg-balloon { min-height: 96px; padding-bottom: 18px; }
  .mg .mg-balloon > span { min-height: 69px; padding: 12px 6px; }
  .mg .mg-balloon > i { top: 72px; height: 16px; }
  .mg .mg-actions .mg-button { flex: 1 1 120px; }
  .mg .mg-entry button { width: 100%; }
  .mg .mg-karaoke-line { line-height: 1.45; }
}
@media (prefers-reduced-motion: reduce) {
  .mg .mg-balloon.is-target > span, .mg .mg-balloon.is-hit > span,
  .mg .mg-balloon.is-hit > i, .mg[data-phase="running"] .mg-ship-shield { animation: none; }
  .mg .mg-beams path.is-fired { animation: none; opacity: 1; }
}
