body.mj-page {
  overflow: hidden;
  height: 100dvh;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.mj-app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.mj-stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(150px, 210px) minmax(240px, auto) minmax(150px, 220px);
  gap: 16px;
  align-items: center;
  justify-content: center;
  padding: 12px 18px 8px;
  min-height: 0;
}

.side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 100%;
}

.panel {
  background: rgba(15, 22, 38, 0.85);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.panel-label {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.stat-row + .stat-row { margin-top: 6px; }
.stat-row strong {
  font-family: var(--mono);
  color: var(--paper);
  font-size: 18px;
  font-weight: 700;
}

.well-frame {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
.well-wrap {
  --chrome: 150px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100%, calc(min(calc(100dvh - var(--chrome)), 820px) * 1.528));
  aspect-ratio: 1100 / 720;
  height: auto;
  background: #071018;
  border-radius: 8px;
  box-shadow:
    0 0 0 3px #1a2438,
    0 0 0 8px #0e1524,
    0 18px 50px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
#well {
  display: block;
  touch-action: manipulation;
  cursor: pointer;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 16, 0.78);
  text-align: center;
  padding: 12px;
  overflow: auto;
}
.overlay.is-on { display: flex; }
.overlay-card h2 {
  margin: 0 0 8px;
  font-size: clamp(26px, 5vw, 44px);
  letter-spacing: 0.04em;
}
.overlay-card p { margin: 0 0 14px; color: var(--muted); }

.layout-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 8px 0 16px;
}
.layout-chip {
  min-width: 72px;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--paper);
  font-family: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
.layout-chip small {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  opacity: 0.7;
}
.layout-chip.is-active {
  background: var(--gold);
  color: #1a1408;
  border-color: var(--gold);
}

#toast {
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translateX(-50%);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: 0 2px 12px #000;
  pointer-events: none;
  font-size: clamp(14px, 2.6vw, 20px);
  color: var(--gold-2);
  white-space: nowrap;
}
#toast.is-bad { color: #fb7185; }

.icon-row { display: flex; gap: 8px; }
.icon-btn {
  flex: 1;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #121a2c;
  color: var(--paper);
  cursor: pointer;
  font-family: inherit;
  font-weight: 650;
  font-size: 13px;
}
.icon-btn.is-off { opacity: 0.5; }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

.help-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
}
.help-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(243, 234, 212, 0.06);
  align-items: center;
}
.help-list kbd {
  font-family: var(--mono);
  color: var(--paper);
  background: #0b1020;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 11px;
}
.how p { margin: 0; font-size: 13px; color: var(--muted); }

#nomoves {
  margin: 0;
  font-size: 12px;
  color: #fb7185;
  min-height: 1.2em;
}

.touch-pad {
  display: none;
  padding: 8px 12px 16px;
  gap: 8px;
  grid-template-columns: 1fr 1fr 1fr;
}
.pad-btn {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #151c2e;
  color: var(--paper);
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  touch-action: manipulation;
  user-select: none;
}

.over-score {
  font-family: var(--mono);
  font-size: 28px;
  color: var(--gold);
  margin: 0 0 4px !important;
}
.best-flag {
  display: inline-block;
  background: var(--gold);
  color: #1a1408;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  margin-bottom: 10px;
}

@media (pointer: coarse), (max-width: 960px) {
  .touch-pad { display: grid; }
  .side.help { display: none; }
  .mj-stage {
    grid-template-columns: minmax(140px, 200px) minmax(0, 1fr);
    padding-bottom: 4px;
  }
  .well-wrap { --chrome: 230px; }
}

@media (max-width: 780px) {
  .mj-stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }
  .side.help { display: none; }
  .side.stats {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }
  .side.stats .panel { flex: 1 1 180px; }
  .side.stats .icon-row { flex: 1 1 100%; }
  .panel { padding: 8px; }
  .stat-row strong { font-size: 14px; }
  .well-wrap {
    --chrome: 260px;
    width: 100%;
    box-shadow: 0 0 0 2px #1a2438, 0 0 0 5px #0e1524;
  }
}
