/* Phone gameplay keeps the world visible and combat within thumb reach. */
body[data-experience='phone'] #hud {
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  top: max(8px, env(safe-area-inset-top));
  width: auto;
  padding: 5px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  background: #102018b8;
  box-shadow: none;
  border-color: #9eaf8c55;
}
body[data-experience='phone'] #hud h1,
body[data-experience='phone'] #objective,
body[data-experience='phone'] #talent-button {
  display: none;
}
body[data-experience='phone'] #hud #menu-button {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  padding: 4px;
  min-height: 44px;
  width: 44px;
  text-align: center;
  font-size: 11px;
}
body[data-experience='phone'] #menu-button small {
  display: none;
}
body[data-experience='phone'] #hero-stats {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px 8px;
  line-height: 1.1;
}
body[data-experience='phone'] #hero-stats .hero-title {
  grid-column: 1/-1;
  margin: 0;
  font-size: 10px;
  justify-content: flex-start;
}
body[data-experience='phone'] #hero-stats .hero-title > span,
body[data-experience='phone'] #hero-stats .wallet,
body[data-experience='phone'] #hero-stats .restoring {
  display: none;
}
body[data-experience='phone'] #hero-stats .hero-title small {
  font-size: 9px;
}
body[data-experience='phone'] .resource-line {
  margin: 1px 0;
  font-size: 11px;
}
body[data-experience='phone'] .resource-line span {
  margin-bottom: 2px;
}
body[data-experience='phone'] .resource-line i {
  height: 5px;
}
body[data-experience='phone'] #status {
  position: fixed;
  top: calc(max(8px, env(safe-area-inset-top)) + 62px);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 5px 8px;
  border-radius: 6px;
  background: #102018e8;
  font-size: 11px;
  line-height: 1.25;
  pointer-events: none;
}
body[data-experience='phone'] #status:empty {
  display: none;
}
body[data-experience='phone'] #movement {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 5;
}
body[data-experience='phone'] #joystick {
  width: 104px;
  height: 104px;
  pointer-events: auto;
}
body[data-experience='phone'] #stick {
  width: 44px;
  height: 44px;
  left: calc(50% - 22px);
  top: calc(50% - 22px);
}
body[data-experience='phone'] #skills {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: min(184px, calc(50vw - 12px));
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
body[data-experience='phone'] #skills button {
  min-width: 0;
  min-height: 52px;
  font-size: 13px;
  padding: 6px 4px;
  touch-action: none;
  pointer-events: auto;
}
body[data-experience='phone'] #skills > button.locked {
  display: none;
}
body[data-experience='phone'] #skills .skill-ready small,
body[data-experience='phone'] #skills .key-hint {
  display: none;
}
body[data-experience='phone'] #quick-items {
  grid-column: 1/-1;
  gap: 6px;
}
body[data-experience='phone'] #quick-items:not(:has(button:not([hidden]))) {
  display: none;
}
body[data-experience='phone'] #skills .potion-button {
  min-height: 48px;
  font-size: 11px;
}
body[data-experience='phone'] #recall-button,
body[data-experience='phone'] #target-button {
  position: fixed;
  bottom: calc(124px + env(safe-area-inset-bottom));
  min-height: 44px;
  margin: 0;
  padding: 6px 4px;
  font-size: 11px;
  text-align: center;
  z-index: 6;
}
body[data-experience='phone'] #recall-button {
  left: max(8px, env(safe-area-inset-left));
  width: 90px;
}
body[data-experience='phone'] #target-button {
  left: calc(max(8px, env(safe-area-inset-left)) + 98px);
  width: 76px;
}
body[data-experience='phone'] #recall-button small,
body[data-experience='phone'] #target-button small {
  display: none;
}
body[data-experience='phone'] #squad-button {
  position: fixed;
  left: max(8px, env(safe-area-inset-left));
  bottom: calc(176px + env(safe-area-inset-bottom));
  width: 104px;
  min-height: 44px;
  margin: 0;
  font-size: 11px;
  z-index: 6;
}
body[data-experience='phone'] #touch-interact-button {
  left: 50%;
  right: auto;
  top: max(68px, 17vh);
  bottom: auto;
  transform: translateX(-50%);
  width: 104px;
  min-height: 44px;
  font-size: 12px;
  padding: 8px 6px;
  touch-action: manipulation;
  border-color: #e8ca8d;
  color: #fce9bb;
  background: linear-gradient(155deg, #69563b, #3e392d);
}
body[data-experience='phone'] #order-button {
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: 96px;
  min-height: 52px;
  display: none;
}
body[data-experience='phone'].menu-open #order-button {
  display: block;
}
body[data-experience='phone'].menu-open #touch-interact-button {
  display: none;
}
body[data-experience='phone'].menu-open #movement {
  z-index: 11;
}
body[data-experience='phone'] #modal {
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: calc(100vw - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right)));
  bottom: 124px;
  padding: 12px;
}
body[data-experience='phone'] #modal-actions button {
  min-height: 48px;
  pointer-events: auto;
}
body[data-experience='phone'] #message {
  width: min(420px, calc(100vw - 16px));
  top: max(8px, env(safe-area-inset-top));
}
body[data-experience='phone'] #message .notice-card {
  font-size: 12px;
  padding: 9px 12px;
}
/* The optional historical layout keeps combat above the left joystick. */
body[data-experience='phone'][data-phone-layout='left-hand'] #skills {
  right: auto;
  left: max(8px, env(safe-area-inset-left));
  bottom: calc(124px + env(safe-area-inset-bottom));
}
body[data-experience='phone'][data-phone-layout='left-hand'] #recall-button {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
}
body[data-experience='phone'][data-phone-layout='left-hand'] #target-button {
  left: auto;
  right: calc(max(8px, env(safe-area-inset-right)) + 98px);
  bottom: max(8px, env(safe-area-inset-bottom));
}
body[data-experience='phone'][data-phone-layout='left-hand'] #squad-button {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  bottom: calc(60px + env(safe-area-inset-bottom));
}
@media (max-height: 500px) and (min-width: 480px) {
  body[data-experience='phone'] #hud {
    right: auto;
    width: min(360px, 48vw);
  }
  body[data-experience='phone'] #touch-interact-button {
    left: calc(50vw - 80px);
    top: 50vh;
  }
  body[data-experience='phone'] #skills {
    width: min(340px, 48vw);
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  body[data-experience='phone'] #skills button {
    min-height: 50px;
    padding: 5px 4px;
  }
  body[data-experience='phone'] #modal {
    top: 8px;
    width: min(520px, 62vw);
    bottom: 120px;
  }
  body[data-experience='phone'][data-phone-layout='left-hand'] #skills {
    bottom: 122px;
  }
}

