body.phone {
  touch-action: pan-x pan-y;
  --mobile-paper: #eddcba url("./assets/mobile-ledger-paper.webp") center / cover no-repeat;
  --touch-left: max(12px, env(safe-area-inset-left), var(--native-safe-left, 0px));
  --touch-right: max(12px, env(safe-area-inset-right), var(--native-safe-right, 0px));
  --touch-top: max(8px, env(safe-area-inset-top), var(--native-safe-top, 0px));
  --touch-bottom: max(8px, env(safe-area-inset-bottom), var(--native-safe-bottom, 0px));
}

body.phone #game {
  --phone-left: var(--touch-left);
  --phone-right: var(--touch-right);
  --phone-bottom: var(--touch-bottom);
  padding-top: 0;
  background: #213b30;
}

body.phone:is(.handset-landscape, .tablet) #game #mapViewport {
  left: 0;
  right: 0;
  width: 100%;
}

body.phone:is(.handset-landscape, .tablet) #game #mapViewport.map-under-hud {
  top: 0;
}

body.phone.handset-landscape.landscape #game #mapViewport {
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

body.handset-landscape #game.lithium-open #lithium-scene .mine-visual canvas {
  object-fit: cover;
}

body.handset-landscape #game.lithium-open #lithium-scene {
  top: 0;
}

body.handset-landscape #game.lithium-open #lithium-scene .mine-header {
  left: var(--touch-left);
  top: calc(var(--hud-bottom) + 5px);
}

body.handset-landscape #game.lithium-open #lithium-scene .mine-readouts {
  top: calc(var(--hud-bottom) + 47px);
}

body.phone #game :is(#dialog, #dialog.tour, #meeting, #mini, #decision, #ending, #pauseMenu) {
  padding: var(--touch-top) var(--touch-right) var(--touch-bottom) var(--touch-left);
}

body.phone #game :is(.meeting-card, .decision-card, .mini-card, .ending-card, .pause-card, #dialogBody) {
  max-height: calc(100dvh - var(--touch-top) - var(--touch-bottom));
  overscroll-behavior: contain;
}

body.phone:is(.handset-landscape, .tablet) #game :is(#panel, #panel.centered, #panel.wide, #panel[data-kind]):not([hidden]) {
  top: calc(var(--hud-bottom) + 7px);
  bottom: var(--touch-bottom);
  left: var(--touch-left);
  right: var(--touch-right);
  width: auto;
  max-width: 780px;
  max-height: none;
  margin-inline: auto;
  transform: none;
}

body.phone #game #panel #panelBody {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

body.phone #game #panel:not([data-kind="questpath"]),
body.phone #game :is(.pause-card, .meeting-card, .decision-card, .mini-card, .ending-card),
body.phone #game #dialogBody:not(:has(.story-scene)),
body.phone #game #globalChatDrawer {
  background: var(--mobile-paper);
}

body.phone #game #panel:not([data-kind="questpath"]) #panelBody {
  background: transparent;
}

body.phone #game #panel:is([data-kind="profile"], [data-kind="public-profile"]) #panelBody {
  padding: 0;
  border: 0;
}

body.phone #game #panel:is([data-kind="profile"], [data-kind="public-profile"]) .company-profile-banner {
  margin: 0;
  border: 0;
  border-radius: 0;
}

body.phone #game #panel:is([data-kind="profile"], [data-kind="public-profile"]) .company-profile > :not(.company-profile-banner) {
  margin-inline: 12px;
}

body.phone #game #panel:is([data-kind="profile"], [data-kind="public-profile"]) .company-profile > :last-child {
  margin-bottom: 12px;
}

body.phone #game #panel :is(#closePanel, button[data-action]):not(.avatar-choice) {
  min-height: 44px;
}

body.phone #game #panel > .panel-head #closePanel {
  position: relative;
  z-index: 3;
  flex: 0 0 44px;
}

body.phone #game :is(#closePanel, .pixel-close, [data-mine^="close-"]) {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid #c79a56;
  border-radius: 50%;
  background: #15372c;
  box-shadow: inset 0 0 0 1px #e5bf7455;
  color: #ffe4a3;
  font-size: 25px;
  line-height: 1;
  touch-action: manipulation;
}

body.phone #game :is(#closePanel, .pixel-close, [data-mine^="close-"]) :is(svg, .game-icon) {
  visibility: visible;
}

