/* Phone/tablet layout layer. Desktop rules and simulator state remain unchanged. */
@media (max-width: 1100px), (pointer: coarse) and (max-width: 1366px) {
  html, body { font-size: 16px; }
  #svelte main { width: 100%; height: 100dvh; --screen-height: 100dvh !important; }
  #svelte .mobile, #svelte .mobile button { font-size: 1rem; }
  #svelte button, #svelte a { touch-action: manipulation; }
  #svelte input, #svelte select, #svelte textarea { font-size: 16px; }
  #svelte .close, #svelte .close-x { width: 44px; height: 44px; flex-shrink: 0; }
  #svelte .uid { right: max(12px, env(safe-area-inset-right)); bottom: env(safe-area-inset-bottom); font-size: 10px; }

  /* Keep the game shell in normal vertical flow in either orientation. */
  #svelte main > section:has(> .col.top) {
    display: flex; flex-direction: column; justify-content: flex-start;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) max(18px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
  }
  #svelte main > section > .col.top { width: 100%; height: auto; min-height: 0; flex: 0 0 auto; }
  #svelte main > section > .col.banner { width: 100%; height: auto; min-height: 0; margin: 0; flex: 1; }
  #svelte .col.banner > .item { min-height: 0; flex: 1; }
  #svelte .col.banner > .col.button { height: auto; flex: 0 0 auto; margin: 0; }
  #svelte #header { height: auto !important; padding: 10px 16px !important; }
  #svelte #header > .top { position: relative; inset: auto; width: 100%; padding: 0; align-items: center; gap: 8px; }
  #svelte #header .identity { flex-shrink: 1; min-width: 0; }
  #svelte #header .wish-title img { display: block; width: 28px; margin-right: 8px; }
  #svelte #header .wish-title button { width: 44px; height: 44px; margin-left: 4px; transform: none; }
  #svelte #header .help { border-width: 1px; }
  #svelte #header .site-icons { gap: 0; margin-left: 6px; }
  #svelte #header .site-icons a { width: 36px; height: 44px; padding: 8px; }
  #svelte #header .finance-lens { width: auto; height: 44px; padding: 6px 10px; margin-right: 6px; font-size: 13px; }
  #svelte #header .finance-lens .lens-label { display: inline; }
  #svelte #header .banner-button { position: relative; inset: auto; max-width: 100%; transform: none; margin: 6px 0 0; }
  #svelte #header .banner-button .bg { display: none; }
  #svelte #header .button-wrapper { width: 100%; height: auto; padding: 0; margin: 0; flex-direction: row; flex-wrap: nowrap !important; justify-content: center; overflow-x: auto; overflow-y: hidden; }
  #svelte #header .button-wrapper > button { flex-shrink: 0; }
  #svelte .banner-container { padding: 0 12px; align-items: center; }
  #svelte .banner-item { width: min(90%, 900px); max-width: 100% !important; max-height: 100%; }
  #svelte .banner-container .navigate { display: flex; width: 100%; padding: 0 4px; }
  #svelte .banner-container .navigate button { width: 44px; height: 44px; }
  #svelte #footer .row { padding: 8px 16px; gap: 10px; align-items: center; }
  #svelte #footer .menu-button { padding: 0; display: flex; white-space: normal; gap: 6px; }
  #svelte #footer .menu-button button { min-height: 44px; margin: 0; padding: 6px 14px; font-size: 14px; }
  #svelte #footer .roll-button { display: flex; justify-content: flex-end; margin: 0 !important; gap: 6px; white-space: normal; }
  #svelte #footer .roll-button button { min-height: 48px; width: 175px; flex: 0 0 175px; margin: 0; font-size: 14px; padding: 2px 10px; transition: filter 160ms, transform 160ms; }
  #svelte #footer .footer-info { bottom: 100%; left: 16px; }

  /* Menus: fixed header, full-width scrolling content and reachable close button. */
  #svelte main > section:has(> .head) { display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) max(18px, env(safe-area-inset-bottom)) env(safe-area-inset-left); }
  #svelte main > section > .head { flex-shrink: 0; align-items: center; margin: 8px 16px; }
  #svelte main > section > .head > .close { margin: 0; }
  #svelte main > section > .head + .container { flex: 1; min-height: 0; height: auto; flex-direction: column; margin: 0 12px; }
  #svelte .head + .container > .sidebar { width: 100%; max-width: none; flex-shrink: 0; }
  #svelte .head + .container .menu-list { display: flex; flex-direction: row; justify-content: flex-start; }
  #svelte .head + .container .menu-item button { min-height: 44px; font-size: 15px; padding: 8px 20px; }
  #svelte .head + .container .menu-item.active::after { display: none; }
  #svelte .head + .container .menu-item.active button { background: #f7f3d8; color: #4a5265; border-radius: 24px; }
  #svelte .head + .container > .content { width: 100%; max-width: none; height: auto; flex: 1; min-height: 0; margin-top: 8px; overflow-y: auto; }
  #svelte .head + .container .rotate { display: none; }
  #svelte .finance-panel { font-size: 14px; }
  #svelte .finance-panel :is(p, small, .label, .status, .progress, .step-track span, .flow-audit, .totals-grid span, .gi-btn, .desk-tabs button) { font-size: 14px; }
  #svelte .finance-panel button, #svelte .workbench button { min-height: 44px; }
  #svelte .finance-panel :is(.gi-card header, .workbench-head, .quiz-footer) { flex-wrap: wrap; gap: 8px; }
  #svelte .finance-panel :is(.gi-card, .controls > *, .policy-grid > *) { min-width: 0; }
  #svelte .finance-panel :is(strong, .large, .equation) { overflow-wrap: anywhere; }

  /* Constrain both standard and custom/blank dialogs to the visible screen. */
  #svelte .modal { height: 100dvh; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  #svelte .modal-content { max-width: 100%; max-height: 100%; display: flex; flex-direction: column; }
  #svelte .modal-content > .container { height: auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  #svelte .modal-content .pop-body { height: auto; max-height: calc(100dvh - 190px); font-size: 16px; }
  #svelte .modal-content.finance-wide .pop-body { height: calc(100dvh - 190px); max-height: calc(100dvh - 190px); }
  #svelte .pop-footer { gap: 8px; padding: 10px 8px; }
  #svelte .pop-footer button { min-height: 44px; max-width: 48%; }
  #svelte .genesis-modal .title { line-height: 1.4; font-size: 20px; }
  #svelte .genesis-modal :is(.payment-type, .channel-result) { font-size: 14px; }
  #svelte .genesis-modal :is(small, .channel-item strong, .invoice-choice strong) { font-size: 13px; }
  #svelte .genesis-modal .channel-item { min-height: 70px; }
  #svelte .finance-result { min-height: 0; max-height: none; overflow: visible; justify-content: flex-start; padding: 20px 12px; }
  #svelte .finance-result :is(p, small, .finance-amounts div, .alternate-path) { font-size: 14px; }
  #svelte .result-confirm { min-height: 44px; }
  #svelte .insight-modal { padding: 12px; }
  #svelte .insight-modal .hero { grid-template-columns: auto minmax(0, 1fr) auto; }
  #svelte .insight-modal :is(p, small, .reason strong, .metric-grid span, .model-strip strong) { font-size: 13px; }
  #svelte .journal, #svelte .journal :is(small, .entry-title, .boundary) { font-size: 13px; }
  #svelte .journal .line { grid-template-columns: 24px minmax(0, 1fr) auto; }
  #svelte .journal .line strong { grid-column: auto; }
  #svelte .items-container { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  #svelte .items-container .item-header { flex: 0 0 auto; min-height: 64px; height: auto; }
  #svelte .items-container .item-body { flex: 1; min-height: 0; height: auto; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  #svelte .item-body .item-list { height: auto; overflow: visible; }
  #svelte .item-body .column { min-width: 0; min-height: 0; }
  #svelte .welcome-veil { overflow-y: auto; overscroll-behavior: contain; padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  #svelte .welcome-stage { flex-shrink: 0; margin-block: auto; }
  #svelte .welcome-veil button { min-height: 44px; }
}

