/* NatureDex Mobile V88 – four large topic tiles + one compact founder edit entry.
   Applied only when the V88 client has enhanced the species profile. */
@media (max-width: 680px) {
  /* One full-screen, vertically scrolling species page — no nested page behind it. */
  #animalModal:has(.nd88-profile) {
    padding: 0;
    align-items: stretch;
    justify-items: stretch;
  }
  #animalModal:has(.nd88-profile) .modal-card.n42-modal-card {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    padding: 0;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    border: 0;
    border-radius: 0;
    overscroll-behavior: contain;
  }
  #animalModal:has(.nd88-profile) .n42-modal-card > .modal-close {
    position: sticky;
    top: 9px;
    float: right;
    right: 10px;
    z-index: 12;
    margin: 8px 10px -51px 0;
    color: #1c4a31;
    background: #f8f2de;
    border: 1px solid #d0bd7b;
    border-radius: 50%;
  }
  #animalModal:has(.nd88-profile) .nd88-founder-pencil {
    position: sticky;
    top: 9px;
    float: right;
    right: 0;
    z-index: 12;
    margin: 8px 6px -51px 0;
  }
  #animalModal .nd73.nd88-profile .n42-body {
    padding: 10px 12px 28px;
  }
  #animalModal .nd73.nd88-profile .n42-tabs {
    display: none !important;
  }
  #animalModal .nd73.nd88-profile .nd88-topic-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 9px;
    padding: 7px 0 10px;
    margin: 0;
    background: #0c3020;
    border: 0;
  }
  #animalModal .nd73.nd88-profile .nd88-topic {
    box-sizing: border-box;
    display: flex;
    gap: 7px;
    justify-content: center;
    align-items: center;
    min-width: 0;
    min-height: 55px;
    margin: 0;
    padding: 10px 8px;
    border: 1px solid #927a43;
    border-radius: 14px;
    background: #174530;
    color: #f5edce;
    font: 800 clamp(12px, 3.4vw, 15px)/1.2 system-ui,sans-serif;
    box-shadow: 0 2px 5px #02130a45;
    cursor: pointer;
    overflow-wrap: anywhere;
  }
  #animalModal .nd73.nd88-profile .nd88-topic[aria-pressed="true"] {
    background: #d9eacf;
    color: #19482b;
    border-color: #b6a36f;
    box-shadow: inset 0 0 0 1px #4c8d5c;
  }
  #animalModal .nd73.nd88-profile .nd88-topic:focus-visible,
  #animalModal .nd88-founder-pencil:focus-visible,
  #animalModal .nd88-more-button:focus-visible {
    outline: 3px solid #e8c65f;
    outline-offset: 2px;
  }
  #animalModal .nd73.nd88-profile .nd88-more-topics:not([hidden]) {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 7px;
    padding: 0 0 11px;
    border-bottom: 1px solid #7a683f;
  }
  #animalModal .nd73.nd88-profile .nd88-more-button {
    min-width: 0;
    padding: 10px 7px;
    min-height: 42px;
    background: #1f4933;
    color: #f7edd0;
    border: 1px solid #7f935e;
    border-radius: 10px;
    font: 750 12px/1.35 system-ui,sans-serif;
    cursor: pointer;
    overflow-wrap: anywhere;
  }
  #animalModal .nd73.nd88-profile .nd88-more-button[aria-pressed="true"] {
    color: #143e27;
    background: #e5edda;
    border-color: #bbab71;
  }
  #animalModal .nd73.nd88-profile .n42-tab-pane {
    min-width: 0;
    max-width: 100%;
    padding: 13px 1px 14px;
  }
  /* Keep the founder actions in DOM, but only expose them after tapping the pencil. */
  #animalModal .nd73.nd88-profile .nd88-founder-tools:not(.nd88-open) {
    display: none !important;
  }
  #animalModal .nd73.nd88-profile .nd88-founder-tools.nd88-open {
    display: grid;
    gap: 12px;
    min-width: 0;
    margin: 7px 0 13px;
    padding: 12px;
    border: 1px solid #a8bd93;
    border-radius: 15px;
    background: #e7eedb;
    color: #214a31;
  }
  #animalModal .nd73.nd88-profile .nd88-founder-tools :is(.nd80-review-bar,.n42-dex-progress,.nd78-edit-menu,.nd79-founder-bar) {
    max-width: 100%;
    min-width: 0;
    margin: 0;
  }
  #animalModal .nd73.nd88-profile .nd88-founder-tools button {
    max-width: 100%;
    white-space: normal;
  }
  #animalModal .nd73.nd88-profile .nd73-edit-photo {
    display: none !important;
  }
  #animalModal .nd88-founder-pencil {
    position: absolute;
    z-index: 11;
    top: 11px;
    right: 66px;
    display: grid;
    place-items: center;
    width: 41px;
    height: 41px;
    padding: 0;
    color: #17432b;
    background: #f5f0dd;
    border: 1px solid #d1b969;
    border-radius: 50%;
    font-size: 21px;
    box-shadow: 0 5px 15px #07170a62;
    cursor: pointer;
  }
  #animalModal .nd88-founder-pencil[aria-expanded="true"] {
    background: #d8efce;
    border-color: #4f9b63;
  }
}

