.dialogue-panel {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: none;
  align-items: center;
  gap: 10px;
  width: clamp(320px, calc(100vw - 460px), 640px);
  min-height: 84px;
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 4px solid #202126;
  border-radius: 8px;
  background: rgba(17, 19, 24, 0.94);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.34);
  pointer-events: auto;
  touch-action: manipulation;
}

@media (max-width: 860px) and (orientation: landscape) {
  .dialogue-panel {
    bottom: max(18px, env(safe-area-inset-bottom));
    width: clamp(320px, calc(100vw - 460px), 410px);
    min-height: 78px;
    padding: 8px 11px;
    gap: 8px;
  }

  .dialogue-portrait {
    width: clamp(48px, 7.5vw, 60px);
  }

  .dialogue-panel p {
    font-size: clamp(0.8rem, 1.45vw, 0.92rem);
    line-height: 1.36;
  }
}

.dialogue-panel.active {
  display: flex;
}

.dialogue-panel.speaker-player {
  flex-direction: row;
}

.dialogue-panel.speaker-other {
  flex-direction: row-reverse;
}

.dialogue-panel.speaker-player .dialogue-content {
  justify-items: start;
}

.dialogue-portrait {
  flex: 0 0 auto;
  width: clamp(56px, 8vw, 74px);
  aspect-ratio: 1;
  border: 3px solid #111;
  border-radius: 6px;
  background:
    linear-gradient(#f6e0ad 0 28%, transparent 28%),
    linear-gradient(90deg, #3157c9 0 50%, #6ab7ff 50%);
  box-shadow: inset 0 -11px 0 rgba(0, 0, 0, 0.25), 0 4px 0 rgba(0, 0, 0, 0.42);
  image-rendering: pixelated;
}

.dialogue-portrait.portrait-enemy {
  background:
    linear-gradient(#2b1715 0 22%, transparent 22%),
    linear-gradient(90deg, #9c6149 0 50%, #d28a5c 50%);
}

.dialogue-portrait.portrait-strong {
  background:
    linear-gradient(#ffffff 0 14%, transparent 14%),
    linear-gradient(90deg, #b52626 0 50%, #ff3f3f 50%);
}

.dialogue-portrait.portrait-npc {
  background:
    linear-gradient(#f6e0ad 0 28%, transparent 28%),
    linear-gradient(90deg, #5b7a59 0 50%, #476c52 50%);
}

.dialogue-portrait.portrait-hiu {
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 255, 255, 0.28), transparent 38%),
    #15171d url("../assets/player/hiu/idle-1.png") center / contain no-repeat;
}

.dialogue-portrait.portrait-challen {
  background:
    radial-gradient(circle at 50% 34%, rgba(130, 242, 255, 0.24), transparent 42%),
    #15171d url("../assets/npc/challen.png") center / contain no-repeat;
}

.dialogue-portrait.portrait-smile {
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 255, 255, 0.22), transparent 44%),
    #15171d url("../assets/npc/smile.png") center / contain no-repeat;
}

.dialogue-portrait.portrait-mu {
  background:
    radial-gradient(circle at 50% 34%, rgba(216, 255, 228, 0.24), transparent 44%),
    #15171d url("../assets/npc/mu.png") center / contain no-repeat;
}

.dialogue-portrait.portrait-c-npc {
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 255, 255, 0.34), transparent 34%),
    #15171d url("../assets/npc/c.png") center / contain no-repeat;
}

.dialogue-content {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.dialogue-name {
  justify-self: start;
  padding: 2px 8px 3px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.42);
  color: #ffd34d;
  font-size: clamp(0.78rem, 1.6vw, 0.95rem);
  font-weight: 900;
}

.dialogue-panel p {
  margin: 0;
  color: #f7f1d0;
  font-size: clamp(0.86rem, 1.55vw, 1rem);
  font-weight: 800;
  line-height: 1.5;
  word-break: keep-all;
}

.event-choice-panel {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: max(112px, calc(env(safe-area-inset-bottom) + 106px));
  display: none;
  width: clamp(320px, 44vw, 520px);
  padding: 12px;
  transform: translateX(-50%);
  border: 4px solid #202126;
  border-radius: 8px;
  background: rgba(17, 19, 24, 0.95);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.34);
  pointer-events: auto;
}

.event-choice-panel.active {
  display: grid;
  gap: 10px;
}

.event-choice-panel > strong {
  color: #ffd34d;
  font-size: 0.92rem;
  font-weight: 900;
}

.event-choice-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.event-choice-button {
  min-height: 42px;
  padding: 8px 10px;
  border: 3px solid #181a1e;
  border-radius: 5px;
  background: #2d2a25;
  color: #f7f1d0;
  font-weight: 900;
  text-align: center;
  touch-action: manipulation;
}

.event-choice-button:active {
  filter: brightness(1.25);
}

.shrink-workshop-panel {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  min-height: 0;
  padding: 36px 14px 14px calc(var(--bag-panel-w) + 18px);
  border: 4px solid #202126;
  border-radius: 8px;
  background: rgba(17, 19, 24, 0.95);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.34);
  color: #f7f1d0;
}

