/* Phone layout (mobile-ui.js). Loaded last. Everything is inside the phone media queries, so the
   desktop and tablet layouts are untouched. Body classes from mobile-ui.js:
   m-clean (hide panels), m-solid (see-through off), m-min-mission / m-min-dock (folded to pills),
   m-hide-<panel> (switched off in the Layout sheet), m-cam-open (camera buttons showing). */

.m-hud,
.m-cam-btn,
.m-min {
  display: none;
}

@media (max-width: 700px), (max-height: 500px) and (max-width: 950px) {
  /* --------------------------------------------------------------- shared glass */
  body {
    --m-glass: #0f2218a6;
    --m-glass-strong: #0f2218cc;
    --m-line: #ffffff2b;
    --m-ink: #f5f3ea;
    --m-soft: #cdd6c3;
    --m-gold: #e4b860;
    --m-blur: blur(10px) saturate(1.2);
    --m-dock-h: 58px;
    --m-gap: 10px;
  }
  body.m-solid {
    --m-glass: #12271cf2;
    --m-glass-strong: #12271cfa;
  }

  /* On the farm the view fits the screen, so the bottom bar is never below the fold on short phones. */
  body.playing #world {
    min-height: 0;
  }

  /* --------------------------------------------------------------- HUD buttons */
  body.playing:not(.entering) #world .m-hud {
    position: absolute;
    z-index: 7;
    top: var(--m-gap);
    right: 12px;
    display: flex;
    gap: 6px;
  }
  .m-hud-btn,
  .m-cam-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 34px;
    padding: 0 11px;
    border-radius: 17px;
    border: 1px solid var(--m-line);
    background: var(--m-glass);
    backdrop-filter: var(--m-blur);
    -webkit-backdrop-filter: var(--m-blur);
    color: var(--m-ink);
    font-size: 9px;
    letter-spacing: 1.2px;
    cursor: pointer;
  }
  .m-hud-btn span,
  .m-cam-btn span {
    font-size: 15px;
    line-height: 1;
  }
  .m-hud-btn[aria-pressed='true'],
  .m-cam-btn[aria-expanded='true'] {
    background: var(--m-gold);
    border-color: var(--m-gold);
    color: #14291e;
  }

  /* The old landing-era overlays that add nothing on a phone once you're on the farm. */
  body.playing #world .world-topline,
  body.playing #world .location-tag,
  body.playing #world .world-controls,
  body.playing #world .engine-status,
  body.playing #world #markers {
    display: none;
  }
  body.playing #world .world-vignette {
    background: linear-gradient(0deg, #0d201666, transparent 22%);
  }

  /* --------------------------------------------------------------- scores: two pills, top left */
  body.playing #world .score-stack {
    top: var(--m-gap);
    bottom: auto;
    left: 12px;
    right: auto;
    width: auto;
    display: flex;
    gap: 6px;
  }
  body.playing #world .score-card,
  body.playing #world .real-score {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 11px;
    border-radius: 17px;
    border: 1px solid var(--m-line);
    background: var(--m-glass);
    backdrop-filter: var(--m-blur);
    -webkit-backdrop-filter: var(--m-blur);
    color: var(--m-ink);
    box-shadow: none;
  }
  /* "VIRTUAL PWR" / "REAL PWR" shortened to fit beside the Hide and Layout buttons. */
  body.playing #world .score-card > .eyebrow,
  body.playing #world .real-score b {
    font-size: 0;
    letter-spacing: 0;
    margin: 0;
  }
  body.playing #world .score-card > .eyebrow:before,
  body.playing #world .real-score b:before {
    content: 'PWR';
    font-size: 8px;
    letter-spacing: 1px;
    color: var(--m-gold);
  }
  body.playing #world .real-score b:before {
    content: 'REAL';
    color: var(--m-ink);
  }
  body.playing #world .real-score > span:last-child:not(.score-icon) {
    display: none;
  }
  #m-layout-btn b {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  #m-layout-btn {
    width: 34px;
    padding: 0;
    justify-content: center;
  }
  body.playing #world .score-card .tiny-arrow,
  body.playing #world .score-card .score-caption,
  body.playing #world .score-card .score-line,
  body.playing #world .score-card .score-unit,
  body.playing #world .real-score small {
    display: none;
  }
  body.playing #world .score-card > div {
    display: flex;
    align-items: baseline;
  }
  body.playing #world .score-card strong {
    font-size: 15px;
    line-height: 1;
  }
  body.playing #world .real-score .score-icon {
    font-size: 13px;
    color: var(--m-gold);
  }
  body.playing #world .real-score > span:not(.score-icon) {
    display: contents;
  }

  /* --------------------------------------------------------------- Next move card */
  body.playing #world .mission-card {
    top: calc(var(--m-gap) + 42px);
    left: 12px;
    right: 12px;
    width: auto;
    padding: 12px 44px 12px 14px;
    border-radius: 10px;
    background: var(--m-glass);
    backdrop-filter: var(--m-blur);
    -webkit-backdrop-filter: var(--m-blur);
    border: 1px solid var(--m-line);
    box-shadow: none;
  }
  body.playing #world .mission-card .eyebrow {
    font-size: 8px;
    margin-bottom: 4px;
  }
  body.playing #world .mission-card h2 {
    font-size: 19px;
    margin: 0 0 4px;
    line-height: 1.15;
  }
  body.playing #world .mission-card p {
    font-size: 12px;
    line-height: 1.45;
    margin: 0 0 9px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  body.playing #world .mission-card .primary {
    padding: 9px 12px;
    font-size: 9px;
    margin: 0;
  }
  body.playing #world .mission-card > small,
  body.playing #world .mission-card .mission-progress {
    display: none;
  }
  .m-min {
    display: grid;
    place-items: center;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--m-line);
    background: #ffffff14;
    color: var(--m-ink);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    z-index: 1;
  }
  /* Folded: a one-line pill with the title; tap it to open again. */
  body.m-min-mission.playing #world .mission-card {
    right: auto;
    max-width: calc(100% - 24px);
    padding: 7px 42px 7px 12px;
    border-radius: 20px;
    cursor: pointer;
  }
  body.m-min-mission.playing #world .mission-card .eyebrow,
  body.m-min-mission.playing #world .mission-card p,
  body.m-min-mission.playing #world .mission-card .primary {
    display: none;
  }
  body.m-min-mission.playing #world .mission-card h2 {
    font-size: 13px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body.m-min-mission.playing #world .mission-card h2:before {
    content: '● ';
    color: var(--m-gold);
    font-size: 10px;
    vertical-align: 2px;
  }
  body.m-min-mission #world .mission-card .m-min {
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    font-size: 16px;
  }

  /* --------------------------------------------------------------- farm status bar */
  body.playing #world .farm-dock {
    left: 12px;
    right: 12px;
    bottom: var(--m-gap);
    min-height: var(--m-dock-h);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto 34px;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 10px;
    row-gap: 1px;
    padding: 8px 8px 8px 14px;
    border-radius: 12px;
    background: var(--m-glass-strong);
    backdrop-filter: var(--m-blur);
    -webkit-backdrop-filter: var(--m-blur);
    border: 1px solid var(--m-line);
    box-shadow: 0 6px 24px #0003;
    color: var(--m-ink);
  }
  body.playing #world .farm-dock .field-icon,
  body.playing #world .farm-dock .dock-identity .eyebrow,
  body.playing #world .farm-dock .dock-stat:not(:nth-of-type(1)),
  body.playing #world .farm-dock .dock-stat > span {
    display: none;
  }
  body.playing #world .farm-dock .dock-identity {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }
  body.playing #world .farm-dock .dock-identity h3 {
    font-size: 16px;
    color: var(--m-ink);
    max-width: none;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body.playing #world .farm-dock .dock-stat:nth-of-type(1) {
    display: block;
    grid-column: 1;
    grid-row: 2;
    padding: 0;
    border: 0;
    min-width: 0;
  }
  body.playing #world .farm-dock .dock-stat b {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--m-soft);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body.playing #world .farm-dock .dock-action {
    grid-column: 2;
    grid-row: 1 / span 2;
    padding: 11px 12px;
    font-size: 9px;
    border-radius: 8px;
    background: var(--m-gold);
    color: #14291e;
    white-space: nowrap;
  }
  body.playing #world .farm-dock .dock-action span {
    margin-left: 6px;
  }
  body.playing #world .farm-dock .m-min {
    position: static;
    grid-column: 3;
    grid-row: 1 / span 2;
  }
  body.m-min-dock.playing #world .farm-dock {
    right: auto;
    min-height: 0;
    grid-template-columns: auto 26px;
    grid-template-rows: auto;
    padding: 5px 5px 5px 12px;
    border-radius: 20px;
    cursor: pointer;
  }
  body.m-min-dock.playing #world .farm-dock .dock-stat,
  body.m-min-dock.playing #world .farm-dock .dock-action {
    display: none;
  }
  body.m-min-dock.playing #world .farm-dock .dock-identity h3 {
    font-size: 12px;
    max-width: 52vw;
  }
  body.m-min-dock.playing #world .farm-dock .m-min {
    grid-column: 2;
    grid-row: 1;
    width: 26px;
    height: 26px;
    font-size: 16px;
  }

  /* --------------------------------------------------------------- quick actions: one row */
  body.playing #world .farm-quick-actions {
    top: auto;
    left: 0;
    right: 0;
    bottom: calc(var(--m-gap) + var(--m-dock-h) + 8px);
    max-width: none;
    padding: 0 12px 2px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
    mask-image: linear-gradient(90deg, #000 88%, transparent);
  }
  body.playing #world .farm-quick-actions::-webkit-scrollbar {
    display: none;
  }
  body.playing #world .farm-quick-actions button {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 17px;
    font-size: 9px;
    background: var(--m-glass);
    backdrop-filter: var(--m-blur);
    -webkit-backdrop-filter: var(--m-blur);
    border: 1px solid var(--m-line);
    color: var(--m-ink);
  }
  body.playing #world .farm-quick-actions .qa-primary {
    background: #e4b860e6;
    color: #14291e;
    border-color: transparent;
  }
  body.m-min-dock.playing #world .farm-quick-actions,
  body.m-hide-dock.playing #world .farm-quick-actions {
    bottom: calc(var(--m-gap) + 44px);
  }
  body.m-min-dock.m-hide-dock.playing #world .farm-quick-actions,
  body.m-hide-dock.playing #world .farm-quick-actions {
    bottom: var(--m-gap);
  }

  /* --------------------------------------------------------------- camera: one View button */
  body.playing:not(.entering) #world .m-cam-btn {
    display: inline-flex;
    position: absolute;
    z-index: 6;
    left: 12px;
    bottom: calc(var(--m-gap) + var(--m-dock-h) + 52px);
  }
  body.playing #world .camera-tools {
    display: none;
  }
  body.m-cam-open.playing #world .camera-tools {
    display: grid;
    grid-template-columns: repeat(4, 40px);
    left: 12px;
    right: auto;
    top: auto;
    bottom: calc(var(--m-gap) + var(--m-dock-h) + 94px);
    border-radius: 12px;
    background: var(--m-glass-strong);
    backdrop-filter: var(--m-blur);
    -webkit-backdrop-filter: var(--m-blur);
    border-color: var(--m-line);
    z-index: 6;
  }
  body.m-cam-open.playing #world .camera-tools button {
    width: 40px;
    height: 40px;
  }
  body.m-cam-open.playing #world .camera-tools > span {
    display: none;
  }
  body.m-min-dock.playing #world .m-cam-btn,
  body.m-hide-dock.playing #world .m-cam-btn {
    bottom: calc(var(--m-gap) + 88px);
  }
  body.m-min-dock.m-cam-open.playing #world .camera-tools,
  body.m-hide-dock.m-cam-open.playing #world .camera-tools {
    bottom: calc(var(--m-gap) + 130px);
  }

  /* Walking pad and the picked-place card sit above the bottom stack. */
  body.playing #world .movement {
    left: auto;
    right: 12px;
    bottom: calc(var(--m-gap) + var(--m-dock-h) + 100px);
  }
  body.playing #world .movement button {
    background: var(--m-glass);
    backdrop-filter: var(--m-blur);
    -webkit-backdrop-filter: var(--m-blur);
  }
  body.playing #world .world-card {
    bottom: calc(var(--m-gap) + var(--m-dock-h) + 50px);
    max-height: 52svh;
    overflow-y: auto;
    z-index: 8;
  }

  /* --------------------------------------------------------------- Clover on phones */
  .host-launch {
    padding: 0;
    right: 12px;
  }
  body.playing:not(.farm-mode):not(.library-mode):not(.talent-mode) .host-launch {
    bottom: calc(var(--m-gap) + var(--m-dock-h) + 52px);
  }
  body.playing:not(.farm-mode):not(.library-mode):not(.talent-mode).m-min-dock .host-launch,
  body.playing:not(.farm-mode):not(.library-mode):not(.talent-mode).m-hide-dock .host-launch {
    bottom: calc(var(--m-gap) + 88px);
  }
  .host-launch .host-mini {
    width: 48px;
    height: 48px;
  }
  .host-launch-bubble {
    width: max-content;
    max-width: min(230px, 62vw);
    font-size: 13px;
    line-height: 1.35;
    padding: 9px 12px;
  }
  body.m-hide-peeks .host-launch-bubble {
    display: none !important;
  }

  /* --------------------------------------------------------------- switched off / clean view */
  body.m-hide-mission #world .mission-card,
  body.m-hide-actions #world .farm-quick-actions,
  body.m-hide-scores #world .score-stack,
  body.m-hide-dock #world .farm-dock,
  body.m-hide-camera #world .m-cam-btn,
  body.m-hide-camera #world .camera-tools {
    display: none !important;
  }
  body.m-clean.playing #world .mission-card,
  body.m-clean.playing #world .farm-quick-actions,
  body.m-clean.playing #world .score-stack,
  body.m-clean.playing #world .farm-dock,
  body.m-clean.playing #world .m-cam-btn,
  body.m-clean.playing #world .camera-tools,
  body.m-clean.playing #world #m-layout-btn,
  body.playing:not(.farm-mode):not(.library-mode):not(.talent-mode).m-clean .host-launch {
    display: none !important;
  }

  /* --------------------------------------------------------------- top bar */
  /* Signed in, Sign out is in the ☰ menu and the account dialog; the space goes to the farm clock. */
  .header .account-btn.signed-in {
    display: none;
  }
  .header .farm-clock {
    min-width: 0;
    flex: 0 1 auto;
  }

  /* --------------------------------------------------------------- Layout sheet */
  .m-sheet-back {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #0008;
    display: flex;
    align-items: flex-end;
  }
  .m-sheet {
    width: 100%;
    max-height: 86svh;
    overflow-y: auto;
    background: #13271c;
    color: var(--m-ink);
    border-radius: 16px 16px 0 0;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 40px #0006;
  }
  .m-sheet header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }
  .m-sheet .eyebrow {
    color: var(--m-gold);
    font-size: 9px;
  }
  .m-sheet h2 {
    margin: 4px 0 6px;
    font-size: 24px;
    color: var(--m-ink);
  }
  .m-sheet h3 {
    font-size: 9px;
    letter-spacing: 1.5px;
    color: var(--m-gold);
    margin: 16px 0 4px;
  }
  .m-sheet-lead {
    font-size: 13px;
    color: var(--m-soft);
    margin: 0 0 8px;
  }
  .m-sheet-x {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--m-line);
    background: none;
    color: var(--m-ink);
    font-size: 15px;
  }
  .m-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid #ffffff14;
    cursor: pointer;
  }
  .m-row b {
    display: block;
    font-size: 14px;
    font-weight: 600;
  }
  .m-row small {
    display: block;
    font-size: 11px;
    color: var(--m-soft);
    margin-top: 2px;
  }
  .m-row input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
  }
  .m-row i {
    flex: none;
    width: 44px;
    height: 26px;
    border-radius: 13px;
    background: #ffffff2e;
    position: relative;
    transition: background 0.2s;
  }
  .m-row i:after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
  }
  .m-row input:checked + i {
    background: var(--m-gold);
  }
  .m-row input:checked + i:after {
    transform: translateX(18px);
  }
  .m-row input:focus-visible + i {
    outline: 2px solid var(--m-gold);
    outline-offset: 3px;
  }
  .m-sheet-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 16px;
  }
  .m-sheet-actions button {
    padding: 13px 8px;
    font-size: 10px;
  }
  .m-sheet-actions .secondary {
    color: var(--m-ink);
    border: 1px solid var(--m-line);
    background: transparent;
  }

  /* --------------------------------------------------------------- farm office on phones */
  #farm-hub .fh-top {
    gap: 8px;
  }
  #farm-hub .fh-top-stats {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
  }
  /* Stats on the first line, the tool buttons as one row of round buttons under them. */
  #farm-hub .fh-top-stats:after {
    content: '';
    order: 1;
    flex-basis: 100%;
    height: 0;
  }
  #farm-hub .fh-top-stats > button {
    order: 2;
    flex: 0 0 auto;
    min-width: 38px;
    height: 38px;
    justify-content: center;
  }
  #farm-hub .fh-top-stats > .fh-agro {
    padding: 2px;
  }
  /* agronomist.css hides every span in this button on small screens, including the face. */
  #farm-hub .fh-top-stats > .fh-agro > .agro-live {
    display: block;
  }
  #farm-hub .fh-top-stats > span {
    min-width: 0;
  }
  #farm-hub .fh-top-stats > span:nth-of-type(4),
  #farm-hub .fh-top-stats em {
    display: none;
  }
  #farm-hub .fh-top-stats small {
    font-size: 9px;
  }
  #farm-hub .fh-top-stats b {
    font-size: 13px;
    white-space: nowrap;
  }
  #farm-hub .coach-hint {
    padding: 8px 10px;
    gap: 6px;
    font-size: 13px;
  }
  #farm-hub .coach-hint-actions .text-link {
    display: none;
  }
  #farm-hub .coach-hint-actions button {
    padding: 7px 10px;
    font-size: 10px;
  }
}