@media (max-width: 600px) {
  #svelte #header { padding: 6px 12px !important; }
  #svelte #header > .top { flex-wrap: wrap; gap: 4px; }
  #svelte #header .identity { width: 100%; justify-content: space-between; }
  #svelte #header .wish-title { font-size: 15px; }
  #svelte #header .wish-title img { width: 24px; }
  #svelte #header .wish-title button { width: 36px; height: 40px; }
  #svelte #header .site-icons { margin: 0; }
  #svelte #header .site-icons a { width: 32px; height: 40px; padding: 7px; }
  #svelte #header .budget { width: 100%; justify-content: space-between; }
  #svelte #header .finance-lens { height: 44px; font-size: 12px; padding: 5px 8px; }
  #svelte #header .fates { display: flex; flex-wrap: wrap; justify-content: flex-end; }
  #svelte #header .fates button { min-height: 40px; font-size: 14px; }
  #svelte #header .finance-guide { left: 0; right: auto; transform: scale(.9); transform-origin: top left; }
  #svelte #header .button-wrapper { justify-content: flex-start; }
  #svelte #header .button-wrapper > button { width: 64px; margin-inline: 2px; min-height: 44px; }
  #svelte #footer .row { flex-direction: column; padding: 6px 12px; gap: 8px; }
  #svelte #footer .menu-button { width: 100%; }
  #svelte #footer .menu-button button { flex: 1; padding: 6px; }
  #svelte #footer .roll-button { width: 100%; }
  #svelte #footer .roll-button button { flex: 1; width: 0; background-size: 100% 100%; }
  #svelte #footer .footer-info { bottom: 100%; flex-direction: row; }
  #svelte .banner-item { width: 100%; }
  #svelte .finance-content { padding: 8px !important; }
  #svelte .finance-panel .gi-card { padding: 12px; }
  #svelte .finance-panel :is(.quiz-options, .rhythm-grid, .tool-row, .policy-grid, .controls, .model-details ol) { grid-template-columns: minmax(0, 1fr) !important; }
  #svelte .finance-panel .totals-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #svelte .desk-tabs { gap: 8px; }
  #svelte .insight-modal .content-grid, #svelte .finance-amounts { grid-template-columns: minmax(0, 1fr); }
  #svelte .insight-modal .hero { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  #svelte .insight-modal .hero-mark { display: none; }
  #svelte .insight-modal .evidence { display: none; }
  #svelte .insight-modal .metric-grid { grid-template-columns: minmax(0, 1fr); }
  #svelte .journal .line { grid-template-columns: 24px minmax(0, 1fr); }
  #svelte .journal .line strong { grid-column: 2; }
  #svelte .genesis-modal .payment-type { padding: 12px; }
  #svelte .genesis-modal .list { flex-wrap: wrap; gap: 6px; }
  #svelte .genesis-modal .channel-item { width: 100%; margin: 0; }
  #svelte .genesis-modal .invoice-choice { grid-template-columns: minmax(0, 1fr); margin: 6px 12px; }
  #svelte .genesis-modal .channel-result { margin: 6px 12px; }
  #svelte .genesis-modal .channel-result p { flex-wrap: wrap; gap: 4px; }
  #svelte .items-container .item-header { min-height: 104px; align-items: flex-start; gap: 4px; padding: 6px 0; }
  #svelte .items-container .item-header .info { padding-right: 48px; }
  #svelte .items-container .item-header .fates { margin: 0; flex-wrap: wrap; }
  #svelte .items-container .item-header .close { top: 6px; }
  #svelte .adventure-file .inner-frame { padding: 18px 14px; }
  #svelte .welcome-stage { padding-top: 90px; }
  #svelte .welcome-veil .message { font-size: 15px; }
}

