/* CRITICAL: author display rules must not override HTML hidden */
[hidden] {
  display: none !important;
}

.mg-step {
  display: none;
}

.mg-step.is-active {
  display: grid;
  place-items: center;
  min-height: min(58vh, 520px);
  animation: mg-step-in 0.28s ease;
}

.mg-step.is-active.mg-step--wide {
  place-items: stretch;
  min-height: 0;
}

.mg-shell--game {
  padding-top: 1.25rem;
  padding-bottom: 3rem;
}

.mg-gamebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.mg-back {
  justify-self: start;
  color: var(--muted);
  font-weight: 500;
}

.mg-back:hover {
  color: var(--brand);
}

.mg-gamebar__center {
  text-align: center;
}

.mg-gamebar__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.mg-gamebar__status {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.mg-gamebar__meta {
  justify-self: end;
  font-size: 0.85rem;
  color: var(--brand);
  font-weight: 600;
}

/* Stepper */
.mg-steps {
  list-style: none;
  margin: 0 0 1.75rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
}

.mg-steps li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(145, 168, 184, 0.18);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0.55;
}

.mg-steps li span {
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: rgba(145, 168, 184, 0.15);
  font-size: 0.72rem;
  font-weight: 700;
}

.mg-steps li.is-done {
  opacity: 0.85;
  color: var(--ok);
  border-color: rgba(93, 222, 160, 0.28);
}

.mg-steps li.is-done span {
  background: rgba(93, 222, 160, 0.2);
  color: var(--ok);
}

.mg-steps li.is-current {
  opacity: 1;
  color: var(--text);
  border-color: rgba(63, 208, 201, 0.45);
  background: rgba(63, 208, 201, 0.08);
}

.mg-steps li.is-current span {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #042028;
}

.mg-steps.is-hidden {
  display: none;
}

/* step visibility controlled via .is-active (+ [hidden] backup) */

