:root {
  --background: #f2f3f1;
  --surface: #ffffff;
  --sidebar: #202522;
  --text: #202421;
  --muted: #6f7772;
  --border: #dfe3df;
  --accent: #426b4d;
  --accent-hover: #34583e;
  --accent-soft: #edf4ef;
  --disabled: #aeb5b0;
  --subtle: #fafbfa;
  --quiet: #f1f3f1;
  --radius: 8px;
  --primary-text: #fff;
  --layer-sticky: 30;
  --layer-modal-backdrop: 40;
  --layer-modal: 50;
  --layer-notification: 60;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --background: #111412;
  --surface: #1a1e1b;
  --sidebar: #161916;
  --text: #edf1ee;
  --muted: #9aa39d;
  --border: #343a36;
  --accent: #6e9b78;
  --accent-hover: #7fab89;
  --primary-text: #111412;
  --accent-soft: #202c23;
  --disabled: #505852;
  --subtle: #1d211e;
  --quiet: #272c28;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
#ordinary-upgrades-panel.hide-unlocked-upgrades .item-row.purchased,
#ordinary-upgrades-panel.hide-unlocked-upgrades .upgrade-group:not(:has(.item-row:not(.purchased))) { display: none !important; }
#immortal-abilities-panel.hide-unlocked-abilities .item-row.purchased,
#immortal-abilities-panel.hide-unlocked-abilities #xiuzhen-innate-nie,
#immortal-abilities-panel.hide-unlocked-abilities #xiuzhen-innate-taTian,
#immortal-abilities-panel.hide-unlocked-abilities .upgrade-group:not(:has(.item-row:not(.purchased):not([hidden]))) { display: none !important; }
#toggle-immortal-ability-filter { margin-bottom: 12px; }

/* Independent action subpage; the global resource/sticky layout is untouched. */
.big-number-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.big-number-tabs button { padding: 8px 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; }
.big-number-tabs button[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); }
.big-number-tabs button:disabled { opacity: .5; cursor: not-allowed; }
.big-number-note { color: var(--muted); font-size: 12px; line-height: 1.7; }
.big-number-panel { display: grid; gap: 18px; overflow-wrap: anywhere; }
.big-number-panel section, .big-number-panel details { padding: 20px; background: var(--subtle); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.big-number-panel summary { cursor: pointer; font-weight: 600; }
.big-number-current h2 { font-size: clamp(26px, 4vw, 40px); margin: 8px 0; color: var(--accent); }
.big-number-panel small { color: var(--muted); line-height: 1.7; }
.fractal-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.fractal-row p { margin: 6px 0; font-size: 13px; }
.fractal-row button { flex-shrink: 0; }
.fractal-complete .primary-button { background: transparent; color: var(--accent); border-color: var(--border); }
.fractal-future { opacity: .5; }
.xiuzhen-fold { margin-top: 18px; }
.xiuzhen-fold > summary { font-weight: 600; padding: 16px; }
.xiuzhen-fold > .upgrade-groups, .xiuzhen-fold > .xiuzhen-fold { margin: 12px; }
.xiuzhen-fold > p, .xiuzhen-resources { padding: 0 16px; overflow-wrap: anywhere; }
.xiuzhen-resources { display: grid; gap: 8px; }
.xiuzhen-resources p { margin: 4px 0; }
.xiuzhen-locked { opacity: .6; }
.big-number-panel progress { display: block; width: 100%; height: 12px; margin: 16px 0; accent-color: var(--accent); }
.graham-milestones { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.graham-milestones span { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; }
.graham-milestones .complete { color: var(--accent); background: var(--accent-soft); }
.graham-milestones .next { border: 2px solid var(--accent); font-weight: 700; }
@media (max-width: 520px) {
  .big-number-panel section, .big-number-panel details { padding: 14px; }
  .fractal-row { align-items: flex-start; flex-direction: column; gap: 10px; }
  .fractal-row button { width: 100%; }
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: var(--background);
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
}

button { font: inherit; }

.app {
  width: min(1120px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  isolation: isolate;
}

.app-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}

.brand-title { display: flex; align-items: baseline; gap: 10px; }
.app-header strong { font-size: 20px; letter-spacing: .04em; }
.app-header span { color: var(--muted); font-size: 14px; }
.app-header .game-version {
  padding: 3px 7px;
  color: var(--muted);
  background: var(--subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 10px;
  letter-spacing: .03em;
}
.app-header p { margin: 0; color: var(--muted); font-size: 13px; }
.app-header b { color: var(--text); }
.header-actions { display: flex; align-items: center; gap: 14px; }
.scale-progress { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.scale-progress small { color: var(--muted); font-size: 10px; }



.settings-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
.settings-button:hover { color: var(--text); background: var(--subtle); }

.app-body {
  min-height: calc(100vh - 98px);
  display: grid;
  grid-template-columns: 164px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "sidebar resources"
    "sidebar main";
  align-items: start;
}

.sidebar {
  grid-area: sidebar;
  align-self: stretch;
  padding: 20px 10px;
  color: #eef1ef;
  background: var(--sidebar);
}

.section-label {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
}

.resource-panel {
  position: sticky;
  top: 0;
  z-index: var(--layer-sticky);
  grid-area: resources;
  min-height: 92px;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 0;
  padding: 14px 24px;
  background: var(--subtle);
  border-bottom: 1px solid var(--border);
}
.resource-panel .section-label { flex: 0 0 auto; margin: 0; }
.resource-items { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
.resource-panel > .resource-items { width: 100%; }
.resource-special { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.resource-items > .resource-row:first-child { border-left: 0; padding-left: 0; }
#big-number-rate { white-space: normal; }
.resource-row { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 5px 16px; border-left: 1px solid var(--border); }
.resource-row > span { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.resource-value { min-width: 0; width: 100%; container-type: inline-size; display: flex; flex-direction: column; flex-wrap: wrap; align-items: flex-start; gap: 4px; }
.resource-value strong { max-width: 100%; font-size: 18px; font-size: clamp(14px, 12cqi, 20px); overflow-wrap: normal; }
.resource-value small { max-width: 100%; color: var(--accent); font-size: 10px; font-size: clamp(10px, 7cqi, 12px); font-weight: 700; white-space: normal; overflow-wrap: anywhere; }
#immortal-power-source-note { flex-basis: 100%; color: var(--muted); font-size: 9px; font-weight: 400; line-height: 1.3; white-space: normal; }



.navigation { position: sticky; top: 20px; display: grid; gap: 4px; }
.nav-item {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  color: #bbc2bd;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
}
.nav-item:hover:not(.locked) { background: #2b312d; color: #fff; }
.nav-item.active { color: #fff; background: #363d38; }
.nav-item small { color: #7e8881; font-size: 10px; }
.nav-item.locked { opacity: .55; cursor: not-allowed; }

.main-panel { grid-area: main; padding: 34px; overflow: hidden; }
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 30px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.page-header h1 { margin: 0; font-size: 30px; font-weight: 650; }
.page-header > p { max-width: 360px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; text-align: right; }

.item-list { display: grid; margin-top: 20px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.upgrade-groups { display: grid; gap: 12px; margin-top: 20px; }
.realm-ability-groups { display: grid; gap: 12px; }
.catalog-groups { margin-top: 12px; }
.upgrade-group { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.upgrade-group > summary {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.upgrade-group > summary::-webkit-details-marker { display: none; }
.upgrade-group > summary span { display: flex; flex-direction: column; gap: 4px; }
.upgrade-group > summary b { font-size: 14px; }
.upgrade-group > summary small { color: var(--muted); font-size: 10px; }
.upgrade-group > summary::after { content: "＋"; color: var(--muted); font-size: 18px; font-weight: 400; }
.upgrade-group[open] > summary::after { content: "－"; }
.upgrade-group[open] > summary { border-bottom: 1px solid var(--border); }
.upgrade-group .item-list { margin-top: 0; border: 0; border-radius: 0; }
.catalog-empty { margin: 0; padding: 22px 18px; color: var(--muted); font-size: 12px; }
.item-row {
  min-height: 132px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 24px;
  background: var(--surface);
}
.item-row + .item-row { border-top: 1px solid var(--border); }
.item-content { flex: 1; min-width: 0; }
.item-type { margin: 0 0 6px; color: var(--accent); font-size: 11px; font-weight: 700; }
.item-content h2 { margin: 0 0 8px; font-size: 19px; }
.item-content > p:not(.item-type):not(.formula) { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.item-content b { color: var(--text); }
.formula {
  display: inline-block;
  margin: 10px 0 0;
  padding: 6px 9px;
  color: #526058;
  background: #f4f6f4;
  border-radius: 4px;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.primary-button {
  min-width: 116px;
  min-height: 40px;
  padding: 9px 16px;
  color: var(--primary-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 5px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.primary-button:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.primary-button:active:not(:disabled) { transform: translateY(1px); }
.primary-button:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.primary-button:disabled { color: #fff; background: var(--disabled); border-color: var(--disabled); cursor: not-allowed; }

.action-control, .purchase-control {
  flex: 0 0 170px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  text-align: right;
}
.action-control > span, .purchase-control > span { color: var(--muted); font-size: 12px; }
.action-control > small, .purchase-control > small { color: var(--muted); font-size: 11px; }
#treasures-page .purchase-control { min-width: 0; }
#treasures-page .purchase-control > small { white-space: pre-line; overflow-wrap: anywhere; line-height: 1.6; }
#treasure-list .item-content > p { display: none; }
#treasure-list .treasure-card .item-content { width: 100%; }
#treasure-list .treasure-card h2 > span { font-weight: 500; white-space: nowrap; }
#treasure-list .treasure-effect { display: block; color: var(--text); font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
#treasure-list .treasure-acquisition { display: block; margin-top: 10px; color: var(--muted); font-size: 13px; line-height: 1.7; white-space: pre-line; overflow-wrap: anywhere; }
@media (min-width: 901px) {
  #treasures-page .purchase-control { flex-basis: 42%; text-align: left; }
}
/* Cards keep the decision and its current value visible. */
.card-details { margin:4px 0 0; }
.card-details > summary { width:fit-content; max-width:100%; padding:5px 0; color:var(--accent); font-size:14px; line-height:1.45; cursor:pointer; overflow-wrap:anywhere; }
.card-details > p { margin:2px 0; color:var(--muted); font-size:14px; line-height:1.55; overflow-wrap:anywhere; }
#treasure-list .treasure-details > summary { font-size:15px; color:var(--text); font-variant-numeric:tabular-nums; }
#treasure-list .treasure-details .treasure-acquisition { margin-top:2px; }
#challenge-list .item-content > p:not(.item-type):not(.formula),
#ordinary-upgrades-panel .item-content > p:not(.item-type):not(.formula) { font-size:15px; color:var(--text); }
#challenge-list .purchase-control > small, #ordinary-upgrades-panel .purchase-control > small { font-size:14px; }
#challenge-list .purchase-control > span { font-size:14px; }
#ordinary-upgrades-panel .purchase-control > span, #ordinary-upgrades-panel .item-content > [id$="-preview"] { color:var(--text); font-size:15px; }
#ordinary-upgrades-panel .purchased:has(.item-content > [id$="-preview"]) .purchase-control > small { display:none; }
@media (min-width:901px) {
  #challenge-list .purchase-control { flex-basis:clamp(200px,27%,310px); }
}
@media (max-width:600px) {
  #challenge-list .item-row, #ordinary-upgrades-panel .item-row { gap:10px; padding-block:16px; }
  #challenge-list .purchase-control, #ordinary-upgrades-panel .purchase-control { gap:5px; }
  #challenge-list .primary-button, #ordinary-upgrades-panel .primary-button { min-height:44px; font-size:15px; }
  #challenge-list .purchase-control:has(> span:first-child + button:last-child) { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; }
  #ordinary-upgrades-panel .purchase-control > small { font-size:15px; }
  #treasure-list .treasure-effect { font-size:16px; }
  .card-details > summary { min-height:32px; }
}
.challenge-active-state {
  margin: 20px 0 10px;
  padding: 12px 16px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-weight: 700;
}

.item-row.purchased { background: var(--subtle); }
.item-row.purchased .primary-button { background: transparent; color: var(--accent); border-color: var(--border); }

.achievement { min-height: 118px; }
.achievement-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; padding: 13px 16px; background: var(--subtle); border: 1px solid var(--border); border-radius: var(--radius); }
.achievement-toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.achievement-toolbar strong { color: var(--accent); font-size: 18px; }
.achievement-toolbar + .catalog-groups { margin-top: 10px; }
.achievement-state {
  flex: 0 0 64px;
  padding: 6px 0;
  color: var(--muted);
  background: var(--quiet);
  border-radius: 4px;
  font-size: 10px;
  text-align: center;
}
.achievement-reward { flex: 0 0 190px; color: var(--muted); font-size: 12px; text-align: right; }
.achievement-reward > strong { display: block; }
.achievement.completed { background: var(--accent-soft); }
.achievement.completed .achievement-state { color: #fff; background: var(--accent); }
.achievement.completed .achievement-reward > strong { color: var(--accent); }

.statistics-tabs { display:flex; gap:4px; width:fit-content; margin:18px 0; padding:3px; border:1px solid var(--border); border-radius:var(--radius); }
.statistics-tabs .secondary-button { min-height:40px; padding:6px 18px; border-color:transparent; }
.statistics-tabs .secondary-button[aria-selected="true"] { color:var(--accent); background:var(--accent-soft); border-color:var(--accent); }
.statistics-summary { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:20px; padding:18px 20px; background:var(--accent-soft); border-radius:var(--radius); }
.statistics-summary > div { min-width:0; }
.statistics-summary span, .statistics-summary small { display:block; color:var(--muted); font-size:13px; }
.statistics-summary strong { display:block; margin:4px 0; font-size:clamp(18px,2.5vw,26px); line-height:1.3; overflow-wrap:anywhere; }
.statistics-summary b { font-weight:500; }
.statistics-section { margin-top:8px; border-bottom:1px solid var(--border); }
.statistics-section[open] { padding-bottom:8px; }
.statistics-section > summary { display:flex; align-items:center; justify-content:space-between; min-height:44px; padding:4px 8px; cursor:pointer; list-style:none; }
.statistics-section > summary::-webkit-details-marker { display:none; }
.statistics-section > summary::after { content:""; width:8px; height:8px; margin-inline:8px; border:solid var(--muted); border-width:0 2px 2px 0; transform:rotate(-45deg); }
.statistics-section[open] > summary::after { transform:rotate(45deg); }
.statistics-section > summary:focus-visible { outline:2px solid var(--accent); outline-offset:-2px; }
.statistics-section h2 { margin:0; font-size:18px; }
.statistics-facts { display:flex; flex-wrap:wrap; gap:8px 24px; margin:8px 0; }
.statistics-facts div { display:flex; align-items:baseline; gap:8px; }
.statistics-facts dt, .statistics-table thead { font-size:13px; color:var(--muted); }
.statistics-facts dd { margin:0; }
.statistics-table { width:100%; table-layout:fixed; border-collapse:collapse; font-variant-numeric:tabular-nums; }
.statistics-table th, .statistics-table td { padding:8px 12px; border-bottom:1px solid var(--border); text-align:right; overflow-wrap:anywhere; }
.statistics-table th:first-child { width:24%; text-align:left; }
.statistics-table td small { display:none; }
.statistics-table td b { font-weight:500; }
@media (max-width:600px) {
  .statistics-summary { gap:12px; padding:12px; }
  .statistics-table th, .statistics-table td { padding:7px 4px; }
  .statistics-table th:first-child { width:20%; }
  .statistics-table.statistics-long-values, .statistics-long-values tbody { display:block; }
  .statistics-long-values thead { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
  .statistics-long-values tbody tr { display:grid; gap:3px; padding:8px 0; border-bottom:1px solid var(--border); }
  .statistics-long-values tbody th:first-child, .statistics-long-values td { width:auto; border:0; padding:0; text-align:left; }
  .statistics-long-values td { display:grid; grid-template-columns:5em minmax(0,1fr); }
  .statistics-long-values td small { display:block; color:var(--muted); font-size:13px; }
}
@media (max-width:350px) {
  .statistics-table, .statistics-table tbody { display:block; }
  .statistics-table thead { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
  .statistics-table tbody tr { display:grid; gap:3px; padding:8px 0; border-bottom:1px solid var(--border); }
  .statistics-table tbody th:first-child, .statistics-table td { width:auto; border:0; padding:0; text-align:left; }
  .statistics-table td { display:grid; grid-template-columns:5em minmax(0,1fr); }
  .statistics-table td small { display:block; color:var(--muted); font-size:13px; }
}

.cultivation-status {
  margin-top: 20px;
  padding: 13px 16px;
  color: var(--muted);
  background: var(--subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
}
.cultivation-tabs {
  display: flex;
  gap: 6px;
  margin-top: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.cultivation-tab {
  min-width: 96px;
  padding: 9px 16px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.cultivation-tab:hover { color: var(--text); background: var(--subtle); }
.cultivation-tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.cultivation-subpage { display: none; }
.cultivation-subpage.active { display: block; }
.cultivation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.cultivation-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.cultivation-card h2 { margin: 0 0 8px; font-size: 19px; }
.cultivation-card > p:not(.item-type) { flex: 1; margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.cultivation-card .primary-button,
.cultivation-card .secondary-button { width: 100%; }
.cultivation-card.selected { background: var(--accent-soft); border-color: var(--accent); }
.cultivation-card.unavailable { background: var(--subtle); }
.secondary-button:disabled { opacity: .55; cursor: not-allowed; }

#achievement-notice,
#scale-notice {
  position: fixed;
  left: 50%;
  z-index: var(--layer-notification);
  width: min(440px, calc(100% - 28px));
  padding: 17px 20px;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 18px 55px rgba(0, 0, 0, .32);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -18px) scale(.97);
  transition: opacity .22s ease, transform .22s ease;
}
#scale-notice { top: 22px; }
#achievement-notice { top: 108px; }
#achievement-notice.show,
#scale-notice.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#achievement-notice span,
#scale-notice span { display: block; margin-bottom: 6px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
#achievement-notice strong,
#scale-notice strong { display: block; font-size: 19px; line-height: 1.45; }

.settings-dialog {
  z-index: var(--layer-modal);
  width: min(560px, calc(100% - 28px));
  max-height: min(720px, calc(100vh - 28px));
  max-height: min(720px, calc(100dvh - 28px));
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}
.settings-dialog::backdrop { z-index: var(--layer-modal-backdrop); background: rgba(10, 12, 10, .55); }
.settings-dialog:not([open]) { display: none; }
.settings-dialog[open] { display: flex; flex-direction: column; }
.settings-header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 22px 24px; border-bottom: 1px solid var(--border); }
.settings-header .section-label { margin-bottom: 4px; }
.settings-header h2 { margin: 0; font-size: 24px; }
.settings-header > button { width: 34px; height: 34px; padding: 0; color: var(--muted); background: transparent; border: 0; font-size: 26px; cursor: pointer; }
.settings-list { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; }
.settings-row { flex: 0 0 auto; min-height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.settings-row:last-child { border-bottom: 0; }
.settings-row h3 { margin: 0 0 5px; font-size: 14px; }
.settings-row p { margin: 0; color: var(--muted); font-size: 11px; }
.settings-row > div:first-child { min-width: 0; }
.settings-row p { overflow-wrap: anywhere; }
.settings-row > button { flex: 0 0 auto; min-height: 44px; white-space: nowrap; }
.secondary-button.settings-toggle[aria-checked="true"] { color: var(--primary-text); background: var(--accent); border-color: var(--accent); }
.secondary-button.settings-toggle[aria-checked="true"]:hover { background: var(--accent-hover); }
.settings-header > button { flex: 0 0 auto; min-width: 44px; min-height: 44px; }
.theme-options { display: flex; flex: 0 0 auto; padding: 3px; background: var(--quiet); border: 1px solid var(--border); border-radius: 6px; }
.theme-options label { position: relative; min-width: 58px; padding: 7px 10px; border-radius: 4px; color: var(--muted); font-size: 12px; text-align: center; cursor: pointer; }
.theme-options label:has(input:checked) { color: #fff; background: var(--accent); }
.theme-options input { position: absolute; opacity: 0; pointer-events: none; }
.secondary-button, .danger-button { min-width: 86px; padding: 8px 13px; border-radius: 5px; font-size: 12px; font-weight: 700; cursor: pointer; }
.secondary-button { color: var(--text); background: transparent; border: 1px solid var(--border); }
.secondary-button:hover { background: var(--subtle); }
.danger-row h3 { color: #b64740; }
.danger-button { color: #b64740; background: transparent; border: 1px solid #d9aaa6; }
.danger-button:hover { color: #fff; background: #a53d36; border-color: #a53d36; }

.automation-dialog {
  width: min(760px, calc(100% - 32px));
  max-height: min(78vh, 760px);
  max-height: min(78dvh, 760px);
}
.automation-content {
  min-height: 0;
  padding: 20px 24px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.automation-groups { display: grid; gap: 18px; }
.automation-group { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); }
.automation-group-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 16px; background: var(--subtle); border-bottom: 1px solid var(--border); }
.automation-group-header h3 { margin: 0; font-size: 14px; }
.automation-group-header small { color: var(--muted); font-size: 11px; }
.automation-items { display: grid; }
.automation-row { min-height: 82px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 24px; padding: 16px; border-bottom: 1px solid var(--border); }
.automation-threshold { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; font-size: 12px; }
.automation-threshold input { width: 110px; max-width: 100%; min-width: 0; padding: 9px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--text); }
.automation-threshold button { min-height: 44px; }
#tree-super-auto-error { margin-top: 6px; }
.tree-upgrade button { touch-action: manipulation; }
.automation-row:last-child { border-bottom: 0; }
.automation-row h4 { margin: 0 0 5px; font-size: 14px; }
.automation-row p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.automation-toggle {
  position: relative;
  min-width: 96px;
  padding: 8px 12px 8px 43px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.automation-toggle::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 25px;
  height: 14px;
  transform: translateY(-50%);
  background: var(--quiet);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.automation-toggle::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 10px;
  height: 10px;
  transform: translateY(-50%);
  background: var(--muted);
  border-radius: 50%;
  transition: transform .16s ease, background .16s ease;
}
.automation-toggle:hover { color: var(--text); background: var(--subtle); }
.automation-toggle[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.automation-toggle[aria-pressed="true"]::before { background: var(--accent); border-color: var(--accent); }
.automation-toggle[aria-pressed="true"]::after { transform: translate(11px, -50%); background: #fff; }
.automation-empty { margin: 0; padding: 42px 18px; color: var(--muted); background: var(--subtle); border: 1px dashed var(--border); border-radius: var(--radius); font-size: 13px; text-align: center; }

#catch-up-notice {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: var(--layer-notification);
  width: min(420px, calc(100% - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right))));
  max-height: calc(100dvh - 24px - env(safe-area-inset-bottom));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0, 0, 0, .18);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
#catch-up-notice button {
  min-height: 44px;
  padding: 8px 12px;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  cursor: pointer;
}
#catch-up-notice button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.offline-progress-dialog {
  width: min(620px, calc(100% - 32px));
  max-height: min(78vh, 680px);
  max-height: min(78dvh, 680px);
}
.offline-progress-dialog.offline-completed-presentation {
  position: fixed;
  inset: 16px 16px auto auto;
  margin: 0;
  width: min(380px, calc(100% - 32px));
  max-height: min(55dvh, 420px);
  pointer-events: none;
}
.offline-progress-dialog.offline-completed-presentation .offline-progress-content { pointer-events: auto; }
.offline-progress-content {
  min-height: 0;
  display: grid;
  gap: 16px;
  padding: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.offline-progress-copy { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.offline-progress-copy strong { color: var(--accent); font-size: 22px; }
.offline-progress-copy span { color: var(--muted); font-size: 12px; }
#offline-progress-bar { width: 100%; height: 12px; accent-color: var(--accent); }
.offline-progress-times { display: flex; flex-wrap: wrap; gap: 5px; margin: 0; color: var(--muted); font-size: 12px; }
.offline-progress-times span:not([aria-hidden]) { color: var(--text); font-variant-numeric: tabular-nums; }
.offline-progress-detail { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.offline-result-panel { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--subtle); }
.offline-result-panel h3 { margin: 0 0 8px; font-size: 15px; }
.offline-result-panel p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; overflow-wrap: anywhere; }
.offline-pause-panel { border-color: #d9aaa6; }
.offline-progress-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.offline-progress-actions button { min-width: 118px; }
.offline-settlement-locked .app button,
.offline-settlement-locked .app input,
.offline-settlement-locked .app select,
.offline-settlement-locked .app textarea { cursor: not-allowed; }

#notice {
  position: fixed;
  inset: auto;
  margin: 0;
  border: 0;
  width: max-content;
  max-width: min(560px, calc(100vw - 32px));
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.5;
  z-index: var(--layer-notification);
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  padding: 9px 14px;
  color: #fff;
  background: #202522;
  border-radius: 4px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
#notice.show { opacity: 1; transform: translate(-50%, 0); }
#notice::backdrop { background: transparent; pointer-events: none; }

@media (min-width: 901px) and (max-width: 1151px) {
  .resource-panel { min-height: 78px; gap: 0; padding: 10px 14px; }
  .resource-panel .section-label { display: none; }
  .resource-items { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
  .resource-row { gap: 8px; padding: 4px 10px; }
  .resource-value { gap: 5px; }
  .resource-value small { font-size: 10px; }
  #immortal-power-source-note { font-size: 8px; }
}

@media (max-width: 900px) {
  .app { width: 100%; min-height: 100vh; margin: 0; border: 0; }
  .app-header {
    height: auto;
    min-height: 64px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 10px 12px;
  }
  .brand-title { min-width: 0; flex-wrap: wrap; gap: 6px; }
  .app-header strong { font-size: 18px; }
  .app-header span { font-size: 12px; }
  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
  }
  .header-actions .scale-progress { grid-column: 1; grid-row: 1; min-width: 0; align-items: flex-start; gap: 2px; }
  .header-actions #open-settings { grid-column: 3; grid-row: 1; }
  #online-compensation-balance { grid-column: 1 / -1; grid-row: 2; min-width: 0; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
  .app-header p,
  .scale-progress small {
    max-width: 100%;
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .app-header p { display: block; font-size: 11px; }
  .scale-progress small { font-size: 9px; }  .settings-button { width: 44px; height: 44px; font-size: 19px; }
  .app-body { min-height: calc(100vh - 111px); display: flex; flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; padding: 8px 12px; }
  .resource-panel { width: 100%; min-height: 0; display: block; padding: 12px 16px; }
  .resource-panel .section-label { display: none; }
  .resource-items { grid-template-columns: repeat(auto-fit, minmax(126px, 1fr)); }
  .resource-row { display: block; padding: 4px 8px; }
  .resource-row:first-child { padding-left: 0; border-left: 0; }
  .resource-value { display: flex; margin-top: 3px; gap: 5px; }  .navigation {
    position: static; display: flex; flex-wrap: wrap; gap: 4px; margin: 0;
    overflow: visible;
  }
  .nav-item { flex: 1 0 64px; width: auto; min-width: 64px; justify-content: center; gap: 8px; }
  .nav-item small { display: none; }
  .main-panel { padding: 20px 12px; align-self: stretch; }
  .main-panel:has(#treasures-page.active) { align-self: stretch; }
  .page-header { display: block; padding-bottom: 16px; }
  .page-header > p { margin-top: 10px; text-align: left; }
  .item-row { align-items: flex-start; flex-direction: column; gap: 16px; padding: 20px; }
  .action-control, .purchase-control { width: 100%; flex-basis: auto; text-align: left; }
  .achievement-reward { width: 100%; flex-basis: auto; text-align: left; }
  .achievement-state { flex-basis: auto; padding: 6px 10px; }
  .achievement-toolbar { align-items: stretch; flex-direction: column; }
  .achievement-toolbar .secondary-button { width: 100%; }
  .cultivation-grid { grid-template-columns: 1fr; }
  .settings-header { padding: 14px 16px; }
  .settings-header > button { flex: 0 0 44px; width: 44px; height: 44px; }
  .settings-row { align-items: flex-start; gap: 16px; padding: 16px; }
  .main-panel button, .settings-dialog button, .theme-options label { min-height: 44px; }
  .settings-dialog input:not([type="checkbox"]):not([type="radio"]), .settings-dialog textarea, .settings-dialog select { font-size: 16px; }
  .automation-dialog {
    width: calc(100% - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }
  .automation-content { padding: 16px; }
  .offline-progress-dialog {
    width: calc(100% - 16px);
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }
  .offline-progress-content { padding: 18px 16px; }
}

@media (max-width: 420px) {
  .app-header { padding: 9px 10px; }
  .brand-title { gap: 5px; }
  .app-header .game-version { padding: 2px 5px; font-size: 9px; }
  .header-actions { gap: 6px; }
  .scale-progress small { display: block; font-size: 9px; white-space: normal; line-height: 1.3; }  .resource-items { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .resource-row { padding: 4px 8px; }
  .resource-row:nth-child(odd) { padding-left: 0; border-left: 0; }
  .settings-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .settings-row > button,
  .theme-options { width: 100%; }
  .theme-options label { flex: 1; }
  .automation-row { grid-template-columns: 1fr; align-items: stretch; gap: 12px; }
  .automation-toggle { width: 100%; }
  .offline-progress-copy { align-items: flex-start; flex-direction: column; gap: 4px; }
  .offline-progress-actions { align-items: stretch; flex-direction: column; }
  .offline-progress-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}


/* Keep tall phone settings rows intrinsic; the list, not the rows, scrolls. */
@media (max-width: 520px) {
  #settings-dialog .settings-header { padding: 16px; }
  #settings-dialog .settings-row { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
  #settings-dialog .settings-row > button,
  #settings-dialog .theme-options { width: 100%; }
  #settings-dialog .theme-options label { flex: 1; min-height: 44px; display: grid; place-items: center; }
}

/* Recovery tools stay out of the everyday save controls until expanded. */
.settings-recovery { flex: 0 0 auto; min-width: 0; border-bottom: 1px solid var(--border); }
.settings-recovery > summary { min-height: 60px; padding: 18px 24px; font-size: 14px; font-weight: 700; line-height: 1.6; cursor: pointer; overflow-wrap: anywhere; }
.settings-recovery > summary:hover { background: var(--subtle); }
.settings-recovery > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
.settings-recovery[open] > summary { border-bottom: 1px solid var(--border); }
@media (max-width: 520px) {
  #settings-dialog .settings-recovery > summary { padding: 16px; }
}

/* Only visible while current confirmed progress lacks persistence confirmation. */
.save-failure-panel:not([hidden]) {
  position: fixed; bottom: 12px; left: 12px; right: 12px; z-index: 10000;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px; border: 1px solid #b67d25; border-radius: 8px;
  color: #fff; background: #493412;
}
.save-failure-panel span { flex: 1 1 260px; overflow-wrap: anywhere; }
.save-failure-panel button { min-height: 44px; flex: 0 0 auto; }

/* Phone portrait: compact resources stay pinned and can be collapsed. */
@media (max-width: 600px) and (orientation: portrait) {
  .resource-panel {
    position: sticky;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    max-height: min(40vh, 260px);
    max-height: min(40dvh, 260px);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    gap: 0 12px;
    padding: 8px 12px;
  }
  .resource-panel > .resource-items:not([hidden]) { display: contents; }
  .resource-panel .resource-panel-toggle { position: sticky; top: 0; z-index: 1; background: var(--subtle); }
  .resource-panel .resource-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: start;
    gap: 6px;
    padding: 4px 0;
    border: 0;
  }
  .resource-panel .resource-row > span { font-size: 11px; line-height: 18px; white-space: nowrap; }
  .resource-panel .resource-value {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    margin: 0;
    text-align: right;
  }
  .resource-panel .resource-value strong { max-width: 100%; font-size: 15px; font-size: clamp(14px, 12cqi, 15px); line-height: 1.2; overflow-wrap: anywhere; }
  .resource-panel .resource-value small { max-width: 100%; font-size: 10px; line-height: 1.3; white-space: normal; overflow-wrap: anywhere; }
  .resource-panel #universeCoefficient-resource,
  .resource-panel #highMultiverseCoefficient-resource,
  .resource-panel #multiverseCoefficient-resource { grid-column: 1 / -1; grid-template-columns: max-content minmax(0, 1fr); }
}

/* Short mobile viewports (landscape or an open keyboard) need the page space. */
@media (max-width: 900px) and (max-height: 500px) {
  .resource-panel { position: static; max-height: none; overflow: visible; }
  .resource-panel .resource-panel-toggle { position: static; }
}

/* The same fold control is available on desktop, tablet and phone. */
.resource-panel-toggle {
  grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; width: 100%; min-height: 44px; padding: 0; margin: 0;
  color: var(--muted); background: transparent; border: 0; cursor: pointer; font-size: 12px;
}
.resource-panel-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.resource-panel.resources-collapsed { min-height: 0; }
.resource-panel.resources-collapsed > .resource-items { display: none !important; }

/* Consistent two-line previews for independent resource sources. */
.source-gain-preview { white-space: pre-line; line-height: 1.55; overflow-wrap: anywhere; }
/* Separate each mobile resource while retaining the compact two-column layout. */
@media (max-width: 900px) {
  .resource-panel .resource-items { gap: 8px; }
  .resource-panel .resource-items > .resource-row {
    border: 1px solid #d6dad7;
    border-radius: 6px;
    padding: 6px 8px;
    min-width: 0;
  }
  html[data-theme="dark"] .resource-panel .resource-items > .resource-row { border-color: #525b55; }
}
@media (max-width: 600px) and (orientation: portrait) {
  .resource-panel { gap: 6px 8px; }
}
/* TREE has one vertical flow at every width; only the upgrades may share a row. */
.tree-panel, .tree-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.tree-target { margin: 0; font-weight: 600; line-height: 1.8; }
.tree-amount { display: block; font-size: clamp(24px, 5vw, 36px); color: var(--accent); overflow-wrap: anywhere; }
.tree-upgrades { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.tree-upgrade { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.tree-upgrade > * { min-width: 0; overflow-wrap: anywhere; }
.tree-upgrade strong, .tree-upgrade small { grid-column: 1 / 3; }
.tree-upgrade > span, .tree-upgrade button { grid-column: 3; }
.tree-upgrade-effect { grid-column: 1 / -1; margin: 4px 0; font-size: 13px; line-height: 1.7; white-space: pre-line; }
.tree-upgrade button { min-height: 44px; padding: 8px 12px; }
.tree-entry > small { display: block; margin-top: 10px; }
.tree-panel .tree-help { padding: 0; border: 0; background: transparent; font-size: 12px; color: var(--muted); }
@media (min-width: 1100px) { .tree-upgrades { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Infinity: one branch at a time, shared with the existing theme. */
.infinity-panel { padding: 16px 0; }
.infinity-branches { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:8px; margin:16px 0; }
.infinity-tree { display:grid; grid-template-columns:repeat(var(--infinity-columns,2),minmax(0,1fr)); gap:18px 8px; max-width:720px; margin:24px auto; }
.infinity-node { min-width:0; min-height:90px; display:flex; flex-direction:column; gap:6px; align-items:center; justify-content:center; padding:12px 6px; overflow-wrap:anywhere; }
.infinity-node[aria-pressed="true"],.infinity-branches [aria-selected="true"] { outline:2px solid currentColor; outline-offset:2px; }
.infinity-node.prerequisite,.infinity-node.exclusive,.infinity-node.unaffordable { opacity:.6; }
.infinity-node.purchased { border-style:double; border-width:3px; }
.infinity-details { min-width:0; border:1px solid currentColor; border-radius:8px; padding:16px; margin:20px 0; overflow-wrap:anywhere; }
#infinity-tree > .infinity-details { margin:0; background:var(--subtle); }
#infinity-tree > .infinity-details .primary-button { width:100%; }
@media(max-width:900px) { .infinity-tree { overflow-anchor:none; } }
@media(max-width:600px) { .infinity-branches { grid-template-columns:repeat(2,minmax(0,1fr)); } .infinity-node { font-size:12px; padding:10px 3px; } }

.infinity-branches button,.infinity-node { background:var(--subtle); color:var(--text); border:1px solid var(--border); border-radius:8px; }
.infinity-branches button { padding:10px 6px; cursor:pointer; }
.infinity-node { position:relative; cursor:pointer; }
.infinity-child::before { content:""; position:absolute; height:17px; border-left:1px solid currentColor; left:50%; top:-19px; opacity:.35; }
.infinity-node.available { border-color:var(--accent); }.infinity-node.purchased { background:var(--accent-soft); }

/* Martial pages share the existing cultivation, action, challenge and settings components. */
.martial-section { margin-top: clamp(16px, 2vw, 24px); min-width: 0; }
.martial-section[hidden], .martial-summary[hidden], #martial-progress[hidden], #martial-progress [hidden] { display: none !important; }
#martial-progress .cultivation-tabs { flex-wrap: wrap; }
#martial-progress .cultivation-tab { flex: 1 0 auto; }
.martial-note { color: var(--muted); font-size: 12px; line-height: 1.65; margin: 10px 0; }
.martial-overview { margin-top: 16px; }
.martial-overview > .upgrade-group { margin-top: 12px; }
.martial-heart-table { display: grid; gap: 8px; padding: 16px; color: var(--muted); font-size: 12px; }
.martial-reason { color: var(--muted); }
#martial-challenges > .martial-note { margin: 12px 24px; }
.martial-summary { display: contents; }
#martial-progress .purchase-control small, #martial-actions .action-control small { overflow-wrap: anywhere; }
@media (max-width: 600px) {
  #martial-progress .cultivation-tab { flex: 1 0 calc(50% - 6px); min-width: 0; }
}

#martial-progress .martial-ability-effect { color: var(--text); font-weight: 600; }

/* High multiverse order is unbounded; wrap its label without changing other resource cards. */
.resource-panel #highMultiverseCoefficient-resource { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.resource-panel #highMultiverseCoefficient-resource > span { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
#infinity-high-multiverse-row, #infinity-high-multiverse-highest-row, #high-multiverse-upgrade { overflow-wrap: anywhere; }

/* Martial ability descriptions stay together; prices and actions form a compact column. */
#martial-progress .item-content > small { display:block; margin-top:6px; line-height:1.6; overflow-wrap:anywhere; }
#martial-progress .item-content { min-width:0; flex:1 1 auto; }
#martial-progress .purchase-control { flex:0 0 170px; min-width:0; }
@media(max-width:900px) { #martial-progress .purchase-control { flex-basis:auto; } }

/* Independent recovery controls remain usable before the runtime is ready. */
.boot-status-panel { position:relative; z-index:2147483647; box-sizing:border-box; max-width:100%; padding:14px 18px; border-bottom:2px solid #80733b; background:#fff8dc; color:#24281f; overflow-wrap:anywhere; }
.boot-status-panel[hidden] { display:none; }
.boot-status-panel p { margin:6px 0; }
.boot-status-actions { display:flex; flex-wrap:wrap; gap:8px; }
.boot-status-panel button { min-height:44px; padding:8px 12px; }
.boot-status-panel textarea { box-sizing:border-box; width:100%; max-height:240px; }

.wis-dialog-overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:9000; }
dialog.wis-dialog-fallback[open] { display:block; position:fixed; inset:50% auto auto 50%; transform:translate(-50%,-50%); margin:0; max-width:calc(100vw - 24px); max-height:calc(100vh - 24px); overflow:auto; z-index:9001; }

/* Native-only backup settings; the hidden attribute remains authoritative. */
.native-backup-settings { overflow-wrap: anywhere; padding: 18px 24px; }
.native-backup-settings h3 { margin: 0 0 5px; font-size: 14px; }
.native-backup-settings p { margin: 8px 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.native-backup-settings label { font-size: 12px; }
.native-backup-settings button { min-height: 44px; }
.native-backup-settings .backup-controls { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; }
.native-backup-settings select { font: inherit; padding: 0.45rem; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 0.4rem; }

/* App distribution is presentation-only; respects existing light/dark theme. */
.app-download-dialog { max-width: min(720px, calc(100vw - 24px)); }
.app-download-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 24px; display: grid; grid-auto-rows: max-content; align-content: start; gap: 18px; }
.app-download-body p { margin: 0; }
#app-download-notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.app-download-important { padding: 14px; border: 1px solid var(--border); background: var(--accent-soft); border-radius: var(--radius); }
.app-download-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.app-download-actions a { text-align: center; text-decoration: none; padding: 12px 20px; border-radius: var(--radius); border: 1px solid var(--border); }
#app-download-qr { text-align: center; }
#app-download-qr svg { display: block; width: 220px; max-width: 100%; margin: 0 auto 8px; background: white; }
#app-download-sha { display: block; margin-top: 12px; overflow-wrap: anywhere; font-size: 13px; user-select: all; }
@media (max-width: 540px) { .app-download-body { padding: 16px; } }

/* Keep the download entry beside its version even when the brand wraps. */
.version-actions { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.app-download-link { padding: 5px 0; border: 0; background: transparent; color: var(--accent); font-size: 11px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.app-download-link:hover { color: var(--text); }
.app-download-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

#app-download-environment:empty, #app-download-status:empty { display: none; }

.save-export-dialog { width: min(640px, calc(100vw - 32px)); max-height: 85vh; max-height: 85dvh; padding: 16px; overflow: auto; overflow-wrap: anywhere; }
.save-export-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
#save-export-text { display: block; box-sizing: border-box; width: 100%; height: 32vh; min-height: 140px; margin: 8px 0; font: 12px monospace; resize: vertical; }
#save-export-close { margin-top: 12px; }

/* Separate rules, optional flavor, and technical failure evidence. */
.item-content .flavor-text { margin-top: 8px; font-size: 12px; color: var(--muted); }
#ordinary-actions-panel .action-control { min-width: 0; }
#ordinary-actions-panel .action-control > span,
#ordinary-actions-panel .action-control > small { overflow-wrap: anywhere; white-space: pre-line; }
#training-availability:empty { display: none; }
.calculation-details { max-width: 100%; color: var(--muted); font-size: 12px; text-align: left; }
.calculation-details summary { cursor: pointer; padding: 8px 0; }
.calculation-details pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
@media (max-width: 600px) {
  #ordinary-actions-panel .item-row { min-height: 0; gap: 12px; padding: 18px; }
  #ordinary-actions-panel .primary-button { min-height: 44px; }
}

/* Adapt action headings and compact resource controls for each layout. */
:root {
  --wis-ink: #153c32;
  --wis-line: #abc9b7;
}
html[data-theme="dark"] { --wis-ink:#142c26; --wis-line:#789b89; }
.brand-title > strong { color:var(--accent); font-weight:850; letter-spacing:-.045em; }
.resource-value strong, .action-control, .purchase-control, #training-goal-value { font-variant-numeric:tabular-nums; }
.resource-value strong { line-height:1.15; }
.nav-item.active { box-shadow:inset 3px 0 #9fc8a9; }
.action-banner {
  position:relative; isolation:isolate; overflow:hidden; align-items:center;
  padding:18px 28px; min-height:80px; border:1px solid #39594a; border-radius:var(--radius);
  color:#f5f4e9; background-color:var(--wis-ink);
  background-image:repeating-radial-gradient(ellipse at 108% 160%, transparent 0 28px, #acc4a31d 29px 30px, transparent 31px 48px),
    linear-gradient(108deg,transparent 35%,#a9c99414);
}
.action-banner h1 { font:700 clamp(27px,3vw,38px)/1.1 "Songti SC","SimSun",serif; letter-spacing:.09em; }
#training-goal { max-width:260px; margin-top:20px; }
#training-goal label { display:flex; justify-content:space-between; gap:12px; color:var(--muted); font-size:12px; }
#training-goal-value { color:var(--text); font-weight:650; }
#training-meter { display:block; width:100%; height:5px; margin-top:8px; border:0; border-radius:5px; overflow:hidden; accent-color:var(--accent); background:var(--border); }
#training-meter::-webkit-progress-bar { background:var(--border); }
#training-meter::-webkit-progress-value { background:var(--accent); }
#training-meter::-moz-progress-bar { background:var(--accent); }
.catalog-no-results { margin:0; padding:18px; color:var(--muted); font-size:14px; }
.catalog-groups:has(> details:not([hidden])) > .catalog-no-results { display:none; }
.catalog-group[data-catalog-system-group="仙道"] > summary,
.catalog-group[data-catalog-system-group="武道"] > summary { border-inline-start:3px solid var(--accent); }
.catalog-group[data-catalog-system-group="武道"] > summary { border-inline-start-color:#a76d42; }
#martial-actions > .upgrade-group > summary { border-inline-start:3px solid #a76d42; }
.infinity-node.purchased { min-height:58px; padding-block:6px; gap:3px; }
.infinity-node.available { border-width:2px; background:var(--accent-soft); }
.infinity-node.purchased:not([aria-pressed="true"]) { color:var(--muted); background:var(--subtle); }
.infinity-node.purchased strong { color:var(--text); }
@media (min-width:901px) {
  .resource-panel { padding-block:7px 12px; }
  .resource-panel-toggle { min-height:32px; }
  .resource-panel.resources-collapsed { padding-block:4px; }
  .nav-item { padding-inline-start:18px; }
  .nav-item.active { background:#38483f; }
  .training-row { min-height:158px; background:linear-gradient(100deg,var(--accent-soft),var(--surface) 68%); }
  .training-row .action-control { padding-inline-start:20px; border-inline-start:1px solid var(--border); }
}
@media (max-width:600px) and (orientation:portrait) {
  .nav-item.active { box-shadow:inset 0 -2px #a6cdb0; }
  .sidebar { padding-block:4px; }
  .main-panel { padding-top:14px; }
  .resource-panel.resources-focused {
    grid-template-columns:minmax(0,1fr) minmax(0,1fr) auto;
    align-items:stretch; padding:6px 10px; gap:6px; overflow:visible; max-height:none;
  }
  .resources-focused .resource-row:not(.focus-resource) { display:none; }
  .resource-panel.resources-focused .focus-resource {
    grid-column:auto; border:0; border-inline-start:2px solid var(--wis-line); border-radius:0;
    display:flex; flex-direction:column; align-items:flex-start; gap:2px; min-width:0; padding:2px 5px;
  }
  .resources-focused .resource-value { align-items:flex-start; text-align:start; }
  .resources-focused .resource-row > span { white-space:normal; line-height:1.25; }
  .resources-focused .resource-value small { font-weight:500; line-height:1.25; }
  .resource-panel.resources-focused .resource-panel-toggle {
    grid-column:3; grid-row:1; align-self:center; position:static; width:auto; min-width:44px; min-height:44px;
    flex-direction:column; justify-content:center; gap:2px; border:1px solid var(--border); border-radius:6px;
  }
  .resource-panel-toggle span:last-child { color:var(--accent); }
  .action-banner { display:flex; min-height:56px; gap:8px; padding:13px 14px; }
  .action-banner h1 { font-size:25px; }
  .training-row { background:linear-gradient(135deg,var(--accent-soft),var(--surface) 65%); }
  #training-goal { margin-top:12px; }
  #ordinary-actions-panel .training-row .item-content { align-self:stretch; }
  #training-goal { max-width:none; }
}
