/* M12.7 — tighten object labels and compact expedition/status pills.
   Mobile-only visual adjustments; original click targets remain unchanged. */
@media (orientation: landscape) and (max-width: 1000px) and (max-height: 540px) {
  :root[data-window-layout="compact"] #game {
    --m12-cream: #fff4db;
    --m12-ink: #4c311e;
    --m12-gold: #cba165;
  }

  /* HUD: keep the controls attached to the viewport, but visually split the line
     into light floating cards instead of one heavy solid strip. */
  :root[data-window-layout="compact"] #game .topbar {
    box-sizing: border-box;
    top: calc(var(--app-viewport-top) + var(--app-safe-top));
    left: calc(var(--app-viewport-left) + var(--app-safe-left));
    width: calc(var(--app-viewport-width) - var(--app-safe-left) - var(--app-safe-right));
    min-height: 42px !important;
    height: 42px !important;
    padding: 0 2px !important;
    gap: 4px !important;
    align-items: center;
    border: 0;
    border-radius: 0;
    background: transparent !important;
    box-shadow: none;
    backdrop-filter: none;
  }
  :root[data-window-layout="compact"] #game .topbar #open-profile {
    flex: 0 0 clamp(106px, 18vw, 132px);
    width: clamp(106px, 18vw, 132px);
    height: 38px;
    min-height: 38px !important;
    grid-template-columns: 29px minmax(0,1fr);
    padding: 3px 5px;
    gap: 5px;
    border: 1px solid #d9ad70;
    border-radius: 12px;
    background: linear-gradient(#fff9e9,#f4ddb8);
    box-shadow: inset 0 1px #fff,0 2px 5px #09192d42;
  }
  :root[data-window-layout="compact"] #game .topbar #open-profile .brand-mark {
    width: 29px;
    height: 29px;
    flex-shrink: 0;
  }
  :root[data-window-layout="compact"] #game .topbar #open-profile .profile-copy { gap: 0; }
  :root[data-window-layout="compact"] #game .topbar #open-profile #player-name {
    font: 700 12px/1.05 Arial,sans-serif !important;
    color: #392719;
    text-overflow: ellipsis;
  }
  :root[data-window-layout="compact"] #game .topbar #open-profile #player-progress,
  :root[data-window-layout="compact"] #game .topbar #open-profile #player-progress > * {
    font: 700 9px/1.05 Arial,sans-serif !important;
    color: #42617a;
  }
  :root[data-window-layout="compact"] #game .topbar .resources {
    flex: 1 1 0;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    min-width: 0;
    height: 38px;
    gap: 4px !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  :root[data-window-layout="compact"] #game .topbar .resources::-webkit-scrollbar { display:none; }
  :root[data-window-layout="compact"] #game .topbar .resources .resource {
    flex: 0 0 auto;
    min-width: 56px;
    width: max-content;
    height: 38px;
    min-height: 38px;
    padding: 2px 6px !important;
    gap: 3px !important;
    border: 1px solid #c7cee044 !important;
    border-radius: 12px !important;
    background: linear-gradient(180deg,#213a5ce3,#1a2f4ddf) !important;
    box-shadow: inset 0 1px #ffffff20,0 2px 4px #0c173058 !important;
  }
  :root[data-window-layout="compact"] #game .topbar .resources .resource .resource-icon {
    flex: 0 0 22px !important;
    width: 22px !important;
    height: 22px !important;
  }
  :root[data-window-layout="compact"] #game .topbar .resources .resource small {
    display: none;
  }
  :root[data-window-layout="compact"] #game .topbar .resources .resource b {
    font: 800 13px/1.05 Arial,sans-serif !important;
    color: #fff5e5 !important;
    letter-spacing: .1px;
    white-space: nowrap;
  }
  :root[data-window-layout="compact"] #game .topbar #open-post {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    margin: 0;
    border: 1px solid #d6aa71 !important;
    border-radius: 12px !important;
    background: linear-gradient(#fff6e3,#edce9e) !important;
    box-shadow: inset 0 1px #fff,0 2px 4px #0b173b48 !important;
  }
  :root[data-window-layout="compact"] #game .topbar #open-post::after { font-size: 22px; }

  /* Bottom dock: smaller and calmer, so the meadow stays the main hero. */
  :root[data-window-layout="compact"] #game .ref-dock {
    position: absolute;
    inset: auto !important;
    left: calc(var(--window-left) + 7px) !important;
    right: auto !important;
    transform: none;
    bottom: calc(var(--window-bottom) + 4px) !important;
    width: min(292px,calc(var(--window-width) - 14px));
    max-width: calc(var(--window-width) - 14px);
    height: 52px;
    margin: 0 !important;
    padding: 3px;
    display: grid;
    grid-template-columns: repeat(5,minmax(0,1fr));
    align-items: stretch;
    gap: 3px;
    border: 1px solid #d6ac73;
    border-radius: 15px;
    background: linear-gradient(#14304bdd,#10243be9);
    box-shadow: 0 5px 14px #0b162f72,inset 0 1px #ffffff33;
    z-index: 49;
  }
  :root[data-window-layout="compact"] #game .ref-dock > button {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-width: 0;
    min-height: 44px;
    width: 100%;
    height: 44px;
    padding: 2px 1px;
    gap: 1px;
    border: 1px solid #c99c65;
    border-radius: 10px;
    background: linear-gradient(#fff9ec,#e7cda7);
    color: #55361f;
    font: 700 9px/1 Arial,sans-serif !important;
    box-shadow: inset 0 1px white;
    text-shadow: none;
  }
  :root[data-window-layout="compact"] #game .ref-dock > button img {
    display: block;
    width: 22px;
    height: 22px;
    object-fit: contain;
  }
  :root[data-window-layout="compact"] #game .ref-dock > button:not(.meadow-sections) > span {
    display: block;
    font: 700 8px/1 Arial,sans-serif;
    white-space: nowrap;
  }
  :root[data-window-layout="compact"] #game .ref-dock .meadow-sections {
    background: linear-gradient(#914e33,#663421);
    color: #fff3d7;
    border-color: #e0b476;
    font: 700 9px/1 Arial,sans-serif !important;
  }
  :root[data-window-layout="compact"] #game .ref-dock .meadow-sections::before {
    content: '☰';
    display:block;
    font-size: 18px;
    line-height: 19px;
  }
  :root[data-window-layout="compact"] #game .ref-dock .meadow-sections[aria-expanded="true"]::before { content:'×'; }

  /* “Разделы”: compact bottom tray instead of a tall left stack. */
  :root[data-window-layout="compact"] #game .ref-rail {
    position: absolute;
    inset: auto !important;
    left: calc(var(--window-left) + 8px) !important;
    right: auto !important;
    top: auto !important;
    bottom: calc(var(--window-bottom) + 60px) !important;
    width: min(326px,calc(var(--window-width) - 16px));
    max-width: calc(var(--window-width) - 16px);
    max-height: min(204px,calc(var(--window-height) - 118px));
    margin: 0 !important;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 7px;
    box-sizing: border-box;
    grid-template-columns: repeat(3,minmax(0,1fr));
    grid-auto-flow: row;
    gap: 4px;
    align-content: start;
    border: 1px solid #d6ad73;
    border-radius: 16px;
    background: linear-gradient(#fff7eaf7,#f2ddbaf7);
    box-shadow: 0 12px 30px #101c35a8;
    scrollbar-color: #b78350 #f7e2c4;
    z-index: 60;
  }
  :root[data-window-layout="compact"] #game .ref-rail[data-expanded] { display: grid; }
  :root[data-window-layout="compact"] #game .ref-rail::before { content: none; }
  :root[data-window-layout="compact"] #game .ref-rail[data-expanded] > :is(button,a) {
    width: 100%;
    min-height: 60px;
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    margin: 0;
    padding: 4px 4px;
    border: 1px solid #dbbd93;
    border-radius: 11px;
    background: #fff9ed;
    box-shadow: 0 2px 4px #71502a18;
    font: 700 10px/1.15 Arial,sans-serif;
    text-align:center;
    color: #57371f;
    overflow-wrap: anywhere;
  }
  :root[data-window-layout="compact"] #game .ref-rail > button img {
    flex: 0 0 22px;
    width: 22px;
    height: 22px;
  }
  :root[data-window-layout="compact"] #game .ref-rail .meadow-support span {
    font: 700 16px/1 Georgia,serif;
  }

  /* Each existing order/event action uses the same tile as the other sections. */
  :root[data-window-layout="compact"] #game .ref-rail .ref-activity {
    display: contents;
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }
  :root[data-window-layout="compact"] #game .ref-rail .ref-activity button {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: none;
    min-width: 0;
    width: 100%;
    height: 60px;
    min-height: 60px;
    margin: 0;
    padding: 4px 4px;
    gap: 2px;
    border: 1px solid #dbbd93;
    border-radius: 11px;
    background: #fff9ed;
    color: #57371f;
    text-shadow: none;
    box-shadow: 0 2px 4px #71502a18;
    font: 700 10px/1.15 Arial,sans-serif;
    text-align: center;
  }
  :root[data-window-layout="compact"] #game .ref-rail .ref-activity button:first-child {
    border-color: #dbbd93;
    background: #fff9ed;
    color: #57371f;
    text-shadow: none;
  }
  :root[data-window-layout="compact"] #game .ref-rail .ref-activity button[hidden] {
    display: none !important;
  }
  :root[data-window-layout="compact"] #game .ref-rail .ref-activity img {
    display: block;
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    object-fit: contain;
    grid-row: auto;
  }
  :root[data-window-layout="compact"] #game .ref-rail .ref-activity button b {
    display: block;
    font: inherit;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  :root[data-window-layout="compact"] #game .ref-rail .ref-activity button small {
    display: none !important;
  }

  /* The old quest postcard duplicates “Задания”. Keep it in the DOM with
     its game handlers, but hide it only inside the compact sections tray. */
  :root[data-window-layout="compact"] #game .ref-rail #quest-card {
    display: none !important;
  }

  /* A factory order is not an expedition. Keep the workshop source state
     in its original DOM for API and accessibility, but do not float it across
     the meadow; the factory view and the button's aria-label keep the status. */
  :root[data-window-layout="compact"] #game #scene #workshop-world-status,
  :root[data-window-layout="compact"] #game #scene #sleigh-world-status {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
  :root[data-window-layout="compact"] #world-labels .raised-sleigh-status[data-state="traveling"] {
    background: #294e72ee !important;
    border-color: #b5d5e5 !important;
    color: #fff6e4 !important;
  }
  :root[data-window-layout="compact"] #world-labels .raised-sleigh-status[data-state="ready"] {
    background: #315d42ef !important;
    border-color: #c9dbab !important;
    color: #fff8e7 !important;
  }

  /* Floating names, not boxed placards; the world-label JS supplies true levels. */
  :root[data-window-layout="compact"] #world-labels .raised-world-name {
    font: 700 9px/1.12 system-ui,sans-serif;
    color: #513521;
    white-space: nowrap;
  }
  :root[data-window-layout="compact"] #world-labels .raised-world-level {
    font: 700 8.5px/1.12 system-ui,sans-serif;
    white-space: nowrap;
    color: #61432e;
    opacity: .95;
  }
  :root[data-window-layout="compact"] #world-labels .raised-world-status {
    font: 700 8.5px/1.12 system-ui,sans-serif;
    white-space: nowrap;
    color: #2f7549;
  }

  :root[data-window-layout="compact"] #game .topbar :is(button,.resource):focus-visible,
  :root[data-window-layout="compact"] #game .ref-dock button:focus-visible,
  :root[data-window-layout="compact"] #game .ref-rail :is(button,a):focus-visible {
    outline: 2px solid #ffdf7f;
    outline-offset: 1px;
  }
}

/* Opening the sections tray should not detach captions from the world. */
@media (orientation: landscape) and (max-width: 1000px) and (max-height: 540px) {
  :root[data-window-layout="compact"] body.meadow-sections-open #world-labels {
    visibility: hidden;
  }
}

/* M12.7 hide detached workshop status */
@media (orientation: landscape) and (pointer: coarse) {
  #workshop-world-status {
    display: none !important;
  }
}


/* M12.7.1: hide legacy workshop badge on mobile */
@media screen and (pointer: coarse) and (orientation: landscape) {
  #workshop-world-status {
    display: none !important;
  }
}