.mg-step__card {
  width: min(440px, 100%);
  padding: 1.6rem 1.5rem 1.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.mg-step__card--wait {
  text-align: center;
  width: min(520px, 100%);
}

.mg-step__eyebrow {
  margin: 0 0 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
}

.mg-panel__card h2,
.mg-step__card h2 {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  font-size: 1.55rem;
}

.mg-panel__card > p,
.mg-step__card > p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.mg-actions--center {
  justify-content: center;
  margin-top: 1.25rem;
}

.mg-mode {
  display: grid;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.mg-mode__btn {
  appearance: none;
  text-align: left;
  cursor: pointer;
  border-radius: 16px;
  border: 1px solid rgba(145, 168, 184, 0.25);
  background: rgba(5, 14, 24, 0.4);
  color: var(--text);
  padding: 1rem 1.1rem;
  font: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.mg-mode__btn strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin-bottom: 0.2rem;
}

.mg-mode__btn span {
  color: var(--muted);
  font-size: 0.9rem;
}

.mg-mode__btn:hover {
  border-color: rgba(63, 208, 201, 0.5);
  background: rgba(63, 208, 201, 0.08);
  transform: translateY(-1px);
}

.mg-wait-pulse {
  display: grid;
  place-items: center;
  margin: 0.5rem auto 1rem;
  width: 64px;
  height: 64px;
}

.mg-wait-pulse span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 0 rgba(63, 208, 201, 0.5);
  animation: mg-pulse 1.4s ease-out infinite;
}

.mg-invite {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  margin: 1.15rem 0 0.75rem;
}

.mg-invite input {
  border-radius: 14px;
  border: 1px solid rgba(145, 168, 184, 0.28);
  background: rgba(5, 14, 24, 0.55);
  color: var(--text);
  padding: 0.85rem 1rem;
  font: inherit;
}

.mg-hint {
  font-size: 0.9rem;
}

.mg-hint--code {
  margin-top: 0.35rem;
  color: var(--muted);
}

.mg-hint--code strong {
  color: var(--brand);
  letter-spacing: 0.08em;
}

.mg-place,
.mg-battle {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.mg-battle {
  grid-template-columns: 1fr 1fr;
}

.mg-place__controls {
  width: 100%;
  position: sticky;
  top: 1rem;
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.mg-fleet {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.mg-fleet li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  border: 1px solid rgba(145, 168, 184, 0.2);
  background: rgba(5, 14, 24, 0.35);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.mg-fleet li.is-active {
  border-color: var(--brand);
  background: rgba(63, 208, 201, 0.1);
}

.mg-fleet li.is-placed {
  opacity: 0.55;
}

.mg-fleet__name {
  font-weight: 600;
  font-size: 0.92rem;
}

.mg-fleet__size {
  display: flex;
  gap: 3px;
}

.mg-fleet__size i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--brand-deep);
  font-style: normal;
}

.mg-board-wrap {
  display: grid;
  gap: 0.65rem;
  justify-items: center;
}

.mg-board-label {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  color: #c5d8e4;
}

.mg-board {
  --cell: clamp(28px, 6.5vw, 42px);
  display: grid;
  grid-template-columns: var(--cell) repeat(10, var(--cell));
  grid-template-rows: var(--cell) repeat(10, var(--cell));
  gap: 3px;
  padding: 0.85rem;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(160deg, rgba(12, 40, 58, 0.9), rgba(8, 22, 36, 0.95));
  box-shadow: var(--shadow);
  user-select: none;
}

.mg-cell,
.mg-axis {
  width: var(--cell);
  height: var(--cell);
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 600;
}

.mg-axis {
  color: var(--muted);
}

.mg-cell {
  background: rgba(120, 170, 190, 0.1);
  border: 1px solid rgba(160, 210, 230, 0.1);
  cursor: default;
  transition: background 0.12s ease, transform 0.12s ease;
}

.mg-board--enemy .mg-cell:not(.is-shot) {
  cursor: pointer;
}

.mg-board--enemy .mg-cell:not(.is-shot):hover {
  background: rgba(63, 208, 201, 0.22);
  transform: scale(1.04);
}

.mg-cell.is-ship {
  background: linear-gradient(180deg, #49c3bf, #1f8f96);
  border-color: transparent;
}

.mg-cell.is-preview {
  background: rgba(63, 208, 201, 0.35);
  border-color: rgba(63, 208, 201, 0.55);
}

.mg-cell.is-preview-bad {
  background: rgba(255, 107, 107, 0.35);
  border-color: rgba(255, 107, 107, 0.55);
}

.mg-cell.is-hit {
  background: var(--danger);
  border-color: transparent;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.mg-cell.is-miss {
  background: rgba(190, 210, 220, 0.28);
  border-color: transparent;
}

.mg-cell.is-hit::after,
.mg-cell.is-miss::after {
  content: "";
  width: 38%;
  height: 38%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
}

.mg-cell.is-miss::after {
  background: rgba(20, 35, 48, 0.55);
}

.mg-panel__card--result {
  text-align: center;
}

.mg-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 50;
  padding: 0.85rem 1.15rem;
  border-radius: 999px;
  background: rgba(10, 24, 36, 0.92);
  border: 1px solid rgba(63, 208, 201, 0.35);
  box-shadow: var(--shadow);
  font-weight: 500;
}

kbd {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  border: 1px solid rgba(145, 168, 184, 0.35);
  background: rgba(5, 14, 24, 0.45);
  font-size: 0.8em;
}

@keyframes mg-pulse {
  0% { box-shadow: 0 0 0 0 rgba(63, 208, 201, 0.55); }
  70% { box-shadow: 0 0 0 18px rgba(63, 208, 201, 0); }
  100% { box-shadow: 0 0 0 0 rgba(63, 208, 201, 0); }
}

@keyframes mg-step-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .mg-place,
  .mg-battle {
    grid-template-columns: 1fr;
  }

  .mg-gamebar {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .mg-back,
  .mg-gamebar__meta {
    justify-self: center;
  }

  .mg-invite {
    grid-template-columns: 1fr;
  }

  .mg-place__controls {
    position: static;
  }

  .mg-steps li {
    font-size: 0;
    gap: 0;
    padding: 0.3rem;
  }

  .mg-steps li span {
    font-size: 0.72rem;
  }
}

/* Hit explosion overlay */
.mg-fx {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(8, 16, 28, 0.55), rgba(8, 16, 28, 0.82));
  opacity: 0;
  transition: opacity 0.18s ease;
}

.mg-fx.is-on {
  opacity: 1;
}

.mg-fx__video {
  width: min(920px, 94vw);
  height: auto;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 18px;
  filter: drop-shadow(0 20px 50px rgba(0, 0, 0, 0.55));
}

/* mobile flow lock */

@media (max-width: 900px) {
  .mg-shell--game {
    width: min(100% - 1.25rem, 1100px);
    padding-top: 0.75rem;
    padding-bottom: 2rem;
  }

  .mg-steps {
    margin-bottom: 1rem;
    gap: 0.35rem;
  }

  .mg-step.is-active {
    min-height: auto;
    place-items: stretch;
  }

  .mg-step__card {
    width: 100%;
    padding: 1.25rem 1.1rem;
  }

  .mg-place,
  .mg-battle {
    gap: 1rem;
  }

  .mg-board {
    --cell: clamp(26px, 8.2vw, 36px);
    gap: 2px;
    padding: 0.55rem;
  }

  .mg-gamebar__title {
    font-size: 1.15rem;
  }

  .mg-fx__video {
    width: min(100vw, 560px);
    max-height: 70vh;
    border-radius: 0;
  }
}
