/* Mobile transport/UI adaptation is NEW_IMPLEMENTATION. Source art is unchanged.
   Renderer.configureViewport is the only owner of canvas dimensions. */
.mobile-tabs,
.mobile-game-title,
.mobile-vitals {
  display: none;
}
.game-tools {
  display: contents;
}
.visibility-status {
  color: #efd183;
  font-size: 11px;
}
.visibility-status[hidden] {
  display: none;
}
html.game-screen-expanded {
  position: fixed;
  inset: 0;
  z-index: 2147483600;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: #101621;
}
@media (max-width: 950px) {
  html,
  body {
    height: 100%;
    min-width: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }
  body {
    height: var(--mobile-height, 100dvh);
    margin: 0;
  }
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }
  button,
  a,
  select {
    touch-action: manipulation;
  }
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
  button,
  .quiet-button {
    min-height: 44px;
  }
  .portal-bar {
    height: calc(44px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-left)) 0;
    gap: 8px;
  }
  .portal-bar .world-brand {
    font-size: 0;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .portal-bar .world-brand::before,
  .portal-bar .world-brand span,
  .header-right .development,
  .header-right > a {
    display: none;
  }
  .portal-bar .world-brand::after {
    content: "‹ 저장 후 뒤로";
    font-size: 12px;
    letter-spacing: 0;
  }
  .mobile-game-title {
    display: block;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .header-right {
    gap: 0;
  }
  .header-right #help-button {
    min-width: 44px;
    padding: 0 6px;
    font-size: 11px;
  }
  body main,
  body.embedded main {
    height: calc(
      var(--mobile-height, 100dvh) - 44px - env(safe-area-inset-top)
    );
    width: 100%;
    max-width: none;
    padding: 0;
    margin: 0;
  }
  body.embedded main {
    height: var(--mobile-height, 100dvh);
  }
  .game-heading,
  .footnote {
    display: none;
  }
  .game-shell,
  .game-shell:fullscreen {
    position: relative;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .scene-toolbar {
    height: 44px;
    min-height: 44px;
    padding: 0 6px;
    gap: 4px;
    flex-wrap: nowrap;
  }
  .scene-toolbar > div {
    min-width: 0;
    gap: 3px;
    flex-wrap: nowrap;
  }
  .scene-toolbar > div:first-child {
    flex: 1;
  }
  .scene-toolbar strong {
    font-size: 11px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  #map-name {
    max-width: none;
  }
  .scene-toolbar select {
    min-height: 44px;
    width: 70px;
    max-width: 70px;
    padding: 3px;
  }
  .scene-toolbar select#render-zoom {
    width: 58px;
  }
  .scene-toolbar button {
    min-width: 44px;
    min-height: 44px;
  }
  #fullscreen-button {
    padding: 3px;
    font-size: 18px;
  }
  #fullscreen-button span,
  .compass,
  #map-coordinates,
  #sound-button {
    display: none;
  }
  .game-shell .play-area,
  .game-shell .play-area:has(.login-panel:not([hidden])),
  .game-shell:fullscreen .play-area {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: auto;
    max-height: none;
    max-width: none;
    aspect-ratio: auto;
    border: 0;
    margin: 0;
  }
  .play-area:has(.login-panel:not([hidden])) canvas {
    height: 100%;
  }
  #world {
    width: 100%;
    height: 100%;
    touch-action: none;
  }
  .scene-tag {
    display: none;
  }
  .target-card {
    top: 8px;
    left: auto;
    right: 8px;
    transform: none;
    width: min(180px, 55%);
    min-width: 0;
    font-size: 11px;
    max-width: 55%;
  }
  #scene-message {
    top: 48px;
    font-size: 12px;
    max-width: 90%;
    pointer-events: none;
  }
  .game-shell:has(#login-panel:not([hidden])) .action-bar,
  .game-shell:has(#login-panel:not([hidden])) .mobile-controls {
    visibility: hidden;
  }
  .player-toolbar {
    height: 40px;
    min-height: 40px;
    padding: 3px 8px;
    gap: 6px;
  }
  .portrait,
  .gold,
  .stat-line,
  .player-details > #player-level {
    display: none;
  }
  .player-details {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0 5px;
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .player-details > strong {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .player-details > .mobile-vitals {
    display: block;
    font-size: 11px;
    line-height: 1.4;
    white-space: nowrap;
    color: #f5d9a0;
    margin: 0;
    flex-shrink: 0;
  }
  .visibility-status {
    width: 100%;
    font-size: 10px;
    line-height: 1.1;
  }
  .game-shell .player-toolbar .action-bar {
    position: absolute;
    inset: auto;
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(106px + env(safe-area-inset-bottom));
    left: auto;
    top: auto;
    transform: none;
    width: min(174px, calc(100% - 166px));
    max-width: none;
    height: auto;
    z-index: 3;
    display: grid;
    grid-template-columns: repeat(3, minmax(44px, 1fr));
    align-content: start;
    gap: 6px;
    margin: 0;
    padding: 0;
    order: initial;
    float: none;
  }
  .game-shell .action-bar button {
    min-width: 44px !important;
    width: 100%;
    min-height: 46px;
    height: 46px;
    flex: none;
    padding: 3px 1px;
    font-size: 10px;
    border-radius: 10px;
    background: #172236ed;
    box-shadow: 0 2px 8px #0008;
  }
  .game-shell .action-bar button > span {
    display: block;
    margin: 0;
  }
  .action-bar button .action-icon {
    font-size: 18px;
    line-height: 19px;
  }
  .action-bar kbd {
    display: none;
  }
  .mobile-controls {
    display: block;
    position: absolute;
    inset: auto;
    left: max(10px, env(safe-area-inset-left));
    bottom: calc(100px + env(safe-area-inset-bottom));
    right: auto;
    top: auto;
    transform: none;
    width: 138px;
    height: 138px;
    padding: 0;
    margin: 0;
    background: none;
    border: 0;
    z-index: 3;
  }
  .mobile-controls p {
    display: none;
  }
  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
    gap: 3px;
  }
  .dpad button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 11px;
    font-size: 17px;
    background: #172236db;
    color: #f3ddb0;
    border: 1px solid #9a9c9e88;
    touch-action: none;
  }
  .dpad > span {
    pointer-events: none;
  }
  .dpad button:first-child {
    grid-column: 2;
    grid-row: 1;
  }
  .dpad button:nth-child(2) {
    grid-column: 1;
    grid-row: 2;
  }
  .dpad > span {
    grid-column: 2;
    grid-row: 2;
    text-align: center;
    align-content: center;
  }
  .dpad button:nth-child(4) {
    grid-column: 3;
    grid-row: 2;
  }
  .dpad button:last-child {
    grid-column: 2;
    grid-row: 3;
  }
  .mobile-tabs {
    display: flex;
    height: calc(48px + env(safe-area-inset-bottom));
    min-height: calc(48px + env(safe-area-inset-bottom));
    padding: 0 0 env(safe-area-inset-bottom);
    background: #111a29;
    z-index: 7;
  }
  .mobile-tabs button {
    flex: 1;
    min-width: 44px;
    min-height: 44px;
    border-radius: 0;
    font-size: 12px;
    padding: 4px 2px;
  }
  .mobile-tabs button[aria-expanded="true"] {
    background: #665331;
    color: #fff0c7;
  }
  .bottom-panels {
    display: none;
    position: absolute;
    bottom: calc(88px + env(safe-area-inset-bottom));
    left: 8px;
    right: 8px;
    z-index: 6;
    margin: 0;
    max-height: calc(100% - 140px);
    overflow: auto;
    border: 1px solid #8d7854;
    box-shadow: 0 6px 30px #0009;
    background: #111a29;
  }
  .bottom-panels > section {
    display: none;
  }
  .mobile-panel-chat .bottom-panels,
  .mobile-panel-journal .bottom-panels {
    display: block;
  }
  .mobile-panel-chat .chat-panel,
  .mobile-panel-journal .quest-panel {
    display: block;
  }
  .panel-heading {
    height: 44px;
  }
  .panel-heading h2 {
    font-size: 12px;
  }
  .panel-heading h2 span {
    display: none;
  }
  #chat-messages {
    height: min(180px, 25dvh);
    padding: 8px;
    font-size: 13px;
  }
  #chat-form {
    min-height: 48px;
    padding: 3px;
  }
  #chat-form input {
    min-width: 0;
    height: 44px;
  }
  #chat-form button {
    min-width: 52px;
    min-height: 44px;
  }
  #chat-form > span {
    display: none;
  }
  #quest-content {
    font-size: 13px;
    line-height: 1.7;
    padding: 12px;
    display: block;
  }
  #quest-content h3 {
    font-size: 14px;
  }
  #nearby-players {
    font-size: 12px;
  }
  #nearby-players button,
  #map-button {
    min-height: 44px;
    font-size: 12px;
  }
  .game-tools {
    display: none;
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: calc(48px + env(safe-area-inset-bottom));
    z-index: 6;
    max-height: calc(100% - 96px);
    overflow: auto;
    overscroll-behavior: contain;
    background: #111a29;
    border: 1px solid #8d7854;
    box-shadow: 0 6px 30px #0009;
  }
  .mobile-panel-controls .game-tools {
    display: block;
  }
  .game-dock {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    padding: 5px;
  }
  .game-dock button {
    min-height: 44px;
    font-size: 11px;
    padding: 5px 2px;
  }
  .game-dock kbd {
    display: none;
  }
  .quick-bar {
    display: flex;
    flex-wrap: wrap;
    padding: 6px;
    gap: 6px;
  }
  .quick-group,
  .quick-group:first-child,
  .quick-group:last-of-type {
    flex: 1 0 100%;
    order: initial;
    min-width: 0;
  }
  .quick-group > span {
    width: 36px;
    font-size: 10px;
  }
  #spell-hotkeys,
  #item-hotkeys {
    display: grid;
    grid-template-columns: repeat(5, minmax(44px, 1fr));
    width: 100%;
    gap: 3px;
  }
  #spell-hotkeys {
    grid-template-columns: repeat(4, minmax(44px, 1fr));
  }
  #spell-hotkeys button,
  #item-hotkeys button {
    width: 100%;
    min-width: 44px;
    height: 44px;
    padding: 2px;
    flex: initial;
  }
  #hotkey-settings {
    min-height: 44px;
  }
  .selected-spell-label {
    flex-basis: 100%;
    font-size: 10px;
    text-align: left;
  }
  .login-panel {
    inset: 0;
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: none;
    overflow: auto;
    border-radius: 0;
    padding: 18px 20px;
    transform: none;
    display: flex;
    flex-direction: column;
    justify-content: safe center;
  }
  .login-panel[hidden] {
    display: none;
  }
  .login-panel .eyebrow,
  .login-panel .login-emblem {
    display: none;
  }
  .login-panel h2 {
    font-size: 22px;
  }
  .login-panel p:not(.eyebrow),
  .login-panel small {
    font-size: 12px;
    line-height: 1.5;
  }
  #appearance-select {
    flex-wrap: wrap;
  }
  #appearance-select button {
    min-width: 44px;
    height: 54px;
  }
  .login-panel input,
  .login-panel .primary {
    min-height: 44px;
  }
  #detail-dialog,
  .game-panel {
    width: calc(100% - 16px);
    max-width: 820px;
    max-height: calc(var(--mobile-height, 100dvh) - 16px);
    overflow: auto;
  }
  #detail-dialog {
    padding: 18px;
  }
  .game-panel-heading {
    padding: 8px 12px;
  }
  .game-panel-heading h2 {
    font-size: 18px;
  }
  .game-panel-heading small {
    font-size: 8px;
  }
  .game-panel-heading button,
  #detail-dialog .dialog-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  .game-panel-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
  }
  .game-panel-tabs button {
    flex: 0 0 auto;
    min-height: 44px;
    font-size: 12px;
  }
  .game-panel-content {
    padding: 12px;
    min-width: 0;
    min-height: 0;
  }
  .game-panel-content button,
  #detail-dialog button {
    min-height: 44px;
  }
  .game-panel input,
  .game-panel select,
  .game-panel textarea,
  #detail-dialog input,
  #detail-dialog select {
    min-height: 44px;
    max-width: 100%;
  }
  .game-panel-footer {
    padding: 6px 10px;
    font-size: 9px;
  }
  .game-panel-footer span {
    display: none;
  }
  .item-grid,
  .roster-list {
    grid-template-columns: 1fr;
  }
  .equipment-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .inventory-transfer,
  .quickslot-transfer {
    flex-wrap: wrap;
  }
  .mobile-keyboard .mobile-controls,
  .mobile-keyboard .action-bar {
    visibility: hidden;
  }
  .mobile-keyboard .bottom-panels {
    bottom: calc(48px + env(safe-area-inset-bottom));
    max-height: calc(100% - 96px);
  }
  .mobile-keyboard #chat-messages {
    height: min(80px, 15dvh);
  }
}
@media (max-width: 950px) and (orientation: landscape) {
  .mobile-tabs {
    height: calc(44px + env(safe-area-inset-bottom));
    min-height: calc(44px + env(safe-area-inset-bottom));
  }
  .mobile-controls {
    bottom: calc(88px + env(safe-area-inset-bottom));
  }
  .game-shell .player-toolbar .action-bar {
    bottom: calc(92px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(3, minmax(44px, 1fr));
  }
  .login-panel {
    justify-content: flex-start;
    padding: 8px 22px;
  }
  .login-panel h2 {
    font-size: 18px;
    margin: 3px;
  }
  .login-panel p:not(.eyebrow),
  .login-panel small {
    display: none;
  }
  #appearance-select {
    margin: 5px 0;
  }
  .login-panel form {
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .login-panel form label {
    display: none;
  }
  .login-panel input {
    flex: 1;
    min-width: 0;
  }
  .login-panel .primary {
    width: auto;
    white-space: nowrap;
  }
  .bottom-panels {
    bottom: calc(84px + env(safe-area-inset-bottom));
    max-height: calc(100% - 128px);
  }
  #chat-messages {
    height: 72px;
  }
}