/* Short landscape phones: the stack is lower, so drop the description and keep the card narrow. */
@media (max-height: 500px) and (max-width: 950px) {
  body.playing #world .mission-card {
    right: auto;
    width: min(360px, 48vw);
  }
  body.playing #world .mission-card p {
    display: none;
  }
  body.playing #world .farm-dock {
    right: auto;
    width: min(420px, 60vw);
  }
  body.playing #world .farm-quick-actions {
    left: auto;
    right: 0;
    width: 44vw;
    bottom: var(--m-gap);
  }
  body.playing:not(.entering) #world .m-cam-btn {
    left: auto;
    right: 74px;
    bottom: calc(var(--m-gap) + 50px);
  }
  body.playing:not(.farm-mode):not(.library-mode):not(.talent-mode) .host-launch,
  body.playing:not(.farm-mode):not(.library-mode):not(.talent-mode).m-min-dock .host-launch,
  body.playing:not(.farm-mode):not(.library-mode):not(.talent-mode).m-hide-dock .host-launch {
    bottom: calc(var(--m-gap) + 44px);
  }
  .host-launch-label {
    display: none;
  }
  body.m-cam-open.playing #world .camera-tools {
    left: auto;
    right: 12px;
    bottom: calc(var(--m-gap) + 86px);
  }
}

html[data-motion='calm'] .m-row i,
html[data-motion='calm'] .m-row i:after {
  transition: none;
}