body.phone #game :is(#closePanel, .pixel-close, [data-mine^="close-"]):is(:hover, :focus-visible) {
  background-color: #2b5441;
}

body.phone #game #globalChatToggle { left: var(--touch-left); }
body.phone #game #mailboxShortcut { right: var(--touch-right); width: 44px; height: 44px; }
body.phone #game #eventShortcut { right: calc(var(--touch-right) + 46px); }
body.phone #game:has(#dialog:not([hidden])) #globalChatToggle { visibility: hidden; }
body.phone #game #globalChatDrawer {
  left: calc(var(--touch-left) + 46px);
  bottom: var(--touch-bottom);
  max-width: calc(100% - var(--touch-left) - var(--touch-right) - 46px);
}

body.phone #startScreen {
  padding-inline-start: max(var(--touch-left), 5vw);
  padding-inline-end: var(--touch-right);
  padding-block-start: max(16px, var(--touch-top));
  padding-block-end: max(16px, var(--touch-bottom));
}

body.phone.tablet #game #hud {
  top: var(--touch-top);
  left: var(--touch-left);
  right: var(--touch-right);
  height: auto;
  padding: 6px 12px;
  grid-auto-rows: minmax(40px, auto);
  align-content: start;
}

body.phone.handset-landscape.landscape #game #hud,
body.phone.handset-landscape.landscape #game #hud.has-ore-stocks {
  top: var(--touch-top);
  left: var(--touch-left);
  right: var(--touch-right);
  height: auto;
  min-height: 0;
  padding: 5px 12px;
  gap: 3px 6px;
  align-content: start;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.16fr) minmax(0, 1.32fr) 72px 90px;
  grid-template-rows: minmax(48px, auto);
  grid-template-areas: "identity money clock kontor controls";
}

body.phone.handset-landscape.landscape #game #hud.has-ore-stocks {
  grid-template-rows: minmax(48px, auto) minmax(18px, auto);
  grid-template-areas: "identity money clock kontor controls" "ore ore ore ore ore";
}

body.phone.handset-landscape.landscape #game #hud :is(#identity, .money, .clock, #hudControls) {
  min-width: 0;
  height: auto;
  align-self: center;
}

body.phone.handset-landscape.landscape #game #hud #identity {
  min-height: 46px;
  padding-inline: 2px;
}

body.phone.handset-landscape.landscape #game #hud #identity #portrait {
  width: 34px;
  height: 40px;
  flex-basis: 34px;
}

body.phone.handset-landscape.landscape #game #hud .money {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: 24px auto;
  gap: 2px 3px;
  padding-inline: 0;
}

body.phone.handset-landscape.landscape #game #hud .money .balance-line { display: contents; }

body.phone.handset-landscape.landscape #game #hud .money .cash-counter {
  grid-area: 1 / 1;
  width: 100%;
  min-width: 0;
  height: 24px;
}

body.phone.handset-landscape.landscape #game #hud .money #jewelBalance { grid-area: 1 / 2; }

body.phone.handset-landscape.landscape #game #hud .money #income {
  grid-area: 2 / 1 / 3 / -1;
  min-width: 0;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.phone.handset-landscape.landscape #game #hud #cash { font-size: clamp(12px, 2vw, 19px); }

body.phone.handset-landscape.landscape #game #hud .clock,
body.phone.handset-landscape.landscape #game #hud.has-ore-stocks .clock {
  width: 100%;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 20px 13px;
  gap: 4px;
  padding: 0;
}

body.phone.handset-landscape.landscape #game #hud .clock :is(#energyControl, #clock) { display: none; }
body.phone.handset-landscape.landscape #game #hud .clock #week {
  grid-area: 1 / 1;
  max-width: none;
  height: 20px;
  min-height: 0;
}
body.phone.handset-landscape.landscape #game #hud .clock #week span { height: 20px; min-height: 0; line-height: 18px; }
body.phone.handset-landscape.landscape #game #hud .clock #day { grid-area: 2 / 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

body.phone.handset-landscape.landscape #game #hud #hudControls { gap: 2px; }
body.phone.handset-landscape.landscape #game #hud #hudControls :is(#hudFullscreen, #pauseButton) {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  height: 44px;
  min-height: 44px;
  flex-basis: 44px;
}