/* Phone: keep the single HP bar, class and level in a narrow corner dock. */
body[data-experience='phone'] #hud {
  left: max(8px, env(safe-area-inset-left));
  right: auto;
  width: min(252px, calc(100vw - 16px));
  padding: 6px 7px;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 6px;
  border-radius: 10px;
  background: linear-gradient(155deg, #172b36ec, #10212bde);
}
body[data-experience='phone'] #hero-stats {
  /* MP is dormant. Give the one HP meter the entire text column. */
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
}
body[data-experience='phone'] #hero-stats .hero-title {
  margin: 0 0 1px;
  justify-content: space-between;
  font-size: 11px;
}
body[data-experience='phone'] #hero-stats .hero-title > span {
  display: inline;
}
body[data-experience='phone'] #hero-stats .hero-title small {
  font-size: 10px;
}
body[data-experience='phone'] .resource-line {
  margin: 1px 0;
  font-size: 10px;
}
body[data-experience='phone'] .resource-line i {
  height: 5px;
}
body[data-experience='phone'] #hud #menu-button {
  width: 42px;
  min-height: 42px;
  padding: 4px;
  font-size: 0;
}
body[data-experience='phone'] #hud #menu-button::before {
  content: '☰';
  display: inline-block;
  font-size: 20px;
  line-height: 1;
}
body[data-experience='phone'] #status {
  top: calc(max(8px, env(safe-area-inset-top)) + 59px);
  width: max-content;
  max-width: min(270px, calc(100vw - 24px));
  padding: 5px 8px;
  background: #122733e8;
  border: 1px solid #7996a54d;
}
body[data-experience='phone'] #modal {
  top: 45%;
  bottom: auto;
  right: auto;
  left: 50%;
  width: min(330px, calc(100vw - 24px));
  max-height: min(54dvh, 470px);
  padding: 11px;
  transform: translate(-50%, -50%);
}
body[data-experience='phone'] #modal h2 {
  font-size: 17px;
}
body[data-experience='phone'] #modal-actions button,
body[data-experience='phone'] #close-button {
  min-height: 44px;
}
body[data-experience='phone'] #message {
  width: min(310px, calc(100vw - 20px));
  padding: 0;
  font-size: 11px;
}
@media (max-height: 500px) and (min-width: 480px) {
  body[data-experience='phone'] #hud {
    width: min(252px, 44vw);
  }
  body[data-experience='phone'] #modal {
    top: 46%;
    width: min(390px, 58vw);
    max-height: min(60dvh, 270px);
  }
}