/* Latest Daily and Expedition feedback: show ALL categories, not four chips. */
@media (max-width: 680px) {
  body.nd86-ready #gameView .nd86-last-preview:not([hidden]) {
    display: grid;
    gap: 10px;
    padding: 12px;
    background: #f8f6e9;
    border: 1px solid #9bbd93;
    border-radius: 15px;
    color: #214832;
    text-align: left;
    max-width: min(100%, 720px);
    margin: 9px auto 14px;
  }
  body.nd86-ready #gameView .nd86-preview-all {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 8px;
  }
  body.nd86-ready #gameView .nd86-last-preview .nd86-cell {
    min-width: 0;
    padding: 9px 8px;
    border-radius: 10px;
    font-size: 12px;
  }
  body.nd86-ready #gameView .nd86-last-preview .nd86-cell-title {
    font-size: 10px;
    margin-bottom: 5px;
  }
  body.nd86-ready #gameView .nd86-last-preview .nd86-cell-value,
  body.nd86-ready #gameView .nd86-last-preview .nd86-cell-value .hint {
    line-height: 1.32;
    font-size: 11px;
  }
  body.nd86-ready #gameView .nd86-preview-open {
    justify-self: start;
    min-height: 40px;
    padding: 8px 0;
    font-size: 13px;
  }
  /* V86 already provides its own two-button footer. Avoid a second floating button. */
  body:has(#nd86QuickPlay) #gameView .nd86-comparison-launcher { display: none !important; }
  #gameView #nd86QuickPlay { z-index: 90; }
}


/* V89 | Mobile corrections: keep each modal action in its own corner.
   V88's floating pencil is NOT the nd78 profile editing button. */
@media (max-width: 680px) {
  #animalModal:has(.nd88-profile) .n42-modal-card > .nd88-founder-pencil {
    position: sticky !important;
    float: left !important;
    top: 9px !important;
    left: 10px !important;
    right: auto !important;
    margin: 8px 0 -51px 10px !important;
    z-index: 25 !important;
    width: 41px;
    height: 41px;
  }
  #animalModal:has(.nd88-profile) .n42-modal-card > .modal-close {
    position: sticky !important;
    float: right !important;
    top: 9px !important;
    left: auto !important;
    right: 10px !important;
    margin: 8px 10px -51px 0 !important;
    z-index: 30 !important;
  }
}
/* V89 | One clean logo row and one control row, on home and in-game.
   Fixed grid slots prevent the language/theme/account buttons from colliding. */
@media (max-width: 680px) {
  body.n35-signed-in.hub-on-home .topbar,
  body:not(.hub-on-home) .topbar {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    grid-template-rows: auto auto !important;
    align-items: stretch !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    gap: 8px !important;
    padding: max(9px,env(safe-area-inset-top)) 10px 10px !important;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar > .logo,
  body:not(.hub-on-home) .topbar > .logo {
    grid-column: 1; grid-row: 1;
    position: static !important;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 19px !important;
    line-height: 1.25 !important;
    text-align: left;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar > .header-actions,
  body:not(.hub-on-home) .topbar > .header-actions {
    grid-column: 1; grid-row: 2;
    position: static !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, .85fr) minmax(0, 1.2fr) 40px 40px !important;
    align-items: stretch !important;
    justify-content: stretch !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 5px !important;
    min-width: 0;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar .header-actions > .wallet-group {display:none !important;}
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar .header-actions > :is(#languageSelect, #n30ThemeToggle, #globalAccountBtn, #settingsBtn, #helpBtn) {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    height: 42px !important;
    min-height: 42px !important;
    margin: 0 !important;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 9px;
    padding: 6px !important;
    font-size: 12px !important;
    line-height: 1.25;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #languageSelect {grid-column:1;grid-row:1;}
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #n30ThemeToggle {grid-column:2;grid-row:1;}
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #globalAccountBtn {grid-column:3;grid-row:1;}
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #settingsBtn {grid-column:4;grid-row:1;}
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #helpBtn {grid-column:5;grid-row:1;}
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #n30FounderNotice:not(.hidden) {
    grid-column:1/-1;grid-row:2;
    width:100%;justify-self:stretch;
    min-height:36px;max-height:40px;
    margin:0;font-size:12px;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #ndNewsShortcut {display:none !important;}
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar > nav {display:none !important;}
}


/* V90: A tall sticky desktop header must never float over mobile gameplay. */
@media(max-width:680px) {
  body.n35-signed-in.hub-on-home .topbar,
  body:not(.hub-on-home) .topbar {
    position: relative !important;
    top: auto !important;
    inset: auto !important;
    z-index: 9;
    box-shadow: none;
    grid-template-rows: auto auto !important;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar > .header-actions {
    grid-template-columns: minmax(0,1.2fr) minmax(0,.75fr) minmax(0,1.1fr) repeat(3,minmax(33px,37px)) !important;
    grid-auto-rows: 42px;
    gap: 4px !important;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #n30FounderNotice:not(.hidden) {
    grid-column: 6 !important;
    grid-row: 1 !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 42px !important;
    max-height: 42px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 0 2px !important;
    font-size: 17px !important;
    border-radius: 9px;
    white-space: nowrap;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #n30FounderNotice > span {
    display: none !important;
  }
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar #n30FounderNotice > b {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    min-width: 15px;
    height: 17px;
    padding: 0 2px;
    font: 700 10px/1 system-ui,sans-serif;
    border-radius: 7px;
  }
  /* Nothing in the header may spill over the next viewport row. */
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar,
  body:is(.n35-signed-in.hub-on-home,:not(.hub-on-home)) .topbar > .header-actions {
    min-width: 0;
    max-width: 100%;
  }
}