body.phone.handset-landscape.landscape #game #hud #hudShop {
  height: 44px;
  min-height: 44px;
  font-size: 11px;
}

body.phone.handset-landscape #game #dock { bottom: var(--touch-bottom); }
body.phone.handset-landscape #game:has(#world[data-scene]) nav#dock {
  left: var(--touch-left) !important;
  right: var(--touch-right) !important;
}

body.phone.handset-landscape #game:has(#world:is([data-scene="office"], [data-scene^="eisen-"], [data-scene="kranenfels-office"])) #mainAction {
  margin-bottom: calc(var(--touch-bottom) - max(8px, env(safe-area-inset-bottom)));
}

body.phone.handset-landscape #game:has(#world[data-scene]) #dock > button {
  min-width: 44px;
  min-height: 44px;
}

body.phone.handset-landscape #game #dialog.hank-guide {
  align-items: end;
  justify-items: start;
  padding: var(--touch-top) var(--touch-right) calc(var(--touch-bottom) + 56px) var(--touch-left);
}

body.phone.handset-landscape #game #dialog.hank-guide:has([data-action="hankTarget"]) { pointer-events: none; }
body.phone.handset-landscape #game #dialog.hank-guide #dialogBody { pointer-events: auto; }

body.phone.handset-landscape #game #dialog.hank-guide #dialogBody:has(.avatar-story) {
  width: min(38vw, 420px);
  max-height: calc(100dvh - var(--hud-bottom) - var(--touch-bottom) - 64px);
}

body.phone.handset-landscape #game.hank-preview #panel:not([hidden]) {
  left: auto;
  right: var(--touch-right);
  width: 49%;
  margin-inline: 0;
}

body.phone.handset-landscape #game #panel[data-kind="questpath"]:not([hidden]) {
  bottom: calc(var(--touch-bottom) + 54px);
}

body.phone.handset-landscape #game #panel[data-kind="questpath"] #panelBody:has(> .quest-book) {
  height: 100%;
  overflow: hidden;
}

body.phone.handset-landscape #game #panel[data-kind="questpath"] .quest-book {
  height: 100%;
  min-height: 0;
  padding: 10px 12px 6px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

body.phone.handset-landscape #game #panel[data-kind="questpath"] .quest-book-spread {
  height: auto;
  min-height: 0;
  gap: 10px;
}

body.phone.handset-landscape #game #panel[data-kind="questpath"] .quest-book-page {
  max-height: none;
  min-height: 0;
}

body.phone.handset-landscape #game #panel[data-kind="questpath"] .quest-book-page:nth-child(2) h2 {
  padding-inline-end: 35px;
}

body.phone.handset-landscape #game #panel[data-kind="questpath"] .quest-book-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin-top: 4px;
}

body.phone.handset-landscape #game #panel[data-kind="questpath"] .quest-book-tabs button {
  min-width: 0;
  min-height: 42px;
  padding: 4px 2px;
  font-size: 11px;
  white-space: normal;
  overflow-wrap: anywhere;
}

body.phone.handset-landscape #game.hank-preview #panel[data-kind="profile"] .company-profile-banner {
  min-height: 108px;
  padding: 7px 9px;
}

body.phone.handset-landscape #game:has(#world[data-scene]) #questTracker {
  width: clamp(110px, 18vw, 150px);
  right: var(--touch-right);
  min-height: 44px;
  padding: 5px 7px;
  gap: 3px;
  font-size: clamp(10px, 1.35vw, 13px);
}

body.phone.handset-landscape #game #questTracker > :is(small, span:not(.quest-progress)) { display: none; }

@media (max-width: 740px) {
  body.phone.handset-landscape.landscape #game #hud,
  body.phone.handset-landscape.landscape #game #hud.has-ore-stocks {
    grid-template-columns: minmax(0, .95fr) minmax(0, 1.27fr) minmax(0, 1.3fr) 60px 90px;
    gap: 3px 4px;
  }
  body.phone.handset-landscape.landscape #game #hud .money,
  body.phone.handset-landscape.landscape #game #hud.has-ore-stocks .money {
    grid-template-rows: 22px auto;
  }
  body.phone.handset-landscape.landscape #game #hud .money #jewelBalance {
    grid-area: 2 / 2;
    height: 18px;
    min-height: 18px;
  }
  body.phone.handset-landscape.landscape #game #hud .money .cash-counter { grid-area: 1 / 1 / 2 / -1; }
  body.phone.handset-landscape.landscape #game #hud .money #income { grid-area: 2 / 1; }
}

