.moon-ensemble {
  --ink: #f9f7ff;
  --muted: #aaa4c9;
  --panel: rgba(13, 12, 35, .88);
  --line: rgba(255, 255, 255, .13);
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto minmax(118px, 24vh) minmax(210px, 1fr) auto;
  width: min(100%, 430px);
  height: 100%;
  margin: 0 auto;
  min-height: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 18%, rgba(126, 83, 203, .32), transparent 30%),
    radial-gradient(circle at 10% 50%, rgba(67, 195, 219, .1), transparent 30%),
    linear-gradient(180deg, #0c0c27 0%, #070817 100%);
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  isolation: isolate;
}

.moon-ensemble *, .moon-ensemble *::before, .moon-ensemble *::after { box-sizing: border-box; }
.moon-ensemble button, .moon-ensemble input { font: inherit; }
.moon-ensemble button { color: inherit; -webkit-tap-highlight-color: transparent; }
.me-rotate { display: none; }

.moon-ensemble::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  opacity: .46;
  background-image:
    linear-gradient(180deg, rgba(7, 7, 25, .08) 0%, rgba(7, 7, 25, .18) 38%, rgba(7, 8, 23, .82) 100%),
    url("../assets/art/moon-ensemble-stage-v2-balanced.webp");
  background-position: center top, center top;
  background-repeat: no-repeat;
  background-size: cover;
  filter: saturate(.9) contrast(1.03);
  mask-image: linear-gradient(to bottom, black 0%, rgba(0,0,0,.82) 58%, rgba(0,0,0,.34) 100%);
}

.me-topbar {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  min-height: 58px;
  padding: max(8px, env(safe-area-inset-top)) 12px 5px;
  text-align: center;
  z-index: 6;
}

.me-topbar small { display: block; color: #bcb4dd; font-size: 8px; letter-spacing: .16em; }
.me-topbar strong { display: block; margin-top: 2px; font-size: 15px; }
.me-icon { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.06); font-weight: 900; }
.me-icon:active { transform: scale(.94); background: rgba(255,255,255,.12); }

.me-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 43px;
  margin: 0 10px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(10, 10, 31, .66);
  backdrop-filter: blur(10px);
  font-variant-numeric: tabular-nums;
  z-index: 5;
}