/* Short landscape is the primary compact play surface. The save/return link
   shares the toolbar row, recovering the separate44px portal strip. No canvas
   dimensions or pointer coordinate transforms are controlled by this layer. */
@media (max-width: 950px) and (max-height: 430px) and (orientation: landscape) {
  .portal-bar {
    position: absolute;
    z-index: 9;
    top: env(safe-area-inset-top);
    left: max(8px, env(safe-area-inset-left));
    width: 98px;
    height: 44px;
    padding: 0;
    gap: 0;
    border: 0;
    background: none;
  }
  .portal-bar .world-brand {
    min-width: 98px;
    height: 44px;
    min-height: 44px;
    gap: 0;
    letter-spacing: 0;
    white-space: nowrap;
  }
  .portal-bar .world-brand::after {
    content: "‹ 저장 후 뒤로";
    font-size: 11px;
    white-space: nowrap;
  }
  .portal-bar .mobile-game-title,
  .portal-bar .header-right {
    display: none;
  }
  body main,
  body.embedded main {
    height: var(--mobile-height, 100dvh);
    padding-top: env(safe-area-inset-top);
  }
  .embedded .portal-bar {
    display: none;
  }
  .scene-toolbar {
    padding-left: calc(112px + env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
  }
  .embedded .scene-toolbar {
    padding-left: max(6px, env(safe-area-inset-left));
  }
  .player-toolbar {
    height: 28px;
    min-height: 28px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  .player-details > strong {
    font-size: 11px;
    line-height: 14px;
  }
  .player-details > .mobile-vitals {
    line-height: 1.1;
  }
  .visibility-status {
    font-size: 9px;
    line-height: 10px;
  }
  .mobile-controls {
    bottom: calc(72px + env(safe-area-inset-bottom));
  }
  .game-shell .player-toolbar .action-bar {
    bottom: calc(76px + env(safe-area-inset-bottom));
  }
  .bottom-panels {
    bottom: calc(72px + env(safe-area-inset-bottom));
    max-height: calc(100% - 116px - env(safe-area-inset-bottom));
  }
  .mobile-keyboard .bottom-panels {
    bottom: calc(44px + env(safe-area-inset-bottom));
    max-height: calc(100% - 88px - env(safe-area-inset-bottom));
  }
  .game-tools {
    max-height: calc(100% - 88px - env(safe-area-inset-bottom));
  }
}