.shrink-workshop-panel.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.shrink-workshop-preview {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 0;
  padding: 12px;
  border: 3px solid #2a2d33;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.32);
}

.shrink-workshop-panel > .rune-section-title {
  position: absolute;
  z-index: 1;
  top: 2px;
  left: calc(var(--bag-panel-w) + 18px);
  right: 16px;
  justify-content: center;
  pointer-events: none;
}

.shrink-workshop-preview-canvas {
  width: 110px;
  height: 110px;
  border: 3px solid #3b3f47;
  border-radius: 6px;
  background: rgba(22, 24, 28, 0.88);
  image-rendering: pixelated;
}

.shrink-workshop-copy {
  display: grid;
  align-content: start;
  gap: 6px;
  min-width: 0;
}

.shrink-workshop-copy strong {
  color: #ffd34d;
  font-size: 1rem;
  font-weight: 900;
}

.shrink-workshop-copy p {
  margin: 0;
  color: #f7f1d0;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: keep-all;
}

.shrink-workshop-copy small,
.shrink-workshop-cost {
  color: #b6c3d1;
  font-size: 0.78rem;
  font-weight: 800;
}

.shrink-workshop-button {
  align-self: end;
  width: 100%;
  min-height: 46px;
  background: linear-gradient(180deg, #8a6b39 0%, #66502a 100%);
}

@media (orientation: portrait) {
  .rotate-hint {
    display: block;
  }

  .hud-top {
    gap: 5px;
  }

  .status-chip {
    padding: 5px 7px;
  }
}

@media (max-height: 430px) {
  .hud-top {
    top: 7px;
  }

  .minimap {
    top: max(52px, calc(env(safe-area-inset-top) + 50px));
    width: clamp(96px, 13vw, 138px);
    padding: 4px;
  }

  .joystick {
    width: clamp(104px, 17vw, 128px);
    bottom: max(24px, env(safe-area-inset-bottom));
  }

  .action-cluster {
    right: max(46px, env(safe-area-inset-right));
    bottom: max(22px, env(safe-area-inset-bottom));
    transform: scale(0.86);
    transform-origin: right bottom;
  }

  .weapon-slots {
    top: max(156px, calc(env(safe-area-inset-top) + 152px));
    right: max(18px, env(safe-area-inset-right));
    gap: 6px;
  }

  .weapon-slot {
    width: clamp(32px, 5.8vw, 40px);
  }

  .test-room-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inventory-window {
    max-height: calc(100vh - 18px);
    padding: 10px;
  }

  .rune-workspace {
    --bag-panel-w: min(330px, 40vw);
    --detail-panel-w: min(205px, 24vw);
    height: min(310px, calc(100vh - 96px));
  }

  .weapon-rune-workspace {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    gap: 8px;
  }

  .hiyu-workspace {
    height: min(310px, calc(100vh - 96px));
  }

  .hiyu-stat-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .weapon-rune-left-column {
    gap: 8px;
  }

  .rune-board-panel,
  .weapon-rune-list-panel,
  .weapon-owned-panel,
  .weapon-info-panel,
  .weapon-slots-panel {
    padding: 10px;
  }

  .rune-list-panel {
    padding: 0;
  }

  .rune-list-item {
    min-height: 58px;
    padding: 7px;
  }

  .rune-board {
    width: min(100%, 300px);
  }
}

@media (max-width: 760px) {
  .rune-workspace {
    --bag-panel-w: min(300px, 43vw);
    --detail-panel-w: min(188px, 27vw);
  }

  .weapon-rune-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .hiyu-stat-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .weapon-rune-list-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .weapon-rune-list-panel > .weapon-rune-effects {
    width: auto;
    max-height: none;
  }

  .weapon-rune-slots {
    grid-template-columns: repeat(5, minmax(38px, 1fr));
  }
}