.me-hud > span:last-child { text-align: right; }
.me-hud small { display: block; color: var(--muted); font-size: 7px; letter-spacing: .12em; }
.me-hud strong { font-size: 15px; }
.me-combo { min-width: 72px; text-align: center; }
.me-combo strong { display: block; color: #fff09a; font-size: 26px; line-height: .85; text-shadow: 0 0 18px rgba(255, 231, 118, .38); }

.me-party {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin: 6px 8px 3px;
  z-index: 5;
}

.me-member {
  position: relative;
  min-width: 0;
  padding: 3px 2px 5px;
  text-align: center;
  border: 1px solid color-mix(in srgb, var(--member) 35%, transparent);
  border-radius: 11px;
  background: color-mix(in srgb, var(--member) 8%, rgba(12,12,36,.8));
  transition: transform .16s, filter .16s;
}

.me-member-avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  margin: 0 auto 2px;
  border: 1px solid color-mix(in srgb, var(--member) 72%, white);
  border-radius: 50% 50% 42% 42%;
  color: #0d1027;
  background: radial-gradient(circle at 44% 38%, white 0 13%, var(--member) 15% 58%, #171730 60%);
  box-shadow: 0 0 12px color-mix(in srgb, var(--member) 34%, transparent);
}

.me-member-avatar::after { content: ""; position: absolute; width: 31px; height: 12px; bottom: -7px; border-radius: 50% 50% 8px 8px; background: color-mix(in srgb, var(--member) 62%, #20203d); z-index: -1; }
.me-member-avatar i { display: none; }
.me-member-avatar img { width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.me-member strong { display: block; overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.me-member small { display: block; overflow: hidden; color: var(--muted); font-size: 6px; text-overflow: ellipsis; white-space: nowrap; }
.me-member-charge { display: block; height: 3px; margin: 3px 3px 0; overflow: hidden; border-radius: 3px; background: rgba(255,255,255,.08); }
.me-member-charge i { display: block; width: 0; height: 100%; background: var(--member); box-shadow: 0 0 7px var(--member); transition: width .16s; }
.me-member.is-attacking { transform: translateY(-4px) scale(1.04); filter: brightness(1.35); }
.me-member.is-active { z-index: 2; transform: translateY(-8px) scale(1.12); filter: brightness(1.65); box-shadow: 0 0 25px color-mix(in srgb, var(--member) 55%, transparent); }

.me-battle { position: relative; min-height: 118px; overflow: hidden; z-index: 1; }
.me-battle::before, .me-battle::after { content: ""; position: absolute; bottom: 23px; width: 42%; height: 48px; border-top: 1px solid rgba(179, 151, 255, .24); border-radius: 50%; background: linear-gradient(180deg, transparent, rgba(79, 66, 136, .12)); }
.me-battle::before { left: -5%; transform: rotate(6deg); }
.me-battle::after { right: -5%; transform: rotate(-6deg); }
.me-moon { position: absolute; left: 50%; top: 7px; width: 68px; height: 68px; border-radius: 50%; transform: translateX(-50%); background: radial-gradient(circle at 38% 35%, #fffbd3, #d0b2ff 55%, #714b9d); box-shadow: 0 0 42px rgba(211, 167, 255, .4); opacity: .74; }
.me-moon::after { content: ""; position: absolute; width: 54px; height: 54px; left: 18px; top: -6px; border-radius: 50%; background: #161438; }

.me-enemy {
  position: absolute;
  left: 50%;
  top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
  filter: drop-shadow(0 14px 18px #0008);
  animation: me-enemy-float 2.1s ease-in-out infinite;
}

.me-enemy-mask { display: grid; place-items: center; width: 54px; height: 63px; border: 2px solid #d8c3ff; border-radius: 55% 55% 45% 45%; color: #221235; background: linear-gradient(140deg, #f7eaff, #9f6ccb 55%, #3b245c); font-size: 28px; font-style: normal; box-shadow: inset 0 -12px 20px rgba(22,11,45,.6); }
.me-enemy.is-boss .me-enemy-mask { width: 67px; height: 70px; border-color: #ffacbe; color: #660b31; background: linear-gradient(140deg, #fff0dc, #db5d95 48%, #471544); }
.me-enemy[data-boss-phase="2"] .me-enemy-mask { box-shadow: 0 0 28px #9b62ff, inset 0 -12px 20px #251148; }
.me-enemy[data-boss-phase="3"] .me-enemy-mask { border-color: #ff536f; box-shadow: 0 0 35px #ff385e, inset 0 -12px 20px #55112a; animation: me-rage .42s infinite alternate; }
.me-enemy strong { margin-top: 1px; font-size: 10px; }
.me-enemy span { color: #ffb2c3; font-size: 7px; }
.me-slash { position: absolute; left: 50%; top: 38%; z-index: 4; padding: 5px 10px; border-radius: 99px; color: #fff4af; background: rgba(22, 12, 51, .9); font-size: 10px; font-weight: 900; opacity: 0; transform: translate(-50%, 12px) rotate(-5deg); pointer-events: none; }
.me-slash.is-visible { animation: me-slash .38s ease-out; }

.me-bars { position: absolute; inset: auto 10px 2px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; z-index: 3; }
.me-bars label { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 5px; color: var(--muted); font-size: 7px; font-weight: 800; }
.me-bars label i { height: 6px; overflow: hidden; border-radius: 6px; background: rgba(255,255,255,.1); }
.me-bars label b { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, #ff4f77, #ffb05f); transition: width .18s; }
.me-bars label:nth-child(2) b { background: linear-gradient(90deg, #6ee9ff, #8cf1a4); }
.me-bars em { color: #ded9ef; font-size: 7px; font-style: normal; font-variant-numeric: tabular-nums; }

.me-playfield {
  position: relative;
  min-height: 190px;
  margin: 2px 9px 0;
  overflow: hidden;
  border: 1px solid rgba(164, 149, 229, .22);
  border-radius: 18px 18px 8px 8px;
  background: linear-gradient(180deg, rgba(7, 8, 27, .35), rgba(10, 10, 29, .96));
  box-shadow: inset 0 -24px 50px rgba(64, 54, 123, .17), 0 8px 28px #0008;
  z-index: 3;
}

.me-playfield canvas { display: block; width: 100%; height: 100%; cursor: pointer; touch-action: none; }
.me-playfield::after { content: "넓은 판정 구역 · 레인 아무 곳이나 탭"; position: absolute; z-index: 4; right: 8px; bottom: 4px; left: 8px; color: rgba(255,255,255,.48); font-size: 7px; font-weight: 800; letter-spacing: .05em; text-align: center; pointer-events: none; }
.me-judge { position: absolute; left: 50%; top: 48%; z-index: 5; text-align: center; opacity: 0; transform: translate(-50%, 8px) scale(.9); pointer-events: none; text-shadow: 0 2px 12px #000; }
.me-judge strong { display: block; white-space: nowrap; font-size: clamp(17px, 5vw, 26px); font-weight: 950; letter-spacing: .06em; }
.me-judge small { display: block; max-width: 280px; margin-top: 1px; color: currentColor; font-size: 8px; font-weight: 800; }
.me-judge.is-visible { animation: me-judge .55s ease-out; }

.me-pads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; padding: 6px 9px max(8px, env(safe-area-inset-bottom)); z-index: 7; }
.me-pad { min-height: 82px; border: 1px solid color-mix(in srgb, var(--lane) 62%, transparent); border-radius: 14px; background: linear-gradient(180deg, color-mix(in srgb, var(--lane) 18%, #171738), #0d0d25); box-shadow: inset 0 -6px 0 rgba(0,0,0,.3), 0 5px 13px #0006; touch-action: none; }
.me-pad > span { display: block; color: var(--lane); font-size: 16px; line-height: 1; text-shadow: 0 0 12px var(--lane); }
.me-pad strong { display: block; margin-top: 3px; font-size: 11px; }
.me-pad small { color: var(--muted); font-size: 7px; }
.me-pad.is-pressed { transform: translateY(3px); filter: brightness(1.55); box-shadow: inset 0 0 24px color-mix(in srgb, var(--lane) 35%, transparent); }

.me-overlay { position: absolute; z-index: 30; inset: 0; display: none; place-items: center; padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom)); overflow: auto; background: rgba(4, 4, 17, .78); backdrop-filter: blur(12px); }
.me-overlay.is-visible { display: grid; }
.me-modal { width: min(430px, 100%); padding: 24px 20px; text-align: center; border: 1px solid rgba(255,255,255,.16); border-radius: 26px; background: linear-gradient(160deg, rgba(38, 29, 72, .98), rgba(11, 10, 29, .98)); box-shadow: 0 24px 80px #000c; }
.me-eyebrow { margin: 0 0 6px; color: #ffd77a; font-size: 9px; font-weight: 900; letter-spacing: .17em; }
.me-modal h1, .me-modal h2 { margin: 4px 0 9px; line-height: 1.1; }
.me-modal h1 { font-size: clamp(32px, 10vw, 48px); background: linear-gradient(90deg, #fff7c1, #c6b0ff, #74eeff); background-clip: text; color: transparent; }
.me-modal h2 { font-size: 25px; }
.me-modal > p:not(.me-eyebrow) { margin: 7px 0 12px; color: #c0bad8; font-size: 12px; line-height: 1.55; }
.me-difficulties { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0 4px; }
.me-difficulty { min-width: 0; padding: 10px 5px; border: 1px solid rgba(255,255,255,.13); border-radius: 14px; color: #d5cfe8; background: rgba(255,255,255,.035); text-align: center; cursor: pointer; transition: border-color .18s, background .18s, transform .18s; }
.me-difficulty strong { display: block; font-size: 12px; }
.me-difficulty small { display: block; margin-top: 3px; overflow: hidden; color: #8e88a8; font-size: 7px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.me-difficulty.is-selected { border-color: #ffe487; color: #fff3bd; background: linear-gradient(145deg, rgba(255,226,125,.18), rgba(150,112,255,.15)); box-shadow: 0 0 20px rgba(255,218,114,.12); transform: translateY(-1px); }
.me-difficulty:focus-visible { outline: 2px solid #80edff; outline-offset: 2px; }
.me-difficulty-note { min-height: 16px; margin: 0 !important; color: #8feaff !important; font-size: 9px !important; font-weight: 800; }
.moon-ensemble[data-difficulty="crescent"] .me-playfield { --difficulty-glow: #72efff; }
.moon-ensemble[data-difficulty="eclipse"] .me-playfield { --difficulty-glow: #ff6fa9; box-shadow: inset 0 0 28px rgba(255,77,145,.12); }
.me-calibration { margin: 15px 0; padding: 12px; text-align: left; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.04); }
.me-calibration label { display: flex; justify-content: space-between; font-size: 11px; font-weight: 800; }
.me-calibration output { color: #7feaff; font-variant-numeric: tabular-nums; }
.me-calibration input { width: 100%; margin: 10px 0 3px; accent-color: #8ceafa; }
.me-calibration small { color: var(--muted); font-size: 8px; }
.me-primary, .me-text { display: block; width: 100%; border: 0; cursor: pointer; }
.me-primary { margin-top: 13px; padding: 13px; border-radius: 15px; color: #171127 !important; background: linear-gradient(135deg, #ffe27d, #f09ab3); font-weight: 950; box-shadow: 0 9px 25px rgba(231, 150, 126, .25); }
.me-primary small { display: block; margin-top: 1px; font-size: 7px; letter-spacing: .12em; }
.me-text { margin-top: 5px; padding: 9px; color: var(--muted) !important; background: transparent; }
.me-primary:active, .me-text:active { transform: scale(.98); }

.me-upgrade-modal { width: min(680px, 100%); }
.me-upgrade-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.me-upgrade { min-height: 172px; padding: 15px 11px; border: 1px solid rgba(255,255,255,.15); border-radius: 18px; text-align: left; background: linear-gradient(150deg, rgba(117, 84, 185, .22), rgba(12, 11, 31, .9)); }
.me-upgrade small { color: #ffd77f; font-size: 8px; letter-spacing: .12em; }
.me-upgrade strong { display: block; margin: 8px 0; font-size: 15px; }
.me-upgrade p { min-height: 45px; margin: 0; color: #c2bbda; font-size: 10px; line-height: 1.45; }
.me-upgrade em { display: block; margin-top: 8px; color: #7feafa; font-size: 7px; font-style: normal; }
.me-upgrade:active { transform: translateY(2px); filter: brightness(1.2); }

.me-result-modal { padding-top: 18px; }
.me-grade { display: grid; place-items: center; width: 65px; height: 65px; margin: 0 auto 5px; border: 2px solid #ffe07c; border-radius: 50%; color: #ffe998; font: 950 34px/1 Georgia, serif; box-shadow: 0 0 30px rgba(255, 222, 99, .22); }
.me-result-score { margin: 10px 0; padding: 10px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.04); }
.me-result-score small { display: block; color: var(--muted); font-size: 8px; }
.me-result-score strong { color: #fff0a5; font-size: 29px; }
.me-result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.me-result-stats span { padding: 7px 3px; border: 1px solid rgba(255,255,255,.09); border-radius: 10px; background: rgba(255,255,255,.03); }
.me-result-stats small { display: block; color: var(--muted); font-size: 6px; }
.me-result-stats strong { display: block; margin-top: 2px; font-size: 11px; }
.me-build { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.me-build span { padding: 4px 8px; border: 1px solid rgba(137, 230, 255, .24); border-radius: 99px; color: #8ceaff; background: rgba(101, 207, 238, .08); font-size: 8px; }
.me-result-modal details { max-height: 120px; margin-top: 9px; overflow: auto; text-align: left; border-top: 1px solid var(--line); color: var(--muted); font-size: 8px; }
.me-result-modal summary { padding: 8px 0 4px; cursor: pointer; }
.me-result-modal ol { margin: 3px 0 0; padding-left: 22px; }
.me-result-modal li { margin: 3px 0; }
.me-result-modal time { display: inline-block; min-width: 37px; margin-right: 5px; color: #8deaff; font-variant-numeric: tabular-nums; }

.moon-ensemble[data-phase="paused"] .me-pad { pointer-events: none; }
.moon-ensemble[data-phase="playing"] .me-enemy { transition: filter .18s; }

.game-shell.moon-game-active > header { display: none; }
.game-shell.moon-game-active .game-slot { height: 100dvh; }

@keyframes me-enemy-float { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -5px); } }
@keyframes me-rage { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes me-slash { 0% { opacity: 0; transform: translate(-50%, 16px) rotate(-5deg) scale(.8); } 35% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -24px) rotate(3deg) scale(1.18); } }
@keyframes me-judge { 0% { opacity: 0; transform: translate(-50%, 12px) scale(.8); } 24% { opacity: 1; transform: translate(-50%, 0) scale(1.07); } 72% { opacity: 1; transform: translate(-50%, -3px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -15px) scale(.94); } }

@media (max-width: 430px) {
  .moon-ensemble { grid-template-rows: auto auto auto minmax(108px, 20vh) minmax(190px, 1fr) auto; }
  .me-member small { display: none; }
  .me-bars { grid-template-columns: 1fr; gap: 2px; }
  .me-bars label:nth-child(2) { direction: rtl; }
  .me-bars label:nth-child(2) i, .me-bars label:nth-child(2) em { direction: ltr; }
  .me-upgrade-grid { grid-template-columns: 1fr; }
  .me-upgrade { min-height: 0; }
  .me-upgrade p { min-height: 0; }
}

@media (max-height: 670px) {
  .moon-ensemble { grid-template-rows: auto auto auto 105px minmax(170px, 1fr) auto; min-height: 520px; }
  .me-topbar { min-height: 48px; }
  .me-party { margin-top: 3px; }
  .me-member-avatar { width: 19px; height: 19px; }
  .me-member-avatar::after { width: 24px; height: 9px; bottom: -5px; }
  .me-pad { min-height: 62px; }
  .me-modal { padding: 17px; }
  .me-ready-card h1 { font-size: 28px; }
  .me-ready-card > p:not(.me-eyebrow) { margin: 4px 0 7px; font-size: 10px; }
  .me-difficulties { margin-top: 7px; }
  .me-difficulty { padding: 7px 4px; }
  .me-calibration { margin: 8px 0; padding: 8px 10px; }
}

@media (orientation: landscape) and (pointer: coarse) {
  .moon-ensemble > :not(.me-rotate) { visibility: hidden; }
  .me-rotate {
    position: absolute;
    z-index: 80;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    padding: 28px;
    color: #f8f1ff;
    background: radial-gradient(circle at 50% 35%, #35245c, #090817 70%);
    text-align: center;
  }
  .me-rotate span { display: grid; place-items: center; width: 74px; height: 74px; border: 1px solid rgba(255,255,255,.22); border-radius: 24px; color: #ffe18a; background: rgba(255,255,255,.07); font-size: 46px; box-shadow: 0 0 35px rgb(174 124 255 / 25%); animation: me-rotate-phone 1.5s ease-in-out infinite alternate; }
  .me-rotate strong { font-size: 18px; }
  .me-rotate small { max-width: 290px; color: #bbb3ce; font-size: 11px; line-height: 1.55; }
}

@keyframes me-rotate-phone { from { transform: rotate(90deg); } to { transform: rotate(0deg); } }

@media (prefers-reduced-motion: reduce) {
  .moon-ensemble *, .moon-ensemble *::before, .moon-ensemble *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

@media (prefers-contrast: more) {
  .moon-ensemble { --line: rgba(255,255,255,.45); }
  .me-pad, .me-playfield, .me-member { border-width: 2px; }
  .me-member small, .me-topbar small, .me-hud small { color: #e2def2; }
}