/* Thumb-first field controls. Keep movement left, unlocked skills right,
   with Interact directly beside the joystick instead of over the world. */
body[data-experience='phone'] #touch-interact-button {
  left: calc(max(8px, env(safe-area-inset-left)) + 110px);
  right: auto;
  top: auto;
  bottom: max(8px, env(safe-area-inset-bottom));
  transform: none;
  width: 58px;
  min-height: 54px;
  padding: 5px 3px;
  font-size: 11px;
  line-height: 1.15;
}
body[data-experience='phone'] #recall-button,
body[data-experience='phone'] #target-button {
  bottom: calc(120px + env(safe-area-inset-bottom));
  min-height: 44px;
  border-radius: 9px;
}
body[data-experience='phone'] #recall-button {
  left: max(8px, env(safe-area-inset-left));
  width: 80px;
}
body[data-experience='phone'] #target-button {
  left: calc(max(8px, env(safe-area-inset-left)) + 88px);
  width: 78px;
}
body[data-experience='phone'] #squad-button {
  left: max(8px, env(safe-area-inset-left));
  bottom: calc(172px + env(safe-area-inset-bottom));
  width: 166px;
  min-height: 44px;
}
body[data-experience='phone'] #joystick {
  border-color: #bdd8cc66;
  border-width: 1px;
  background: #17333226;
  box-shadow: none;
}
body[data-experience='phone'] #stick {
  border: 1px solid #d0e3d57a;
  background: radial-gradient(circle at 35% 30%, #b5d2c36b, #56867c59 73%);
  box-shadow: none;
}
body[data-experience='phone'] #hero-stats .hero-title {
  font-size: 12px;
}
body[data-experience='phone'] #hero-stats .hero-title small {
  font-size: 11px;
}
body[data-experience='phone'] .resource-line {
  font-size: 11px;
}
body[data-experience='phone'] #status {
  font-size: 12px;
  line-height: 1.3;
}
body[data-experience='phone'] #message {
  /* Amber cards live below the compact vitals; brief status feedback follows the stack. */
  top: calc(max(8px, env(safe-area-inset-top)) + 70px);
  transform: translate(-50%, 0);
}
/* Long reading uses the available width instead of a deep card over the hero. */
body[data-experience='phone'] #message.wide-notice {
  --notice-edge: max(8px, env(safe-area-inset-left), env(safe-area-inset-right));
  width: calc(100vw - 2 * var(--notice-edge));
}
body[data-experience='phone'] #message.wide-notice .notice-card {
  padding: 6px 9px;
  border-radius: 6px;
  overflow-wrap: anywhere;
  line-height: 1.3;
}
body[data-experience='phone'] #message .notice-card.notice-narration::before {
  display: inline;
  margin: 0 6px 0 0;
}
body[data-experience='phone'] #modal-description,
body[data-experience='phone'] #modal-actions button {
  font-size: 13px;
}
body[data-experience='phone'] #modal-actions .detail {
  font-size: 11px;
}
body[data-experience='phone'] #modal[data-dialog-size='compact'] {
  width: min(280px, calc(100vw - 24px));
}
body[data-experience='phone'] #modal[data-dialog-size='regular'] {
  width: min(300px, calc(100vw - 24px));
}
body[data-experience='phone'] #modal[data-dialog-size='wide'] {
  width: min(330px, calc(100vw - 24px));
}
body[data-experience='phone'][data-phone-layout='left-hand'] #recall-button,
body[data-experience='phone'][data-phone-layout='left-hand'] #target-button {
  bottom: max(8px, env(safe-area-inset-bottom));
}
body[data-experience='phone'][data-phone-layout='left-hand'] #recall-button {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  width: 80px;
}
body[data-experience='phone'][data-phone-layout='left-hand'] #target-button {
  left: auto;
  right: calc(max(8px, env(safe-area-inset-right)) + 88px);
  width: 78px;
}
body[data-experience='phone'][data-phone-layout='left-hand'] #squad-button {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  bottom: calc(60px + env(safe-area-inset-bottom));
  width: 166px;
}
@media (max-height: 500px) and (min-width: 480px) {
  body[data-experience='phone'] #modal[data-dialog-size='compact'] {
    width: min(290px, 58vw);
  }
  body[data-experience='phone'] #modal[data-dialog-size='regular'] {
    width: min(330px, 58vw);
  }
  body[data-experience='phone'] #modal[data-dialog-size='wide'] {
    width: min(390px, 58vw);
  }
}