#mapShortcuts { display: contents; }
#mapShortcuts .map-shortcut { display: none; }

body.phone.handset-landscape.landscape #game #hud,
body.phone.handset-landscape.landscape #game #hud.has-ore-stocks {
  min-height: 0;
  grid-template-columns: minmax(0, .95fr) minmax(0, 1.24fr) minmax(0, 1.2fr) 44px;
  grid-template-areas: "identity money clock controls";
  gap: 4px 8px;
  padding: 0;
  border: 0;
  border-image: none;
  background: none;
  box-shadow: none;
  overflow: visible;
  pointer-events: none;
}

body.phone.handset-landscape.landscape #game #hud.has-ore-stocks {
  grid-template-areas: "identity money clock controls" "ore ore ore ore";
}

body.phone.handset-landscape.landscape #game #hud button { pointer-events: auto; }

body.phone.handset-landscape.landscape #game #hud :is(#hudShop, #hudFullscreen) { display: none; }

body.phone.handset-landscape.landscape #game #hud :is(.money, .clock) {
  border: 0;
  background: none;
  box-shadow: none;
}

body.phone.handset-landscape.landscape #game #hud #identity {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  justify-items: stretch;
  min-height: 44px;
  margin: 0;
  padding: 0;
  gap: 7px;
  border: 0;
  background: none;
  box-shadow: none;
}

body.phone.handset-landscape.landscape #game :is(#hud, #hud.has-ore-stocks) #identity #portrait {
  width: 44px;
  height: 44px;
  margin: 0;
  border-radius: 3px;
  object-fit: cover;
}

body.phone.handset-landscape.landscape #game #hud #identity > span {
  display: block;
  min-width: 0;
  padding: 0;
}

body.phone.handset-landscape.landscape #game #hud #identity :is(#firm, #reputation) { display: none; }

body.phone.handset-landscape.landscape #game #hud #identity .level-row {
  min-width: 0;
  min-height: 30px;
  margin: 0;
  padding: 5px clamp(10px, 1.7vw, 15px);
  gap: 3px 5px;
  border: 0;
  background: url("./assets/handset-hud-xp.webp") center / 100% 100% no-repeat;
  box-shadow: none;
}

body.phone.handset-landscape.landscape #game #hud #identity .level-row #level {
  padding: 0;
  border: 0;
  white-space: nowrap;
}

body.phone.handset-landscape.landscape #game #hud #identity .level-row #xpText {
  color: #fff0ca;
}

body.phone.handset-landscape.landscape #game #hud #identity .level-row > i {
  height: 5px;
  background: #091d17;
  box-shadow: inset 0 0 0 1px #b78c4b66;
  overflow: hidden;
}

body.phone.handset-landscape.landscape #game #hud #identity .level-row > i > em {
  background: linear-gradient(#ffdf8a, #ba8438);
}

body.phone.handset-landscape.landscape #game #hud .money .cash-counter,
body.phone.handset-landscape.landscape #game #hud.has-ore-stocks .money .cash-counter {
  height: 27px;
  padding: 0 clamp(13px, 2.15vw, 19px);
  border: 0;
  background: url("./assets/handset-hud-cash.webp") center / 100% 100% no-repeat;
  box-shadow: none;
}

body.phone.handset-landscape.landscape #game #hud .money {
  grid-template-rows: 27px auto;
}

body.phone.handset-landscape.landscape #game #hud .money .cash-counter .cash-coin {
  width: 18px;
  height: 18px;
}

body.phone.handset-landscape.landscape #game #hud .money #income,
body.phone.handset-landscape.landscape #game #hud .clock #day {
  align-self: center;
  justify-self: start;
  max-width: 100%;
  padding: 1px 5px;
  border: 1px solid #9c8050;
  border-radius: 2px;
  background: #15372d;
  color: #fff1cc;
  line-height: 13px;
}

body.phone.handset-landscape.landscape #game #hud .clock { grid-template-rows: 20px auto; }

body.handset-landscape #game #mapShortcuts {
  position: absolute;
  z-index: 10;
  top: calc(var(--hud-bottom) + 6px);
  right: var(--touch-right);
  bottom: var(--touch-bottom);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(2px, 1.15dvh, 5px);
  pointer-events: none;
}