@media (max-height: 500px) and (max-width: 1100px) and (orientation: landscape) {
  #svelte #header { padding-block: 2px !important; }
  #svelte #header .site-icons { display: none; }
  #svelte #header .banner-button { margin: 0; }
  #svelte #header .button-wrapper > button { width: 64px; margin-block: 0; }
  #svelte #header .finance-guide { display: none; }
  #svelte .banner-item { width: min(65%, calc((100dvh - 170px) * 1.93)); }
  #svelte #footer .row { padding-block: 2px; }
  #svelte #footer .footer-info { display: none; }
  #svelte .welcome-veil { display: block; }
  #svelte .welcome-stage { margin: 0 auto; }
  #svelte .adventure-file .inner-frame { padding: 16px 24px; }
}

@media (max-width: 1100px), (pointer: coarse) and (max-width: 1366px) {
  #svelte .summary :is(p, small, .totals span, .compare-grid, .compare-grid .head, .model-flow strong, .tax-grid strong) { font-size: 13px; }
  #svelte .summary .section-heading { flex-wrap: wrap; gap: 6px; }
  #svelte .case-list button { min-height: 64px; }
  #svelte .modal-content .container:has(> .genesis-modal) { -webkit-overflow-scrolling: touch; }
  #svelte .navbar { flex-shrink: 0; overflow-y: auto; max-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 600px) {
  #svelte #footer .roll-button button { height: 52px; aspect-ratio: auto; }
  #svelte .summary .totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #svelte .summary :is(.tax-grid, .model-flow) { grid-template-columns: minmax(0, 1fr); }
  #svelte .summary .model-flow div::after { display: none; }
  #svelte .summary .compare-grid { grid-template-columns: 1.2fr 1fr 1fr; gap: 8px 4px; overflow-wrap: anywhere; }
}
@media (max-width: 360px) {
  #svelte #header .wish-title img { display: none; }
  #svelte #header .site-icons a { width: 30px; }
  #svelte #header .finance-lens { padding: 5px; gap: 4px; }
  #svelte #header .fates button { margin-inline: 2px; padding-inline: 4px; }
}

