.bem-shell {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: hidden;
  color: #f1e9dc;
  background:
    radial-gradient(circle at 50% 12%, rgba(124, 91, 54, 0.18), transparent 36%),
    #121011;
  font-family: Pretendard, system-ui, sans-serif;
}

.bem-header {
  display: flex;
  flex: 0 0 auto;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: max(10px, env(safe-area-inset-top)) clamp(14px, 3vw, 32px) 10px;
  border-bottom: 1px solid rgba(225, 198, 148, 0.24);
  background: rgba(15, 12, 12, 0.94);
}

.bem-header h1 {
  margin: 2px 0 0;
  font: 600 clamp(1.05rem, 2vw, 1.45rem)/1.2 ui-serif, Georgia, serif;
  letter-spacing: 0.04em;
}

.bem-kicker {
  color: #bda77f;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
}

.bem-floor-tabs {
  display: flex;
  gap: 8px;
}

.bem-header-controls,
.bem-move-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bem-floor-tabs button {
  min-height: 44px;
  border: 1px solid rgba(225, 198, 148, 0.36);
  border-radius: 999px;
  padding: 8px 14px;
  color: inherit;
  background: rgba(74, 55, 39, 0.44);
  touch-action: manipulation;
}

.bem-floor-tabs button[aria-pressed="true"] {
  border-color: #e6c98f;
  color: #191412;
  background: #e6c98f;
}

.bem-close,
.bem-move-controls button {
  min-height: 44px;
  border: 1px solid rgba(225, 198, 148, 0.36);
  border-radius: 999px;
  padding: 8px 16px;
  color: inherit;
  background: rgba(38, 31, 29, 0.9);
  touch-action: manipulation;
}

.bem-move-controls button.is-primary:not(:disabled) {
  border-color: #e6c98f;
  color: #191412;
  background: #e6c98f;
}

.bem-move-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.bem-workspace {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 14px;
  padding: 14px clamp(12px, 2.4vw, 28px);
  overflow: hidden;
}

.bem-map-panel,
.bem-status {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(225, 198, 148, 0.26);
  border-radius: 18px;
  background: rgba(27, 22, 21, 0.9);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.bem-map-panel {
  position: relative;
  display: grid;
  place-items: center;
  overflow: auto hidden;
  scrollbar-color: rgba(225, 198, 148, 0.42) transparent;
}

.bem-pan-hint {
  display: none;
  position: sticky;
  right: 10px;
  bottom: 10px;
  align-self: end;
  justify-self: end;
  z-index: 3;
  border: 1px solid rgba(225, 198, 148, 0.24);
  border-radius: 999px;
  padding: 5px 9px;
  color: #d8c9b6;
  background: rgba(18, 16, 17, 0.86);
  font-size: 0.66rem;
  pointer-events: none;
}

.bem-map-panel svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
}

.bem-shell [hidden] {
  display: none !important;
}

.bem-edge {
  fill: none;
  stroke: rgba(210, 190, 157, 0.32);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke 160ms ease, stroke-width 160ms ease;
}

.bem-edge.is-route {
  stroke: #e8bd67;
  stroke-width: 16;
  filter: drop-shadow(0 0 8px rgba(232, 189, 103, 0.42));
}

.bem-room-shape,
.bem-connector-shape,
.bem-service-passage {
  fill: #272120;
  stroke: #7f6b56;
  stroke-width: 2;
}

.bem-room.is-available .bem-room-shape {
  fill: #302821;
  stroke: #c4a56d;
}

.bem-room.is-visited .bem-room-shape {
  fill: #38413a;
  stroke: #849d84;
}

.bem-room.is-current .bem-room-shape {
  fill: #77582f;
  stroke: #ffe0a0;
  stroke-width: 5;
  filter: drop-shadow(0 0 12px rgba(255, 214, 137, 0.55));
}

.bem-room.is-selected .bem-room-shape {
  fill: #674f2d;
  stroke: #f5c86f;
  stroke-width: 5;
  filter: drop-shadow(0 0 12px rgba(245, 200, 111, 0.52));
}

.bem-room.is-locked .bem-room-shape,
.bem-connector.is-locked .bem-connector-shape {
  fill: #1c1919;
  stroke: #554b48;
  stroke-dasharray: 9 7;
}

.bem-hit-region {
  fill: transparent;
  stroke: none;
  pointer-events: all;
}

.bem-room,
.bem-connector {
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
}

.bem-room:focus-visible .bem-room-shape,
.bem-connector:focus-visible .bem-connector-shape {
  stroke: #fff3c7;
  stroke-width: 6;
  filter: drop-shadow(0 0 10px rgba(255, 243, 199, 0.72));
}

.bem-room-label,
.bem-connector-label,
.bem-floor-lock-label,
.bem-lock,
.bem-anchor text {
  fill: #f0e7d8;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-size: 17px;
  font-weight: 700;
}

.bem-connector-label {
  font-size: 11px;
}

.bem-lock {
  fill: #a5968e;
  font-size: 13px;
}

.bem-floor-lock-label {
  fill: #b8a89c;
  font-size: 19px;
  letter-spacing: 0.08em;
}

.bem-anchor path {
  fill: none;
  stroke: #d3b16f;
  stroke-width: 7;
  stroke-linecap: round;
}

.bem-anchor text {
  fill: #b9a47d;
  font-size: 12px;
}

.bem-status {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: clamp(16px, 2.4vw, 26px);
  overflow-y: auto;
}