body.handset-landscape #game #mapShortcuts > button,
body.handset-landscape #game #globalChatToggle {
  position: relative;
  inset: auto;
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 5px;
  border: 1px solid #cc9c58;
  border-radius: 5px;
  background: linear-gradient(145deg, #285144, #102c23);
  box-shadow: inset 0 0 0 1px #f0bf7355, 0 2px 4px #10231e66;
  color: #fff1cc;
  pointer-events: auto;
}

body.handset-landscape #game #mapShortcuts > button {
  padding: 0;
  border: 0;
  background: url("./assets/handset-hud-tile.webp") center / 100% 100% no-repeat;
  box-shadow: none;
}

body.handset-landscape #game #mapShortcuts #mailboxShortcut img {
  width: 42px;
  height: 42px;
  clip-path: inset(27% 16% round 2px);
}

body.handset-landscape #game #mapShortcuts #eventShortcut::before {
  content: "";
  width: 29px;
  height: 29px;
  background: url("./assets/event-button-deco.png") center / contain no-repeat;
}
body.handset-landscape #game #mapShortcuts #eventShortcut > span { display: none; }

body.handset-landscape #game #mapShortcuts .map-shortcut :is(img, .jewel-icon, .game-icon) {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

body.handset-landscape #game:has(:is(#panel, #dialog, #decision, #meeting, #ending):not([hidden])) #mapShortcuts { visibility: hidden; }
body.handset-landscape #game:not(:has(#world:is([data-scene="city"], [data-scene="eisenhafen"], [data-scene="kranenfels"]))) #mapShortcuts [data-panel] { display: none; }

body.handset-landscape #game #globalChatToggle {
  position: absolute;
  top: 50%;
  left: var(--touch-left);
}
body.handset-landscape #game #globalChatToggle .chat-arrow { display: none; }
body.handset-landscape #game:has(#panel:not([hidden])) #globalChatToggle { visibility: hidden; }

body.handset-landscape #game:has(#world:is([data-scene="city"], [data-scene="eisenhafen"], [data-scene="kranenfels"])) #questTracker { display: none; }

body.handset-landscape #game:has(#world[data-scene="world"]) {
  --world-quest-width: clamp(110px, 18vw, 150px);
}

body.handset-landscape #game:has(#world[data-scene="world"]):has(#questTracker:not([hidden])) nav#dock {
  right: calc(var(--touch-right) + var(--world-quest-width) + 8px) !important;
}

body.handset-landscape #game:has(#world[data-scene="world"]) #questTracker {
  bottom: var(--touch-bottom) !important;
  width: var(--world-quest-width);
  right: var(--touch-right);
  box-sizing: border-box;
  overflow: hidden;
}

body.handset-landscape #game #questTracker .quest-progress {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
}

body.handset-landscape #game #questTracker progress {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
}

body.handset-landscape #game #panel[data-kind="minispiele"] #panelBody {
  padding: 8px 12px;
}

body.handset-landscape #game #panel[data-kind="minispiele"] .match-game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: repeat(4, auto);
  align-items: center;
  align-content: center;
  gap: 6px 14px;
  margin: 0;
  padding: 6px 12px;
}

body.handset-landscape #game #panel[data-kind="minispiele"] .match-game > :not(.match-board) {
  grid-column: 1;
  margin: 0;
}

body.handset-landscape #game #panel[data-kind="minispiele"] .match-game .match-board {
  grid-area: 1 / 2 / 5 / 3;
  width: clamp(156px, calc(100dvh - var(--hud-bottom) - var(--touch-bottom) - 104px), 260px);
  aspect-ratio: 1;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  box-sizing: border-box;
  margin: 0;
  gap: 2px;
  padding: 3px;
}

body.handset-landscape #game #panel[data-kind="minispiele"] #panelBody .match-board button {
  height: 100%;
  min-height: 0;
  padding: 1px;
}

@media (max-height: 350px) {
  body.handset-landscape #game #panel[data-kind="minispiele"] .match-game {
    padding: 4px 8px;
    gap: 4px 10px;
  }
  body.handset-landscape #game #panel[data-kind="minispiele"] .match-game h2 {
    font-size: 16px;
  }
  body.handset-landscape #game #panel[data-kind="minispiele"] .match-game p {
    font-size: 12px;
    line-height: 1.2;
  }
}
