:root {
  --ink: #241712;
  --paper: #f8e8bd;
  --paper-light: #fff5d7;
  --red: #9e2d1e;
  --gold: #f0bf39;
}

.stage-launcher {
  position: fixed;
  z-index: 2;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  min-width: 82px;
  min-height: 42px;
  padding: 7px 13px;
  color: var(--ink);
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 3px 0 #6f311b, inset 0 2px 0 #fff390;
  font: 700 17px/1 "STKaiti", "KaiTi", serif;
  letter-spacing: .08em;
  touch-action: manipulation;
}

.stage-launcher:focus-visible,
.stage-close:focus-visible,
.stage-card:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.stage-dialog {
  width: min(540px, calc(100dvw - 20px));
  max-width: none;
  max-height: min(86dvh, 760px);
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: 4px;
  box-shadow: 0 12px 35px #0008, inset 0 0 0 4px #cead76;
  font-family: "STKaiti", "KaiTi", "SimSun", serif;
}

.stage-dialog:modal {
  overscroll-behavior: contain;
}

.stage-dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: #160c0bb8;
}

.stage-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: inherit;
}

.stage-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px 10px;
  border-bottom: 2px solid #6d3d25;
  background: linear-gradient(#fff6d9, #ead2a1);
}

.stage-title {
  margin: 0;
  font-size: clamp(28px, 8dvw, 38px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: .08em;
}

.stage-subtitle {
  margin: 7px 0 0;
  color: #6f3e2c;
  font-size: 14px;
  line-height: 1.4;
}

.stage-close {
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--ink);
  background: #fff1c7;
  border: 3px solid var(--ink);
  border-radius: 50%;
  font: 900 26px/1 serif;
}

.stage-content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 18px;
  scrollbar-color: #9d612e #ead2a1;
}

.stage-group + .stage-group {
  margin-top: 15px;
}

.stage-map-title {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin: 0 0 7px;
  color: var(--red);
  font-size: 23px;
  line-height: 1;
}

.stage-map-title small {
  color: #765137;
  font-size: 13px;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.stage-card {
  min-height: 54px;
  padding: 6px 4px;
  color: var(--ink);
  background: var(--paper-light);
  border: 2px solid #7b4930;
  border-radius: 5px;
  box-shadow: 0 2px 0 #aa7848;
  font-family: inherit;
  touch-action: manipulation;
}

.stage-card strong,
.stage-card span {
  display: block;
}

.stage-card strong {
  font-size: 17px;
  line-height: 1.15;
}

.stage-card span {
  margin-top: 3px;
  color: #815e40;
  font-size: 12px;
}

.stage-card[aria-current="true"] {
  color: #fff;
  background: var(--red);
  border-color: #4d1a14;
}

.stage-card[aria-current="true"] span {
  color: #ffe2b0;
}

.stage-foot {
  padding: 9px 14px max(10px, env(safe-area-inset-bottom));
  color: #6b432d;
  background: #ead2a1;
  border-top: 2px solid #6d3d25;
  font-size: 13px;
  line-height: 1.4;
}

.stage-status {
  margin: 0;
}

@media (max-width: 430px) {
  .stage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: no-preference) {
  .stage-dialog[open] {
    animation: stage-in 140ms ease-out;
  }

  @keyframes stage-in {
    from {
      opacity: 0;
      transform: translateY(12px) scale(.98);
    }
  }
}
