/* Shared surfaces for mobile dialogs and auxiliary pages. */
.exchange-tier-balance { display: none; }

@media (max-width: 760px), (pointer: coarse) {
  body { isolation: isolate; background: #10232f; }
  body:before {
    content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
    background: radial-gradient(ellipse at 0% 12%, #35677966, transparent 65%),
      radial-gradient(ellipse at 100% 88%, #947d4524, transparent 60%),
      linear-gradient(160deg, #183846, #112a38 48%, #0c1b28);
    filter: none;
  }
  body:after { content: none; }
  :root {
    color-scheme: dark;
    --ql-surface: #172f3e;
    --ql-raised: #223d4c;
    --ql-field: #102733;
    --ql-line: #3b5968;
    --ql-text: #d5e3e9;
    --ql-muted: #9cb8c6;
    --ql-gold: #ddbf7d;
    --panel: var(--ql-surface);
    --soft: var(--ql-raised);
    --line: var(--ql-line);
    --text: var(--ql-text);
    --muted: var(--ql-muted);
    --accent: var(--ql-gold);
    --accent-strong: #eccf90;
    --accent-soft: #30434a;
    --surface-cool: #243f4e;
  }
  #selectionDialog, #exchangeDialog, #targetDialog, #confirmDialog,
  #purchaseDialog, #rulesDialog, #eventDialog, #expenseDialog, #milestoneDialog {
    background: var(--ql-surface); color: var(--ql-text);
    border: 1px solid var(--ql-line); border-radius: 12px; padding: 12px;
  }
  dialog::backdrop { background: #05111cb3; }
  :root dialog > .dialog-heading, .progress-editor-actions {
    background: var(--ql-surface); position: sticky; top: -12px; z-index: 8;
  }
  :root dialog > .dialog-heading { min-height: 40px; padding: 2px 0 8px; margin-bottom: 6px; }
  :root dialog > .dialog-heading h2 { color: var(--ql-gold); font: 600 16px/24px var(--qinglong-font); }
  :root dialog .close, #exchangeDialog .close {
    position: relative; top: auto; right: auto; width: 40px; height: 40px;
    min-height: 40px; color: #c3d7e0; background: var(--ql-raised); flex-shrink: 0;
  }
  dialog .close:hover:enabled { background: #2b4a5b; color: #fff; }
  dialog .subtle, dialog .target-note, dialog .target-result > p,
  dialog .target-start label, dialog .target-form label,
  dialog .target-start legend, dialog .target-note,
  :root dialog summary, .mobile-panel .analysis-note, .mobile-panel .subtle {
    color: var(--ql-muted);
  }
  :root dialog input:not([type=checkbox]):not([type=radio]), :root dialog select,
  #simulationTools select {
    background: var(--ql-field); color: var(--ql-text); border-color: var(--ql-line);
  }
  dialog input:focus-visible, dialog select:focus-visible { background: var(--ql-field); outline-color: var(--ql-gold); }
  :root dialog button:where(:not(.close):not(.gold-button):not(.select-item):not(.exchange-prize):not(.result-confirm)),
  .mobile-panel #simulationTools #settleButton {
    color: var(--ql-text); background: var(--ql-raised); border-color: var(--ql-line);
  }
  dialog .gold-button, dialog .target-actions button {
    color: #342915; background: #d7b46b; border-color: #c7a25d;
  }
  dialog .gold-button:hover:enabled, dialog .target-actions button:hover:enabled { background: #e3c785; }
  :root dialog button:where(:not(.close):not(.gold-button):not(.select-item):not(.exchange-prize):not(.result-confirm)):hover:enabled { background: #2b4a5b; }
  :root dialog button[aria-pressed=true]:hover:enabled { background: #40534f; color: var(--ql-gold); }
  dialog button:disabled { opacity: .5; }
  dialog .target-presets button[aria-pressed=true], dialog .tier-tabs button[aria-pressed=true],
  dialog .event-tabs button[aria-pressed=true] { background: #344c52; border-color: #ae955c; color: #efd396; }
  #targetProgress, .progress-compact, dialog .event-card,
  dialog .strategy-choice, .mobile-panel .expense-overview,
  .mobile-panel #simulationTools .panel, .mobile-panel #simulationTools .estimate-grid {
    background: var(--ql-raised); border-color: var(--ql-line); color: var(--ql-text);
  }
  dialog .progress-compact strong, dialog .target-details b,
  .mobile-panel #simulationTools h2 { color: var(--ql-text); }
  dialog .progress-compact span, dialog .target-details span,
  dialog .event-card small, dialog .strategy-choice small { color: var(--ql-muted); }
  .progress-editor-actions { top: auto; bottom: -12px; }
  dialog .progress-error { color: #f0b19b; }
  dialog .target-start, dialog .target-guide, dialog .target-alternatives,
  dialog .target-details > div { border-color: var(--ql-line); }
  dialog .target-recommendation { background: #263c43; border-color: #9d8858; }
  dialog .plan-tag, dialog .event-badge { color: #ecd197; background: #435049; }
  dialog .plan-summary h3, dialog .plan-price strong, dialog .plan-price span,
  dialog .target-reference h3 { color: var(--ql-gold); }
  dialog .plan-summary p, dialog .plan-summary .plan-requirement,
  dialog .target-recommendation .plan-instruction { color: #bdced1; }
  dialog .target-path li { background: #1a333f; border-color: #57717a; }
  dialog .target-path .key-step { background: #354348; border-color: #ae955c; }
  dialog .target-path .step-mobile-round, dialog .step-round { color: #d3e3e8; }
  dialog .target-path .key-step .step-mobile-round, dialog .key-step .step-round { color: var(--ql-gold); }
  dialog .step-pool, dialog .step-prefix, dialog .step-spent,
  dialog .step-total, dialog .step-mobile-start { color: var(--ql-muted); }
  dialog .step-action, dialog .target-path li:last-child .step-action { color: var(--ql-muted); background: #213c49; border-color: var(--ql-line); }
  dialog .mobile-path-details, dialog .target-path-details li { border-color: #596661; }
  dialog .mobile-path-details summary { color: var(--ql-muted); }
  dialog .target-result tr.chosen-plan { background: var(--ql-raised); }
  dialog .select-item { background: var(--ql-raised); color: var(--ql-text); border-color: var(--ql-line); }
  dialog .select-item[aria-pressed=true] { background: #374746; border-color: #bc9e5e; }
  dialog .select-item[aria-pressed=true]:after { border-color: #e9c883; }
  dialog .select-item:hover:enabled, dialog .exchange-prize:hover:enabled { background: #2c4958; border-color: #708895; }
  dialog .select-item[aria-pressed=true]:hover:enabled { background: #40534f; border-color: #d3b775; }
  .mobile-panel #simulationTools .metrics { color: var(--ql-muted); }
  .mobile-panel #simulationTools .metrics strong, .mobile-panel .expense-overview strong { color: var(--ql-gold); }

  /* These nodes move out of the expense dialog on phones. Theme the owner,
     including its local variables, so both presentations stay consistent. */
  :root #simulationTools {
    --text: var(--ql-text); --muted: var(--ql-muted); --panel: var(--ql-raised);
    --soft: var(--ql-field); --line: var(--ql-line); --accent: var(--ql-gold);
    color: var(--ql-text);
  }
  :root #simulationTools .metrics, :root #simulationTools .panel,
  :root #simulationTools .estimate-grid {
    background: var(--ql-raised); color: var(--ql-text); border-color: var(--ql-line);
  }
  :root #simulationTools .metrics label, :root #simulationTools .subtle,
  :root #simulationTools .analysis-note, :root #simulationTools .section-heading > span,
  :root #simulationTools .analysis-assumptions summary { color: var(--ql-muted); }
  :root #simulationTools h2 { color: var(--ql-text); }
  :root #simulationTools .metrics strong, :root #simulationTools .estimate-grid strong { color: var(--ql-gold); }
  :root #simulationTools select { background: var(--ql-field); color: var(--ql-text); border-color: var(--ql-line); border-radius: 7px; }
  :root #simulationTools #settleButton { background: var(--ql-field); color: var(--ql-text); border-color: var(--ql-line); border-radius: 7px; }
  :root #simulationTools #analysisButton { background: #d7b46b; color: #342915; border-color: #c7a25d; border-radius: 7px; font-weight: 600; }
  :root #simulationTools #analysisButton:hover:enabled { background: #e3c785; color: #342915; }
  :root #simulationTools #settleButton:hover:enabled { background: #2b4a5b; }
  :root #simulationTools #exportButton { color: var(--ql-gold); background: transparent; border: 0; }
  :root #simulationTools .analysis-assumptions { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--ql-line); font-size: 11px; line-height: 18px; }
  :root #simulationTools .analysis-assumptions summary { cursor: pointer; min-height: 28px; }
  :root #simulationTools .analysis-assumptions .analysis-note { margin: 4px 0 0; }

  #resultDialog { width: min(380px, 80vw); height: fit-content; aspect-ratio: auto; max-height: calc(100dvh - 48px); margin: auto; inset: 0; transform: none; padding: 12px; border: 1px solid #ae955c; border-radius: 12px; background: var(--ql-surface); color: var(--ql-text); overflow: auto; }
  #resultDialog .result-art { display: none; }
  #resultDialog .mobile-result-heading { display: flex; position: static; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
  #resultDialog .mobile-result-heading h2 { margin: 0; color: var(--ql-gold); font: 600 16px/24px var(--qinglong-font); }
  #resultDialog .mobile-result-heading .close { position: relative; right: auto; top: auto; }
  #resultDialog .result-rewards { position: static; display: flex; flex-wrap: wrap; justify-content: center; transform: none; gap: 12px; padding: 0; max-height: calc(100dvh - 200px); overflow: auto; color: var(--ql-text); }
  #resultDialog .result-rewards > div { width: 100px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
  #resultDialog .result-rewards img { width: 44px; height: 44px; }
  #resultDialog .result-rewards p { margin: 0; font: 11px/16px var(--qinglong-font); }
  #resultDialog .egg-caption { position: static; transform: none; order: 2; color: var(--ql-gold); background: var(--ql-raised); font: 9px/14px var(--qinglong-font); }
  #resultDialog .result-confirm { position: static; width: 100%; height: 40px; margin-top: 14px; min-height: 40px; border: 0; border-radius: 6px; background: #d7b46b!important; color: #342915; font: 600 12px var(--qinglong-font); }
  #resultDialog .result-confirm .mobile-only { display: inline; }
  #resultDialog.batch-result .result-rewards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #resultDialog.batch-result .result-rewards > div { width: auto; }

  #exchangeDialog { width: min(600px, 80vw); max-height: calc(100dvh - 48px); min-height: 0; overflow: hidden; }
  #exchangeDialog[open] { display: flex; flex-direction: column; }
  #exchangeDialog:before { content: none; }
  #exchangeDialog .dialog-heading { position: relative; top: auto; flex-shrink: 0; gap: 6px; margin: 0; }
  #exchangeDialog .dialog-heading h2 { display: block; margin: 0; flex: 1; font-size: 15px; white-space: nowrap; }
  #exchangeDialog .dialog-back { display: block; min-height: 40px; padding: 4px; border: 0; background: transparent; font-size: 12px; color: var(--ql-muted); }
  .exchange-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  #exchangeDialog .exchange-body > .subtle { margin: 8px 0; font-size: 11px; line-height: 18px; }
  #exchangeDialog .exchange-emphasis { color: var(--ql-gold); }
  .exchange-pool-tabs { gap: 5px; margin: 4px 0 8px; overflow-x: auto; }
  .exchange-pool-tabs button { flex: 0 0 auto; min-width: 54px; padding: 5px 8px; border-radius: 5px; font-size: 11px; white-space: nowrap; }
  .exchange-pool-tabs button:disabled { display: none; }
  #exchangeDialog .exchange-pool-tabs button[aria-pressed=true] { background: #344c52; color: #efd396; border-color: #ae955c; }
  #exchangeDialog .exchange-tier-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin: 12px 0 10px; }
  .exchange-tier-tabs button { display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 48px; padding: 6px 2px; border-radius: 6px; }
  .exchange-tier-tabs strong { font-size: 12px; font-weight: 500; }
  .exchange-tier-tabs small { color: var(--ql-muted); font-size: 10px; }
  #exchangeDialog .exchange-tier-tabs button[aria-pressed=true] { background: #344c52; border-color: #ae955c; color: var(--ql-gold); }
  #exchangeDialog .exchange-tier-row { display: none; margin: 0; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  #exchangeDialog .exchange-tier-row[data-active=true] { display: grid; }
  #exchangeDialog .exchange-tier-label { display: none; }
  #exchangeDialog .exchange-prize { min-width: 0; min-height: 110px; padding: 8px 3px; border: 1px solid var(--ql-line); border-radius: 7px; background: var(--ql-raised); color: var(--ql-text); }
  #exchangeDialog .exchange-prize img { width: 36px; height: 36px; flex-shrink: 0; }
  #exchangeDialog .exchange-prize p { font-size: 10px; line-height: 15px; flex: 1; margin: 6px 0 3px; overflow-wrap: anywhere; }
  #exchangeDialog .exchange-prize small { font-size: 9px; color: var(--ql-muted); }
  #exchangeDialog .exchange-prize:disabled { opacity: 1; color: #7894a1; background: #192f3b; }
  #exchangeDialog .exchange-prize:disabled img { filter: grayscale(1); opacity: .4; }
  #exchangeDialog .exchange-prize[aria-pressed=true] { background: #364743; border-color: #c3a465; }
  #exchangeDialog .exchange-action { grid-column: 1/-1; display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; align-items: center; margin-top: 4px; }
  #exchangeDialog .exchange-action > span, #exchangeDialog .exchange-action small { align-self: auto; justify-self: start; margin: 0; color: var(--ql-muted); font-size: 10px; }
  #exchangeDialog .exchange-action .insufficient { color: #deb497; }
  #exchangeDialog .exchange-action button { grid-column: 2; grid-row: 1/3; margin: 0; min-height: 40px; padding: 6px 16px; border-radius: 6px; color: #342915; background: #d7b46b; border-color: #c7a25d; }
  #exchangeDialog .simulation-cards { margin-top: 14px; padding-top: 8px; border-top: 1px solid var(--ql-line); font-size: 11px; }
  #exchangeDialog .simulation-cards p { font-size: 11px; color: var(--ql-muted); line-height: 18px; }
  #exchangeDialog #addCards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  #exchangeDialog #addCards button { min-height: 38px; padding: 5px; font-size: 11px; border-radius: 5px; }
  #exchangeDialog .exchange-footer { display: block; flex-shrink: 0; padding-top: 12px; }
  .exchange-footer button { width: 100%; min-height: 40px; border-radius: 6px; font-size: 12px; }
}

@media (max-width: 760px) {
  :root .mobile-panel .expense-overview { padding: 12px 14px; margin-bottom: 10px; }
  :root .mobile-panel #simulationTools .metrics { padding: 14px; gap: 12px 14px; border: 1px solid var(--ql-line); }
  :root .mobile-panel #simulationTools .metrics > div { border: 0; min-width: 0; gap: 4px; }
  :root .mobile-panel #simulationTools .metrics > div:nth-child(-n+2) { padding-bottom: 10px; border-bottom: 1px solid var(--ql-line); }
  :root .mobile-panel #simulationTools .metrics > div:nth-child(3) { grid-column: 1/-1; }
  :root .mobile-panel #simulationTools .metrics > div:nth-child(3) label { flex-direction: row; align-items: center; gap: 12px; }
  :root .mobile-panel #simulationTools .metrics select { flex: 1; min-width: 0; min-height: 40px; }
  :root .mobile-panel #simulationTools .metrics > div:last-child { grid-column: 1/-1; }
  :root .mobile-panel #simulationTools #settleButton { min-height: 40px; }
  :root .mobile-panel #simulationTools .panel { padding: 14px; }
  :root .mobile-panel #simulationTools .section-heading { gap: 8px; }
  :root .mobile-panel #simulationTools h2 { font-size: 15px; margin: 0; }
  :root .mobile-panel #simulationTools .subtle { font-size: 12px; line-height: 19px; margin: 8px 0 12px; }
  :root .mobile-panel #simulationTools .analysis-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
  :root .mobile-panel #simulationTools .analysis-controls label { display: flex; flex-direction: column; gap: 5px; min-width: 0; color: var(--ql-muted); font-size: 11px; }
  :root .mobile-panel #simulationTools .analysis-controls select { width: 100%; min-height: 40px; }
  :root .mobile-panel #simulationTools #analysisButton { grid-column: 1/-1; min-height: 44px; }
  :root .mobile-panel #simulationTools .analysis-result > p:only-child { display: none; }
  :root .mobile-panel #simulationTools .estimate-grid strong { font-size: 18px; }
  :root .mobile-panel #simulationTools .history-list { max-height: 320px; overscroll-behavior: contain; }
  :root .mobile-panel #simulationTools .history-row { grid-template-columns: 34px minmax(0, 1fr) 75px; gap: 7px; }
}
