:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6dff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --line: rgba(255, 255, 255, 0.08);
  --green: #3fd36a;
  --p2: #ff9a3d;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 8px;
}
button {
  font: inherit;
  color: inherit;
}
[hidden] {
  display: none !important;
}
.mg-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.mg-shell {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ---------- HUD ---------- */
.mg-hud {
  width: 100%;
  max-width: 760px;
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.mg-chip {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5px 4px;
  border-radius: 999px;
  background: linear-gradient(180deg, #27283c, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 10px rgba(0, 0, 0, 0.25);
  line-height: 1.05;
}
.mg-chip span {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.mg-chip strong {
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mg-chip.is-bump {
  animation: mg-bump 0.35s ease;
}
.mg-chip-player {
  background: linear-gradient(180deg, #7b5cff, #5230e6);
}
.mg-chip-player span {
  color: #e2dbff;
}
.mg-chip-player.is-p2 {
  background: linear-gradient(180deg, #ffb35c, #f07a16);
}
.mg-chip-player.is-p2 span {
  color: #fff0dc;
}
.mg-chip-strokes.is-warn strong {
  color: #ff6b7d;
}
.mg-icon-button {
  flex: 0 0 auto;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 10px rgba(0, 0, 0, 0.25);
}
.mg-icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.mg-icon-button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---------- Stage ---------- */
.mg-stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  border-radius: 22px;
  overflow: hidden;
  background: #1f6b34;
  box-shadow:
    0 0 0 1px var(--line),
    0 18px 40px rgba(0, 0, 0, 0.45);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.mg-stage.is-shake {
  animation: mg-shake 0.34s ease;
}
#mg-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
#mg-canvas:focus {
  outline: none;
}
#mg-canvas:focus-visible {
  outline: 3px solid #b9a8ff;
  outline-offset: -3px;
  border-radius: 22px;
}

.mg-banner {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translate(-50%, -140%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  background: rgba(20, 21, 36, 0.86);
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  white-space: nowrap;
  max-width: calc(100% - 20px);
  opacity: 0;
  transition:
    transform 0.4s cubic-bezier(0.2, 1.4, 0.4, 1),
    opacity 0.3s ease;
  pointer-events: none;
}
.mg-banner.is-on {
  transform: translate(-50%, 0);
  opacity: 1;
}
.mg-banner-hole {
  padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #8a6dff, #5a36e0);
  font-weight: 900;
  font-size: 14px;
}
.mg-banner.is-p2 .mg-banner-hole {
  background: linear-gradient(180deg, #ffb35c, #f07a16);
}
.mg-banner-name {
  font-weight: 900;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mg-banner-par {
  font-weight: 800;
  font-size: 13px;
  color: var(--muted);
}

.mg-pop {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(0.3);
  font-size: clamp(30px, 7vw, 56px);
  font-weight: 900;
  letter-spacing: 0.01em;
  color: #fff;
  text-shadow:
    0 4px 0 rgba(0, 0, 0, 0.25),
    0 10px 30px rgba(0, 0, 0, 0.45);
  -webkit-text-stroke: 2px rgba(20, 10, 60, 0.35);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.mg-pop.is-on {
  animation: mg-pop 1.5s cubic-bezier(0.2, 1.3, 0.4, 1) forwards;
}
.mg-pop.eagle {
  color: #ffe45c;
}
.mg-pop.birdie {
  color: #7dffa0;
}
.mg-pop.par {
  color: #ffffff;
}
.mg-pop.bogey {
  color: #ffc59a;
}
.mg-pop.double {
  color: #ff9aa6;
}
.mg-pop.water {
  color: #8fe3ff;
  font-size: clamp(24px, 5vw, 38px);
}

/* ---------- Overlays ---------- */
.mg-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: radial-gradient(
    ellipse at center,
    rgba(15, 16, 32, 0.55),
    rgba(15, 16, 32, 0.85)
  );
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
}
.mg-card {
  width: min(340px, 100%);
  padding: 18px 18px 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, #25263a, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: mg-card-in 0.35s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.mg-card-wide {
  width: min(560px, 100%);
}
.mg-logo svg {
  width: 110px;
  height: 82px;
  display: block;
  margin: -4px auto 0;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4));
}
.mg-title {
  margin: 2px 0 4px;
  font-size: 30px;
  font-weight: 900;
  line-height: 1.05;
  background: linear-gradient(180deg, #ffffff, #d4ccff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.mg-title-small {
  font-size: 24px;
}
.mg-lead {
  margin: 0 0 12px;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.35;
}
.mg-lead-small {
  margin-bottom: 10px;
  font-size: 13px;
}
.mg-seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: #121322;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}
.mg-seg-button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
}
.mg-seg-button[aria-pressed="true"] {
  background: linear-gradient(180deg, #8a6dff, #6842ff);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 3px 8px rgba(104, 66, 255, 0.45);
}
.mg-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mg-actions-row {
  flex-direction: row;
  justify-content: center;
  margin-top: 12px;
}
.mg-actions-row .mg-button {
  flex: 1 1 0;
  max-width: 200px;
}
.mg-button {
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--text);
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #17182a,
    0 8px 16px rgba(0, 0, 0, 0.3);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}
.mg-button:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 1px 0 #17182a;
}
.mg-button-primary {
  background: linear-gradient(180deg, #8166ff, #6842ff);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 4px 0 #3f22b8,
    0 10px 22px rgba(104, 66, 255, 0.45);
}
.mg-button-primary:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 1px 0 #3f22b8;
}
.mg-button-big {
  min-height: 54px;
  font-size: 19px;
}
.mg-best-line {
  margin: 12px 0 0;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}
.mg-best-line strong {
  color: #ffe45c;
}
:is(button, .mg-hole-button):focus-visible {
  outline: 3px solid #b9a8ff;
  outline-offset: 3px;
}

/* Hole select */
.mg-hole-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}
.mg-hole-button {
  position: relative;
  min-height: 52px;
  padding: 4px 2px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #3bc15d, #23913e);
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 3px 0 #16632a;
}
.mg-hole-button b {
  font-size: 18px;
  font-weight: 900;
}
.mg-hole-button small {
  font-size: 10px;
  font-weight: 800;
  opacity: 0.9;
}
.mg-hole-button:disabled {
  background: #2a2b3d;
  color: #6e7088;
  cursor: default;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Scorecard */
.mg-kicker {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-2);
}
.mg-sc-summary {
  margin: 2px 0 6px;
  font-size: 26px;
  font-weight: 900;
  line-height: 1.15;
}
.mg-sc-summary small {
  display: block;
  font-size: 14px;
  font-weight: 800;
  color: var(--muted);
}
.mg-newbest {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe45c, #ffb300);
  color: #3a2600;
  font-weight: 900;
  font-size: 13px;
  animation: mg-bump 0.6s ease 2;
}
.mg-table-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
}
.mg-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 2px;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
}
.mg-table th,
.mg-table td {
  padding: 4px 0;
  text-align: center;
  border-radius: 7px;
  background: #15162a;
}
.mg-table th {
  color: var(--muted);
  font-size: 11px;
}
.mg-table th[scope="row"] {
  width: 44px;
  text-align: left;
  padding-left: 6px;
  background: transparent;
}
.mg-table .mg-row-par td {
  color: var(--muted);
}
.mg-table td.is-current {
  box-shadow: inset 0 0 0 2px var(--accent-2);
}
.mg-table td.eagle {
  background: linear-gradient(180deg, #ffe45c, #ffb300);
  color: #3a2600;
}
.mg-table td.birdie {
  background: linear-gradient(180deg, #54e27c, #22a64a);
}
.mg-table td.bogey {
  background: #5a3a3f;
}
.mg-table td.double {
  background: #7a2e3b;
}
.mg-table td.mg-total-cell {
  background: #2a2b3d;
  color: #fff;
}
.mg-p2-dot,
.mg-p1-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
  background: var(--accent-2);
  vertical-align: 1px;
}
.mg-p2-dot {
  background: var(--p2);
}

.mg-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  line-height: 1.5;
}
.mg-help-keys {
  margin-left: 6px;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #121322;
  font: inherit;
  font-size: 11px;
  font-weight: 900;
  color: #fff;
}

@keyframes mg-bump {
  0%,
  100% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.14);
  }
}
@keyframes mg-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-7px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(2px);
  }
}
@keyframes mg-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(-8deg);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15) rotate(3deg);
  }
  30% {
    transform: translate(-50%, -50%) scale(1) rotate(0);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -60%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -75%) scale(0.95);
  }
}
@keyframes mg-card-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(10px);
  }
}