/* Best-effort letterbox-style fit for smaller viewports. The design reference
   remains 375x800 (800x375 rotated); no separate small-phone layout is authored. */
body[data-experience='phone'] #joystick,
body[data-experience='phone'] #recall-button,
body[data-experience='phone'] #target-button,
body[data-experience='phone'] #squad-button,
body[data-experience='phone'] #touch-interact-button,
body[data-experience='phone'] #order-button {
  transform: scale(var(--phone-ui-fit, 1));
  transform-origin: bottom left;
}
body[data-experience='phone'] #skills {
  transform: scale(var(--phone-ui-fit, 1));
  transform-origin: bottom right;
}
body[data-experience='phone'][data-phone-layout='left-hand'] #skills {
  transform-origin: bottom left;
}
body[data-experience='phone'][data-phone-layout='left-hand'] #recall-button,
body[data-experience='phone'][data-phone-layout='left-hand'] #target-button,
body[data-experience='phone'][data-phone-layout='left-hand'] #squad-button {
  transform-origin: bottom right;
}

/* All phone menus use compact typography and restrained vertical spacing. */
body[data-experience='phone'] #modal {
  top: 50%;
  max-height: min(72dvh, 570px);
  padding: 8px;
  transform: translate(-50%, -50%);
}
body[data-experience='phone'] #modal h2 {
  font-size: 14px;
  line-height: 1.15;
  margin-bottom: 5px;
  padding-bottom: 5px;
}
body[data-experience='phone'] #modal-description {
  font-size: 11px;
  line-height: 1.3;
  margin-bottom: 5px;
}
body[data-experience='phone'] #modal-actions {
  gap: 3px;
}
body[data-experience='phone'] #modal-actions button,
body[data-experience='phone'] #close-button {
  min-height: 44px;
  padding: 5px 8px;
  font-size: 11px;
  line-height: 1.2;
}
body[data-experience='phone'] #modal-actions .detail {
  font-size: 9px;
  line-height: 1.2;
  margin-top: 2px;
}
body[data-experience='phone'] #close-button {
  margin-top: 6px;
}
body[data-experience='phone'] #modal[data-view='map'] {
  width: min(340px, calc(100vw - 20px));
  max-height: min(82dvh, 650px);
}
body[data-experience='phone'] #modal[data-view='map'] #modal-description canvas {
  max-height: 150px;
}
@media (max-height: 500px) and (min-width: 480px) {
  body[data-experience='phone'] #modal {
    top: 50%;
    max-height: min(88dvh, 350px);
  }
  body[data-experience='phone'] #modal[data-view='map'] {
    width: min(600px, calc(100vw - 20px));
    max-height: min(88dvh, 350px);
  }
  body[data-experience='phone'] #modal[data-view='map'] #modal-content {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr);
    gap: 8px;
    overflow: hidden;
  }
  body[data-experience='phone'] #modal[data-view='map'] #modal-description {
    min-width: 0;
    align-self: start;
    margin: 0;
  }
  body[data-experience='phone'] #modal[data-view='map'] #modal-description canvas {
    max-height: none;
  }
  body[data-experience='phone'] #modal[data-view='map'] #modal-actions {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* Developer controls stay beside the joystick and off the combat skill grid. */
body[data-experience='phone'] #developer-summon {
  left: calc(max(8px, env(safe-area-inset-left)) + 110px);
  bottom: calc(64px + env(safe-area-inset-bottom));
  width: 58px;
  min-height: 42px;
  padding: 4px;
  font-size: 11px;
  transform: scale(var(--phone-ui-fit, 1));
  transform-origin: bottom left;
}
body[data-experience='phone'] #developer-combat-monitor {
  left: auto;
  right: max(8px, env(safe-area-inset-right));
  top: calc(90px + env(safe-area-inset-top));
  max-width: min(180px, 41vw);
  padding: 5px 7px;
  font-size: 10px;
}
