/* ============================================================================
 * Touch-Mode & Multi-Breakpoint Responsive Reflow (antislop-layoutmobile)
 * ========================================================================== */
body.touch-mode .key-hint-strip,
body.touch-mode .magic-cast-btn {
  display: none;
}

.key-sp,
body.touch-mode .key-pc {
  display: none;
}

body.touch-mode .key-sp {
  display: inline-flex;
}

body.touch-mode .status-head {
  cursor: pointer;
}

.status-toggle-btn {
  display: inline-flex;
}

.status-details {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transform-origin: top left;
  transform: translateY(-4px) scale(0.98);
  pointer-events: none;
  transition: grid-template-rows 240ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms cubic-bezier(0.22, 1, 0.36, 1), transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.status-details-inner {
  overflow: hidden;
}

.status-cluster.is-expanded .status-details {
  grid-template-rows: 1fr;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

body.touch-mode .status-cluster:not(.is-expanded) ~ .blessing-strip {
  display: none;
}

body.touch-mode .status-cluster.is-expanded ~ .blessing-strip {
  animation: status-bloom-in 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes status-bloom-in {
  0% { opacity: 0; transform: translateY(-4px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

body.touch-mode .dungeon-log {
  position: static;
  top: auto;
  bottom: auto;
  left: auto;
  width: 100%;
  max-width: min(228px, calc(100vw - 180px));
  margin-top: 2px;
}

body.touch-mode .blueprint-dock {
  grid-template-columns: repeat(4, 54px);
  gap: 5px;
  padding: 5px;
}

body.touch-mode .slot-card {
  flex-direction: column;
  padding: 4px 3px 3px;
  gap: 2px;
  text-align: center;
}

body.touch-mode .slot-card::before {
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
}

body.touch-mode .slot-card .pixel-art {
  width: 38px;
  height: 38px;
}

body.touch-mode .slot-card .slot-info {
  width: 100%;
  align-items: center;
}

body.touch-mode .slot-card .slot-role-row {
  justify-content: center;
  gap: 3px;
}

body.touch-mode .slot-card .slot-role,
body.touch-mode .slot-card .slot-info strong {
  display: none;
}

body.touch-mode .slot-card .slot-skill {
  font-size: 9px;
  max-width: 48px;
}

body.touch-mode .gimmick-hint {
  bottom: calc(94px + env(safe-area-inset-bottom, 0px) + var(--tb, 0px));
}

body.touch-mode .morph-preview {
  top: calc(274px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  left: auto;
  bottom: auto;
  width: min(236px, calc(100vw - 140px));
  padding: 8px 9px;
}

body.touch-mode .morph-preview .pixel-art.large {
  width: 36px;
  height: 36px;
}

/* Hide active gameplay HUD while Title Screen overlay is visible */
body:has(#title-overlay.visible) .hud-top,
body:has(#title-overlay.visible) .dock-cluster,
body:has(#title-overlay.visible) .dungeon-log,
body:has(#title-overlay.visible) .morph-preview,
body:has(#title-overlay.visible) .gimmick-hint,
body:has(#title-overlay.visible) .stairs-confirm,
body:has(#title-overlay.visible) #lock-reticle {
  opacity: 0;
  pointer-events: none;
}

/* Mid-Width / Small Laptop Breakpoint */
@media (max-width: 1320px) {
  .dungeon-log {
    bottom: 138px;
    width: 244px;
  }
}

@media (max-width: 1120px) {
  .status-cluster {
    min-width: 214px;
    padding: 8px 10px;
  }
  .phys-stats {
    gap: 6px;
    font-size: 10.5px;
  }
  .hud-center {
    max-width: calc(100vw - 410px);
  }
  .floor-cluster {
    padding: 6px 10px 7px;
  }
  .floor-meta-row {
    gap: 3px 6px;
  }
  .floor-title {
    font-size: 13px;
  }
  .floor-sub-row {
    flex-wrap: wrap;
    gap: 4px 6px;
  }
  .icon-btn {
    padding: 6px 8px;
    font-size: 11px;
    white-space: nowrap;
  }
  .btn-key-hint {
    display: none;
  }
  #minimap-canvas {
    width: 136px;
    height: 136px;
  }
  .minimap-legend {
    max-width: 136px;
  }
  .tuning-panel {
    top: 240px;
  }
  .morph-preview,
  body.touch-mode .morph-preview {
    top: 252px;
    right: 12px;
    width: 236px;
    padding: 9px 10px;
  }
  .morph-preview .pixel-art.large {
    width: 38px;
    height: 38px;
  }
  .key-hint-strip {
    font-size: 10px;
    gap: 7px;
    padding: 3px 9px;
  }
  .blueprint-dock {
    grid-template-columns: repeat(4, minmax(128px, 168px));
  }
  .slot-card {
    gap: 7px;
    padding: 5px 7px;
  }
  .slot-card .pixel-art {
    width: 40px;
    height: 40px;
  }
}

/* Mobile / Narrow Viewport Reflow */
@media (max-width: 760px) {
  .hud-top {
    top: calc(38px + env(safe-area-inset-top, 0px));
    left: calc(10px + env(safe-area-inset-left, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    gap: 8px;
  }
  .hud-left {
    flex: 1 1 0;
    min-width: 0;
    max-width: calc(100vw - 134px);
  }
  .hud-right {
    flex: 0 0 auto;
    max-width: 108px;
  }
  .status-cluster {
    min-width: 0;
    width: 100%;
    max-width: 242px;
    padding: 7px 9px;
  }
  .status-head {
    gap: 6px;
    margin-bottom: 5px;
    cursor: pointer;
  }
  .status-toggle-btn {
    display: inline-flex;
  }
  .status-details {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transform-origin: top left;
    transform: translateY(-4px) scale(0.98);
    pointer-events: none;
    transition: grid-template-rows 240ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms cubic-bezier(0.22, 1, 0.36, 1), transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  .status-details-inner {
    overflow: hidden;
  }
  .status-cluster.is-expanded .status-details {
    grid-template-rows: 1fr;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
  .status-cluster:not(.is-expanded) ~ .blessing-strip {
    display: none;
  }
  .status-cluster.is-expanded ~ .blessing-strip {
    animation: status-bloom-in 240ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  .phys-stats {
    gap: 6px;
    font-size: 10px;
  }
  #minimap-canvas {
    width: 104px;
    height: 104px;
  }
  .minimap-legend {
    max-width: 104px;
    font-size: 9px;
    gap: 2px 5px;
  }
  .hud-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 104px;
    gap: 4px;
  }
  .icon-btn {
    min-height: 36px;
    padding: 4px 4px;
    font-size: 10.5px;
    white-space: nowrap;
    text-align: center;
  }
  .btn-key-hint {
    display: none;
  }
  .hud-toast,
  body.has-boss-bar .hud-toast {
    position: fixed;
    left: 50%;
    top: calc(46px + env(safe-area-inset-top, 0px));
    transform: translate(-50%, -6px);
    width: max-content;
    max-width: calc(100vw - 24px);
    padding: 6px 12px;
    font-size: 11.5px;
    white-space: normal;
    text-align: center;
    z-index: 32;
  }
  .hud-toast.visible,
  body.has-boss-bar .hud-toast.visible {
    transform: translate(-50%, 0);
  }
  .blueprint-dock {
    grid-template-columns: repeat(4, 52px);
    gap: 5px;
    padding: 5px;
  }
  .slot-card {
    flex-direction: column;
    padding: 4px 3px 3px;
    gap: 2px;
    text-align: center;
  }
  .slot-card::before {
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
  }
  .slot-card .pixel-art {
    width: 36px;
    height: 36px;
  }
  .slot-card .slot-info {
    width: 100%;
    align-items: center;
  }
  .slot-card .slot-role,
  .slot-card .top-magic-key,
  .slot-card .slot-info strong {
    display: none;
  }
  .slot-card .slot-skill {
    font-size: 9px;
    max-width: 46px;
  }
  .floor-cluster {
    position: fixed;
    top: calc(6px + env(safe-area-inset-top, 0px));
    left: calc(10px + env(safe-area-inset-left, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    width: auto;
    max-width: none;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    text-align: left;
    box-shadow: 0 2px 0 var(--stone-ledge);
  }
  .floor-meta-row {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
  }
  .floor-progress {
    font-size: 11px;
    flex-shrink: 0;
  }
  .floor-title {
    font-size: 11.5px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .score-chip {
    margin-left: auto;
    font-size: 10.5px;
    flex-shrink: 0;
  }
  .floor-sub-row {
    margin-top: 0;
    flex-shrink: 0;
    gap: 4px;
  }
  .floor-cluster .mode-badge,
  .floor-cluster .brass-sep,
  .floor-cluster .algo-tag:not(.is-monster-house),
  .floor-cluster .sig-badge,
  .floor-cluster .floor-sub,
  .floor-cluster .milestone-tag,
  .floor-cluster .boss-banner {
    display: none;
  }
  .key-hint-strip {
    display: none;
  }
  .magic-cast-btn {
    padding: 4px 9px;
    font-size: 10.5px;
  }
  .dungeon-log {
    position: static;
    top: auto;
    bottom: auto;
    left: auto;
    width: 100%;
    max-width: min(210px, calc(100vw - 134px));
    margin-top: 2px;
  }
  .gimmick-hint {
    bottom: 90px;
  }
  .morph-preview,
  body.touch-mode .morph-preview {
    top: calc(252px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    left: auto;
    bottom: auto;
    width: min(232px, calc(100vw - 124px));
    padding: 8px 9px;
    max-height: calc(100dvh - 420px);
  }
  .save-io-actions {
    grid-template-columns: 1fr;
  }
  .save-preview-grid {
    grid-template-columns: 1fr;
  }
  .save-preview-actions {
    grid-template-columns: 1fr;
  }
  .morph-preview .pixel-art.large {
    width: 36px;
    height: 36px;
  }
  .stairs-confirm {
    top: calc(120px + env(safe-area-inset-top, 0px));
  }
  .overlay.title-mode {
    align-items: flex-end;
    padding: 20px 18px calc(24px + env(safe-area-inset-bottom, 0px) + var(--tb, 0px));
    background: linear-gradient(
      180deg,
      rgba(11, 13, 19, 0.14) 0%,
      rgba(11, 13, 19, 0.82) 38%,
      rgba(11, 13, 19, 0.96) 100%
    );
  }
  .overlay.result-mode {
    justify-content: center;
    padding: 16px;
    background: rgba(10, 12, 18, 0.84);
  }
  .controls-list {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .controls-list li {
    white-space: normal;
  }
  .title-records {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .record-divider {
    width: 100%;
    height: 1px;
  }
  .title-actions {
    grid-template-columns: 1fr;
  }
  .tuning-panel,
  body:has(#title-overlay.visible) .tuning-panel {
    top: 58px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100vh - 116px);
  }
  .blessing-cards {
    grid-template-columns: 1fr;
  }
  .ending-sheet {
    padding: 18px 16px 16px;
  }
  .ending-sub-actions {
    grid-template-columns: 1fr;
  }
  .ending-epilogue br {
    display: none;
  }
  .codex-arch-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .codex-boss-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .codex-variant-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .codex-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .codex-milestones-grid {
    grid-template-columns: 1fr;
  }
  .codex-header {
    padding: 12px 14px 10px;
  }
  .codex-tabs {
    padding: 6px 12px 0;
    overflow-x: auto;
  }
  .codex-tab {
    padding: 7px 10px;
    font-size: 11px;
    white-space: nowrap;
  }
  .codex-body {
    padding: 12px 14px 16px;
  }
  .codex-filter-bar {
    top: -12px;
    margin: -12px -14px 10px;
    padding: 8px 14px;
    gap: 4px;
  }
  .codex-filter-btn {
    padding: 4px 7px;
    font-size: 10.5px;
  }
  .lead {
    word-break: normal;
  }
  .lead br {
    display: none;
  }
}

@media (max-width: 680px) {
  body.touch-mode .dock-cluster {
    bottom: calc(198px + env(safe-area-inset-bottom, 0px) + var(--tb, 0px));
  }
  body.touch-mode .blueprint-dock {
    grid-template-columns: repeat(4, 48px);
    gap: 4px;
    padding: 5px;
  }
  body.touch-mode .slot-card .pixel-art {
    width: 34px;
    height: 34px;
  }
  body.touch-mode .slot-card .slot-skill {
    max-width: 42px;
  }
  body.touch-mode .gimmick-hint {
    bottom: calc(260px + env(safe-area-inset-bottom, 0px) + var(--tb, 0px));
  }
}

/* 見える高さが低いスマホ（src/ui/viewport.js が付ける）：面の帯を絵だけにして左へ寄せ、主人公に重ねない */
@media (max-width: 680px) {
  body.touch-mode.short-screen .dock-cluster {
    left: 10px;
    bottom: calc(148px + env(safe-area-inset-bottom, 0px) + var(--tb, 0px));
    transform: none;
  }
  body.touch-mode.short-screen .blueprint-dock {
    grid-template-columns: repeat(4, 34px);
    gap: 3px;
    padding: 4px;
  }
  body.touch-mode.short-screen .slot-card {
    padding: 3px 2px;
  }
  body.touch-mode.short-screen .slot-card .pixel-art {
    width: 26px;
    height: 26px;
  }
  body.touch-mode.short-screen .slot-card .slot-info {
    display: none;
  }
}

@media (max-width: 350px) {
  body.touch-mode.short-screen .dock-cluster {
    bottom: calc(184px + env(safe-area-inset-bottom, 0px) + var(--tb, 0px));
  }
}

@media (max-width: 420px) {
  .touch-btn-magic {
    width: 46px;
    height: 46px;
    right: 132px;
    bottom: 54px;
  }
  .touch-btn-magic .touch-btn-kanji {
    font-size: 14px;
  }
}
