/* Spencer Quests — mobile (≤700px). Loaded after styles.css. */
@media (max-width: 700px) {
  :root {
    --meter-lift: max(8px, env(safe-area-inset-bottom, 8px));
    --meter-gap: 8px;
    --play-footer-h: 168px;
    --desk-dock-h: 0px;
    --mobile-chrome-h: 132px;
  }

  body {
    overflow-x: hidden;
  }

  body:has(.app.has-daypanel:not(.prologue)) {
    overflow: hidden;
    height: 100%;
  }

  /* ── App shell ── */
  .app {
    display: flex !important;
    flex-direction: column;
    grid-template-columns: unset !important;
    grid-template-areas: unset !important;
    min-height: 100svh;
    max-height: 100svh;
    height: 100svh;
    overflow: hidden;
    padding: max(6px, env(safe-area-inset-top, 6px)) 10px var(--play-footer-h, 168px);
    max-width: none;
    margin: 0;
  }

  .app.has-daypanel {
    display: flex !important;
    flex-direction: column;
    max-height: 100svh;
    height: 100svh;
    overflow: hidden;
  }

  /* ── Header ── */
  .topbar {
    flex: 0 0 auto;
    margin-bottom: 4px;
    gap: 6px;
  }

  .app.has-daypanel .daytag {
    display: none;
  }

  .logo {
    font-size: 16px;
    letter-spacing: 0.5px;
  }

  .app.has-daypanel .logo {
    flex: 1 1 auto;
  }

  .btn {
    padding: 8px 10px;
    font-size: 10px;
    min-height: 36px;
  }

  #music-btn {
    min-width: 0;
    display: none;
  }

  /* ── Week strip ── */
  .weekmap {
    flex: 0 0 auto;
    order: 2;
    margin-bottom: 4px;
    padding: 4px 4px;
    cursor: default;
  }

  .app.week-collapsed .weekmap {
    cursor: pointer;
  }

  .app.week-collapsed:not(.week-expanded) .weekmap {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    margin-bottom: 4px;
    border-radius: 8px;
    background: rgba(26, 18, 8, 0.55);
    border: 1px solid rgba(201, 169, 79, 0.28);
  }

  .app.week-collapsed:not(.week-expanded) .chamber:not(.current) {
    display: none !important;
  }

  .app.week-collapsed:not(.week-expanded) .chamber.current {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
  }

  .app.week-collapsed:not(.week-expanded) .chamber.current .chamber-node {
    width: 24px;
    height: 24px;
  }

  .app.week-collapsed:not(.week-expanded) .chamber.current .chamber-label {
    font-size: 10px;
    letter-spacing: 0.4px;
  }

  .app.week-collapsed:not(.week-expanded) .weekmap::after {
    content: "▾";
    flex: 0 0 auto;
    margin-left: auto;
    font-size: 10px;
    color: rgba(201, 169, 79, 0.75);
    line-height: 1;
  }

  .app.week-collapsed.week-expanded .weekmap::after {
    content: "▴";
    flex: 1 1 100%;
    text-align: center;
    font-size: 10px;
    color: rgba(201, 169, 79, 0.75);
    margin-top: 2px;
    line-height: 1;
  }

  .app.week-collapsed.week-expanded .weekmap {
    cursor: pointer;
  }

  .chamber {
    padding: 2px 0;
    gap: 2px;
  }

  .chamber-node {
    width: 22px;
    height: 22px;
    font-size: 9px;
  }

  .chamber-label {
    font-size: 7px;
    letter-spacing: 0;
  }

  .chamber-note {
    display: none !important;
  }

  /* ── Day status chip ── */
  .daypanel[hidden] {
    display: none !important;
  }

  .daypanel {
    order: 3;
    flex: 0 0 auto;
    display: flex !important;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    margin: 0 0 4px;
    border-radius: 8px;
    min-height: 0;
  }

  .daypanel-day {
    font-size: 12px;
    flex: 0 0 auto;
    letter-spacing: 0.4px;
  }

  .daypanel-phase {
    flex: 0 1 auto;
    font-size: 10px;
    padding-bottom: 0;
    border-bottom: none;
    min-width: 0;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .daypanel-phase::before {
    content: "· ";
    opacity: 0.65;
  }

  .daypanel-time {
    flex: 0 0 auto;
    font-size: 11px;
    margin-left: 0;
    white-space: nowrap;
  }

  .daypanel-time[hidden] {
    display: none !important;
  }

  .daypanel-task {
    flex: 0 0 auto;
    margin-left: auto;
    margin-top: 0;
    padding: 3px 8px;
    font-size: 9px;
    letter-spacing: 0.35px;
    border-radius: 5px;
    white-space: nowrap;
  }

  .daypanel-task[hidden] {
    display: none !important;
  }

  /* ── Scene: scrollable hero ── */
  .stage {
    order: 4;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    width: 100%;
    align-self: stretch;
    position: relative;
  }

  .stage.can-scroll {
    box-shadow: inset 0 -18px 14px -10px rgba(14, 9, 4, 0.42);
  }

  .stage .card {
    min-height: 0;
    height: auto;
    max-height: none;
    padding: 16px 14px 20px;
    border-radius: 10px;
  }

  .scene-from,
  .speaker-label {
    font-size: 11px;
    margin: 4px 0 4px;
  }

  .scene-text {
    font-size: 17px;
    line-height: 1.48;
    margin-bottom: 10px;
  }

  .scene-text.dialogue {
    font-size: 17px;
  }

  .monk-ask {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 11px;
    margin-top: 10px;
  }

  .choices {
    gap: 10px;
    margin-top: 12px;
  }

  .choice,
  .continue-btn {
    min-height: 48px;
    padding: 12px 14px;
    font-size: 16px;
    line-height: 1.4;
  }

  /* ── Fixed desk dock (above scorecard) ── */
  .siderail {
    position: fixed;
    left: 10px;
    right: 10px;
    width: auto;
    bottom: calc(var(--meter-bar-h, 90px) + var(--meter-lift) + 6px);
    z-index: 28;
    margin: 0;
    order: unset;
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "phone book" "crew crew";
    gap: 5px;
    pointer-events: auto;
  }

  .siderail[hidden] {
    display: none !important;
  }

  .siderail .rail-title {
    display: none !important;
  }

  .siderail .widget-phone {
    grid-area: phone;
  }

  .siderail .widget-book {
    grid-area: book;
  }

  .siderail.solo-book {
    grid-template-columns: 1fr;
    grid-template-areas: "crew";
  }

  .siderail.solo-book .widget-book {
    display: none !important;
  }

  .siderail .widget {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    min-height: 40px;
    border-radius: 8px;
  }

  .siderail .widget-glyph {
    font-size: 16px;
  }

  .siderail .book-gauge {
    flex: 1 1 auto;
    max-width: 56px;
    height: 8px;
  }

  .siderail .widget-val {
    font-size: 10px;
  }

  .siderail .widget-val b {
    font-size: 11px;
  }

  /* Crew: horizontal scroll strip (beat .app.has-daypanel .rail-bonds column in styles.css) */
  .app.has-daypanel .siderail .rail-bonds {
    grid-area: crew;
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: stretch;
    gap: 6px;
    padding: 5px 6px;
    margin: 0;
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-height: 46px;
    min-height: 0;
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 20px), rgba(0, 0, 0, 0.35));
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 20px), rgba(0, 0, 0, 0.35));
  }

  .app.has-daypanel .siderail .rail-bonds::-webkit-scrollbar {
    display: none;
  }

  .app.has-daypanel .siderail .rail-bonds .rail-title {
    display: none !important;
  }

  .railbond-legend {
    display: none !important;
  }

  .app.has-daypanel .siderail .rail-bonds .railbond-row {
    flex: 0 0 88px !important;
    min-width: 88px;
    max-width: 88px;
    gap: 1px;
  }

  .railbond-name {
    font-size: 9px;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .railbond-val {
    font-size: 8px;
  }

  .railbond-tier {
    font-size: 7px;
    display: none;
  }

  .railbond-bar {
    height: 4px;
  }

  /* ── Fixed scorecard ── */
  .meters {
    position: fixed;
    z-index: 30;
    left: 10px;
    right: 10px;
    width: auto;
    transform: none;
    bottom: var(--meter-lift);
    padding: 9px 10px 11px;
    gap: 8px;
    align-items: center;
    border-radius: 10px;
    flex-wrap: wrap;
  }

  .meter-book {
    flex: 1 1 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 5px;
    margin-top: 1px;
    border-top: 1px solid rgba(201, 169, 79, 0.22);
  }

  .meter-book[hidden] {
    display: none !important;
  }

  .meter-book-label {
    flex: 0 0 auto;
    font-family: "Cinzel", serif;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.45px;
    text-transform: uppercase;
    color: rgba(232, 212, 168, 0.92);
  }

  .meter-book-track {
    flex: 1 1 auto;
    height: 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(201, 169, 79, 0.28);
    overflow: hidden;
  }

  .meter-book-fill {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    background: linear-gradient(90deg, #6b4e2a, #c9a94f);
  }

  .meter-book-pct {
    flex: 0 0 auto;
    font-family: "Cinzel", serif;
    font-size: 10px;
    font-weight: 700;
    color: #e8d4a8;
    min-width: 2.2em;
    text-align: right;
  }

  .player-portrait {
    width: 40px;
    flex: 0 0 40px;
    gap: 0;
  }

  .player-photo {
    width: 40px;
    height: 40px;
    border-radius: 7px;
  }

  .player-name {
    display: none;
  }

  .meters-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, auto);
    gap: 6px 10px;
    align-content: center;
  }

  .meter-top {
    flex-direction: row;
    justify-content: space-between;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 3px;
  }

  .meter-name {
    font-size: 9px;
    letter-spacing: 0.35px;
  }

  .meter-num {
    font-size: 16px;
  }

  .bar {
    height: 7px;
  }

  /* ── Prologue / intro ── */
  .app.prologue {
    height: 100svh;
    max-height: 100svh;
    max-width: none;
    width: 100%;
    padding: max(8px, env(safe-area-inset-top, 8px)) 12px 0;
    overflow: hidden;
  }

  .app.prologue .stage {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--meter-bar-h) + var(--meter-lift) + var(--meter-gap));
  }

  .app.prologue .card {
    width: 100%;
    min-height: 0;
    max-height: none;
    padding: 18px 16px 22px;
    overflow: visible;
  }

  .app.prologue .intro-eg-grid,
  .app.prologue .eg-grid,
  .eg-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .app.prologue .intro-eg-grid .eg-check,
  .app.prologue .intro-eg-grid.intro-eg-single .eg-check,
  .app.prologue .intro-eg-grid.intro-eg-all .eg-check,
  .app.prologue .intro-eg-grid.intro-eg-triple .eg-check,
  .app.prologue .intro-eg-grid.intro-eg-triple .eg-tile[data-eg="trip"] .eg-check,
  .intro-board-wrap .eg-check {
    display: flex !important;
    flex-direction: column !important;
    grid-template-columns: unset !important;
    gap: 0 !important;
  }

  .app.prologue .intro-eg-grid .eg-check li,
  .intro-board-wrap .eg-check li {
    font-size: 14px;
    line-height: 1.38;
    padding: 3px 0;
  }

  .app.prologue .intro-eg-grid .eg-tile,
  .app.prologue .eg-tile,
  .eg-tile {
    min-height: 0;
    padding: 14px 12px;
  }

  .app.prologue .scene-text {
    font-size: 17px;
  }

  .app.prologue .continue-btn,
  .app.prologue .choice {
    min-height: 48px;
    font-size: 16px;
    padding: 12px 16px;
  }

  .app.prologue .monk-avatar {
    width: 72px;
    height: 72px;
  }

  .app.prologue-no-meters {
    padding-bottom: 16px;
  }

  .app.prologue-no-meters .stage {
    padding-bottom: 16px;
  }

  .app.prologue-no-meters .meters {
    display: none;
  }

  .app.prologue.prologue-no-meters .stage {
    padding-bottom: 16px;
  }

  /* ── Mode select / start ── */
  .app.prologue-no-meters:not(.prologue) .logo {
    display: none;
  }

  .app.prologue-no-meters:not(.prologue) .daytag {
    flex: 1 1 auto;
    min-width: 0;
  }

  .app.prologue-no-meters:not(.prologue) .topbar {
    margin-bottom: 8px;
  }
  .app:not(.has-daypanel):not(.prologue) {
    overflow-y: auto;
    max-height: none;
    height: auto;
    min-height: 100svh;
    padding: max(8px, env(safe-area-inset-top, 8px)) 12px 24px;
  }

  .app:not(.has-daypanel):not(.prologue) .stage {
    flex: 1 0 auto;
    width: 100%;
  }

  .app:not(.has-daypanel):not(.prologue) .meters {
    display: none;
  }

  .start-box {
    padding: 20px 16px 24px;
    width: 100%;
  }

  .start-title {
    font-size: 26px;
    margin-bottom: 6px;
  }

  .start-sub {
    font-size: 15px;
    margin-bottom: 18px;
  }

  .mode-picker {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mode-card {
    padding: 16px 14px;
    width: 100%;
  }

  .mode-name {
    font-size: 16px;
  }

  .mode-desc {
    font-size: 14px;
  }

  .mode-goal {
    font-size: 11px;
  }

  /* ── Modals ── */
  .monk-modal-inner,
  .sinder-inner {
    width: calc(100vw - 20px);
    max-width: none;
    margin: 10px;
    padding: 18px 16px;
  }

  .monk-modal-avatar {
    width: 58px;
    height: 58px;
  }

  .sinder-inner .choice {
    font-size: 15px;
    min-height: 46px;
  }

  /* ── Kill legacy 560px leaks inside mobile range ── */
  .app.has-daypanel .siderail {
    position: fixed;
  }
}

@media (max-width: 700px) and (orientation: landscape) and (max-height: 500px) {
  .app.has-daypanel {
    padding-top: max(4px, env(safe-area-inset-top, 4px));
  }

  .topbar {
    margin-bottom: 2px;
  }

  .weekmap,
  .app.week-collapsed:not(.week-expanded) .weekmap {
    margin-bottom: 2px;
    padding: 2px 6px;
  }

  .daypanel {
    padding: 4px 8px;
    margin-bottom: 2px;
  }

  .stage .card {
    padding: 12px 12px 16px;
  }

  .choice,
  .continue-btn {
    min-height: 42px;
    padding: 10px 12px;
    font-size: 15px;
  }

  .meters {
    padding: 6px 8px 8px;
  }

  .player-photo {
    width: 34px;
    height: 34px;
  }

  .player-portrait {
    width: 34px;
    flex: 0 0 34px;
  }
}

@media (max-width: 400px) {
  .chamber-label {
    display: none;
  }

  .chamber-node {
    width: 20px;
    height: 20px;
  }
}
