*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #05060c;
  --panel: #0b0f18;
  --cyan: #2ee8ff;
  --magenta: #ff3ec8;
  --mint: #6dffcf;
  --text: #e8f2ff;
  --muted: #8fa2be;
  --wall: #1b2333;
  --danger: #ff6b47;
  --v: 20261119-g3;
  --term: #ffd54a;
  --gate: #6dffcf;
  --blink: #ffb84d;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, rgba(46, 232, 255, 0.07), transparent 55%),
    radial-gradient(ellipse 80% 60% at 100% 40%, rgba(255, 62, 200, 0.06), transparent 50%),
    var(--bg);
}

.shell {
  width: min(100%, 430px);
  margin: 0 auto;
  padding: 0.55rem 0.75rem calc(0.65rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 100svh;
  position: relative;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.back {
  color: var(--mint);
  text-decoration: none;
  font-size: 0.82rem;
}

.brand {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.brand strong {
  display: block;
  color: var(--text);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
}

.ghost-button,
.btn-primary {
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

.btn-primary {
  background: linear-gradient(135deg, rgba(46, 232, 255, 0.2), rgba(255, 62, 200, 0.15));
  border-color: rgba(46, 232, 255, 0.35);
  color: var(--text);
  padding: 0.7rem 1rem;
  font-weight: 700;
  width: 100%;
}

.play-intro h1 {
  margin: 0.2rem 0 0.35rem;
  font-size: 1.35rem;
  line-height: 1.25;
}

.play-intro h1 span {
  display: block;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}

.kicker {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  color: var(--mint);
}

.lead,
.rule-list {
  margin: 0.35rem 0;
  font-size: 0.88rem;
  line-height: 1.55;
}

.rule-list {
  padding-left: 1.1rem;
}

.rule-list li {
  margin: 0.15rem 0;
}

.rule-list strong {
  color: var(--cyan);
}

.rule-mirror strong {
  color: var(--magenta);
}

.console[hidden],
.summary[hidden],
.play-intro[hidden] {
  display: none !important;
}

.console:not([hidden]) {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 0;
}

.scene-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, transparent 0%, rgba(8, 20, 40, 0.5) 40%, rgba(18, 8, 28, 0.55) 100%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 18px,
      rgba(46, 232, 255, 0.04) 18px,
      rgba(46, 232, 255, 0.04) 19px
    ),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 28px,
      rgba(255, 62, 200, 0.03) 28px,
      rgba(255, 62, 200, 0.03) 29px
    );
  border-radius: 14px;
  mask-image: linear-gradient(180deg, #000 0%, #000 88%, transparent 100%);
}

.console > *:not(.scene-backdrop) {
  position: relative;
  z-index: 1;
}

.mirror-bar {
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
  margin: 0;
  padding: 0.28rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: rgba(11, 15, 24, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.mirror-bar--intro {
  margin: 0.25rem 0 0.35rem;
}

.mirror-left {
  color: var(--cyan);
}

.mirror-right {
  color: var(--magenta);
}

.mission-strip {
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.06em;
}

.board-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.45rem;
  margin: 0;
  padding: 0.3rem 0.4rem;
  list-style: none;
  font-size: 0.62rem;
  line-height: 1.3;
  background: rgba(11, 15, 24, 0.85);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.board-legend li {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.board-legend .swatch {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
  flex-shrink: 0;
}

.leg-term .swatch {
  border-radius: 50%;
  background: var(--term);
  box-shadow: 0 0 6px rgba(255, 213, 74, 0.5);
}

.leg-gate .swatch {
  background: transparent;
  border: 2px solid var(--gate);
}

.leg-blink .swatch {
  background: var(--blink);
  animation: blink-swatch 1.2s ease-in-out infinite;
}

.leg-hazard .swatch {
  background: var(--danger);
}

@keyframes blink-swatch {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  font-size: 0.72rem;
}

.hud div {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 0.25rem 0.35rem;
}

.hud span {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
}

.hud strong {
  font-size: 0.95rem;
}

.canvas-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  background: #060912;
}

.hint-arrow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.2rem;
  color: var(--mint);
  text-shadow: 0 0 18px rgba(109, 255, 207, 0.65);
  opacity: 0;
  transition: opacity 0.2s;
}

.hint-arrow.show {
  opacity: 0.92;
}

.controls-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.dpad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, minmax(44px, 1fr));
  gap: 0.35rem;
  max-width: 220px;
}

.dpad button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 12px;
  font-size: 1.3rem;
  cursor: pointer;
}

.dpad button:active:not(:disabled) {
  background: rgba(46, 232, 255, 0.18);
  border-color: var(--cyan);
}

.dpad button:disabled {
  opacity: 0.35;
}

.dpad .spacer {
  visibility: hidden;
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.side-actions button {
  min-width: 4.5rem;
}

.operator {
  display: flex;
  gap: 0.45rem;
  align-items: flex-start;
  padding: 0.45rem 0.55rem;
  background: var(--panel);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: auto;
}

.op-icon {
  opacity: 0.92;
}

.op-label {
  margin: 0;
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.op-msg {
  margin: 0.1rem 0 0;
  font-size: 0.82rem;
  line-height: 1.4;
}

.summary h2 {
  margin: 0.2rem 0;
}

.sum-rank {
  font-size: 2rem;
  font-weight: 800;
  color: var(--mint);
  margin: 0.2rem 0;
}

#sum-stats {
  margin: 0.4rem 0 0.8rem;
  padding-left: 1.1rem;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.records {
  font-size: 0.78rem;
  color: var(--muted);
}

html[data-capture="1"] .capture-hide {
  display: none !important;
}

html[data-capture="1"] .shell {
  max-width: 430px;
  padding-top: 0.35rem;
}

html[data-capture="1"] .masthead,
html[data-capture="1"] .play-intro {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .hint-arrow {
    transition: none;
  }
}

@media (min-width: 720px) {
  .shell {
    width: min(100%, 480px);
  }
}

html[data-promo-shot="1"] .capture-hide,
html[data-promo-og="1"] .capture-hide {
  display: none !important;
}

html[data-promo-shot="1"] body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(ellipse 90% 55% at 50% 0%, rgba(46, 232, 255, 0.1), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 60%, rgba(255, 62, 200, 0.08), transparent 50%),
    radial-gradient(ellipse 80% 45% at 0% 80%, rgba(46, 232, 255, 0.06), transparent 45%),
    var(--bg);
}

html[data-promo-shot="1"] .shell {
  width: 100%;
  max-width: 390px;
  min-height: 100svh;
  padding: 0.5rem 0.65rem calc(0.55rem + env(safe-area-inset-bottom));
  justify-content: stretch;
}

html[data-promo-shot="1"] .console {
  flex: 1;
  min-height: calc(100svh - 1rem);
}

html[data-promo-shot="1"] .scene-backdrop {
  mask-image: none;
  opacity: 0.95;
}

html[data-promo-shot="1"] .canvas-wrap {
  flex: 0 0 auto;
}

html[data-promo-shot="1"] .operator {
  margin-top: auto;
}

html[data-promo-shot="1"] .summary {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1rem 0.5rem;
}

html[data-promo-shot="1"] .summary[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .leg-blink .swatch {
    animation: none;
    opacity: 0.85;
  }
}