@media (max-width: 520px) {
  .mg-chip-best {
    display: none;
  }
  .mg-chip strong {
    font-size: 16px;
  }
  .mg-chip span {
    font-size: 9px;
    letter-spacing: 0.04em;
  }
  .mg-help-keys {
    display: none;
  }
  .mg-hole-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 5px;
  }
  .mg-hole-button {
    min-height: 46px;
  }
  .mg-table {
    font-size: 12px;
    border-spacing: 1px;
  }
  .mg-table th[scope="row"] {
    width: 34px;
    padding-left: 2px;
  }
}
@media (max-width: 360px) {
  body {
    padding: 6px;
  }
  .mg-hud {
    gap: 4px;
  }
  .mg-icon-button {
    width: 40px;
    min-height: 40px;
  }
  .mg-card {
    padding: 14px 12px 12px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .mg-chip.is-bump,
  .mg-stage.is-shake,
  .mg-newbest,
  .mg-card {
    animation: none;
  }
  .mg-banner {
    transition: opacity 0.2s ease;
  }
  .mg-pop.is-on {
    animation: mg-pop-fade 1.5s linear forwards;
  }
  @keyframes mg-pop-fade {
    0%,
    80% {
      opacity: 1;
      transform: translate(-50%, -50%) scale(1);
    }
    100% {
      opacity: 0;
      transform: translate(-50%, -50%) scale(1);
    }
  }
}