/* The history book becomes a readable sheet; wide records scroll inside it. */
@media (max-width: 700px) {
  #svelte .content-details.v2 { padding: 16px 12px 54px !important; align-items: flex-start; }
  #svelte .content-details.v2 .content-container { width: 100%; min-width: 0; height: calc(100dvh - 82px) !important; }
  #svelte .content-details.v2 .book { width: 100%; height: 100% !important; aspect-ratio: auto; padding: 14px; background: #f3eddf; border: 2px solid #d2c69c; border-radius: 8px; }
  #svelte .content-details.v2 .book-content { height: 100%; min-height: 0; }
  #svelte .content-details.v2 .book-content > .container { min-height: 0; flex: 1; }
  #svelte .content-details.v2 h1 { font-size: 20px; padding-right: 44px; }
  #svelte .content-details.v2 .tutup { width: 44px; height: 44px; top: 4px; right: 4px; color: #4a5265; }
  #svelte .content-details.v2 .tutup::after { content: '×'; font-size: 28px; }
  #svelte .content-details.v2 .old { bottom: -42px; transform: translateX(-50%); min-height: 44px; white-space: nowrap; }
  #svelte .content-details.v2 :is(p, .legend, .selectType, .selected, .select-list button, .report, .pagination, .table) { font-size: 14px; }
  #svelte .content-details.v2 .selectType { display: flex; flex-wrap: wrap; gap: 6px; }
  #svelte .content-details.v2 .selected { min-height: 44px; line-height: 1.4; }
  #svelte .content-details.v2 .table { overflow-x: auto; }
  #svelte .content-details.v2 .table .row { min-width: 550px; min-height: 44px; }
  #svelte .content-details.v2 .table .cell { font-size: 13px; }
  #svelte .content-details.v2 .pagination button { min-width: 44px; min-height: 44px; }
}
@media (max-width: 700px) {
  #svelte .content-details.v2 .tutup { z-index: 5; }
}
@media (max-width: 1100px), (pointer: coarse) and (max-width: 1366px) {
  #svelte #inventory .header { position: relative; width: 100%; inset: auto; align-items: center; gap: 8px; padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
  #svelte #inventory .header .close { margin: 0; }
  #svelte #inventory .budget { flex-wrap: wrap; gap: 4px; }
  #svelte #inventory .budget button { min-height: 36px; margin: 0; }
}
@media (max-width: 1100px), (pointer: coarse) and (max-width: 1366px) {
  #svelte #footer .menu-button button, #svelte #header button { transition-property: background-color, color, filter, transform; }
}