.bem-debug {
  margin-top: auto;
  border-top: 1px solid rgba(225, 198, 148, 0.2);
  padding-top: 12px;
  color: #d6c8b6;
  font: 0.72rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.bem-debug summary {
  cursor: pointer;
}

.bem-current span,
.bem-status dt {
  display: block;
  margin-bottom: 5px;
  color: #bda77f;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bem-current strong {
  font: 600 1.35rem/1.3 ui-serif, Georgia, serif;
}

.bem-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bem-focus-current {
  flex: 0 0 auto;
  min-height: 44px;
  border: 1px solid rgba(225, 198, 148, 0.36);
  border-radius: 999px;
  padding: 7px 12px;
  color: #eadcc3;
  background: rgba(74, 55, 39, 0.44);
  font-size: 0.72rem;
  touch-action: manipulation;
}

.bem-focus-current:focus-visible {
  outline: 2px solid #fff3c7;
  outline-offset: 2px;
}

.bem-status dl {
  margin: 0;
}

.bem-status dd {
  margin: 0 0 14px;
  overflow-wrap: anywhere;
  color: #e8ded1;
  font: 0.82rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.bem-notice {
  margin: auto 0 0;
  border-left: 3px solid #c9a664;
  padding: 10px 12px;
  color: #eadcc3;
  background: rgba(201, 166, 100, 0.09);
}

.bem-footer {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 8px clamp(14px, 3vw, 32px) max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(225, 198, 148, 0.2);
  color: #cfc3b3;
  background: rgba(15, 12, 12, 0.96);
}

.bem-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.76rem;
  white-space: nowrap;
  overflow-x: hidden;
}

.bem-legend span::before {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #8a7b6a;
  content: '';
}

.bem-legend .is-current::before { background: #ffe0a0; }
.bem-legend .is-selected::before { background: #f5c86f; }
.bem-legend .is-visited::before { background: #849d84; }
.bem-legend .is-available::before { background: #c4a56d; }
.bem-legend .is-locked::before { background: #554b48; }

@media (max-width: 600px) {
  .bem-header {
    min-height: 58px;
    gap: 8px;
    padding-inline: 12px;
  }

  .bem-kicker {
    display: none;
  }

  .bem-header h1 {
    font-size: 1rem;
  }

  .bem-floor-tabs button {
    min-height: 44px;
    padding: 7px 10px;
    font-size: 0.75rem;
  }

  .bem-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(280px, 1fr) auto;
    gap: 8px;
    padding: 8px;
  }

  .bem-map-panel {
    place-items: stretch start;
  }

  .bem-map-panel svg {
    width: auto;
    min-width: 680px;
    max-width: none;
    height: 100%;
  }

  .bem-map-panel[data-map-floor="2"] svg {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
  }

  .bem-pan-hint {
    display: block;
  }

  .bem-map-panel,
  .bem-status {
    border-radius: 12px;
  }

  .bem-status {
    display: grid;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    gap: 10px;
    max-height: 156px;
    padding: 10px 12px;
  }

  .bem-current strong {
    font-size: 1rem;
  }

  .bem-current {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .bem-focus-current {
    min-height: 40px;
    padding: 5px 9px;
    font-size: 0.66rem;
  }

  .bem-status dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 8px;
  }

  .bem-status dt,
  .bem-status dd {
    margin: 0;
    font-size: 0.66rem;
  }

  .bem-status dt:nth-of-type(n + 3),
  .bem-status dd:nth-of-type(n + 3) {
    display: none;
  }

  .bem-notice {
    grid-column: 1 / -1;
    margin: 0;
    padding: 5px 8px;
    font-size: 0.72rem;
  }

  .bem-footer {
    gap: 8px;
    min-height: 48px;
    padding: 5px 8px max(5px, env(safe-area-inset-bottom));
  }

  .bem-legend {
    justify-content: space-between;
    gap: 6px;
    font-size: 0.64rem;
  }

  .bem-legend .is-visited,
  .bem-legend .is-available {
    display: none;
  }

  .bem-move-controls button {
    min-height: 44px;
    padding: 6px 12px;
    font-size: 0.76rem;
  }
}

@media (max-height: 420px) {
  .bem-header {
    min-height: 44px;
    padding: 3px 10px;
  }

  .bem-header h1 {
    font-size: 0.88rem;
  }

  .bem-floor-tabs button {
    min-height: 38px;
    padding: 4px 9px;
    font-size: 0.68rem;
  }

  .bem-workspace {
    grid-template-columns: minmax(0, 1fr) 190px;
    grid-template-rows: minmax(0, 1fr);
    gap: 6px;
    padding: 5px 8px;
  }

  .bem-map-panel svg {
    min-width: 590px;
  }

  .bem-map-panel[data-map-floor="2"] svg {
    min-width: 100%;
  }

  .bem-status {
    display: block;
    max-height: none;
    padding: 8px 10px;
  }

  .bem-status dl {
    display: block;
    margin-top: 8px;
  }

  .bem-status dt,
  .bem-status dd {
    display: block !important;
    margin: 0;
    font-size: 0.6rem;
    line-height: 1.35;
  }

  .bem-status dt:nth-of-type(n + 2),
  .bem-status dd:nth-of-type(n + 2) {
    display: none !important;
  }

  .bem-current strong {
    font-size: 0.88rem;
  }

  .bem-current {
    align-items: flex-start;
  }

  .bem-focus-current {
    min-height: 36px;
    padding: 3px 7px;
    font-size: 0.58rem;
  }

  .bem-footer {
    min-height: 40px;
    padding: 2px 8px max(2px, env(safe-area-inset-bottom));
  }

  .bem-legend {
    font-size: 0.58rem;
  }

  .bem-move-controls button {
    min-height: 36px;
    padding: 3px 9px;
  }
}
