/* Shell redesign (2026-11-12), from the design spec (Cokoon-Core-Design.html): the shared layout layer for
   every inner screen. Home's room is never touched here: rules are scoped to inner pages, focused flows,
   tab roots other than Home, and sheets. Colors come from config/theme.js, type sizes from typeScale.
   Pieces (markup from core.js "Shell kit"):
   1. compact centered header (.compact-header, .back-pill, .header-right)
   2. focused flow (.phone.focused-flow, .flow-page, .flow-actions pinned at the bottom, .flow-links)
   3. grouped list rows (.ui-list, .ui-row, .ui-tile, .ui-pill, .ui-chev), segmented control (.ui-seg),
      switch (.ui-switch-row, .ui-switch), sheet title/actions (.sheet-title, .sheet-actions)
   4. semantic cards (.ui-card-prompt/partner/success/secret) and the shared-stars badge (.ui-stars-badge) */

/* ---------- 1. Compact centered header ---------- */
body.cokoon-app #app-screen .page-header.compact-header {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr); align-items: center; gap: 8px;
  min-height: 52px; margin: -6px -8px 14px;
}
body.cokoon-app #app-screen .compact-header .header-nav { margin: 0; justify-self: start; display: flex; }
body.cokoon-app #app-screen .compact-header .header-title { min-width: 0; text-align: center; }
body.cokoon-app #app-screen .compact-header h1 {
  font-size: var(--type-title); line-height: 22px; font-weight: 800; letter-spacing: -.3px; margin: 0;
  overflow-wrap: normal; text-wrap: balance;
}
body.cokoon-app #app-screen .compact-header .header-sub {
  display: block; margin-top: 1px; font-size: var(--type-subtitle); line-height: 15px; font-weight: 650; color: var(--text-secondary);
}
body.cokoon-app #app-screen .compact-header .header-right { justify-self: end; display: flex; align-items: center; gap: 6px; min-width: 0; }
body.cokoon-app .back-pill {
  display: inline-flex; align-items: center; gap: 3px; height: 36px; min-height: 36px; padding: 0 13px 0 8px; margin: 0;
  border-radius: 99px; border: 1px solid var(--border-default); background: var(--navigation-background); color: var(--text-primary);
  font: inherit; font-size: 13px; font-weight: 750; white-space: nowrap; box-shadow: none;
}
body.cokoon-app .back-pill svg { width: 18px; height: 18px; flex: none; }
body.cokoon-app .back-pill.back-icon { width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 50%; }
body.cokoon-app .back-pill:active { opacity: .55; }
body.cokoon-app #app-screen .page-lead {
  margin: -6px 4px 16px; text-align: center; font-size: 14px; line-height: 20px; color: var(--text-secondary);
}
/* Right actions: a quiet text action ("Set aside") or a round accent icon button (+, edit). */
body.cokoon-app .header-action {
  min-height: 40px; padding: 8px 2px; border: 0; background: none; color: var(--text-secondary);
  font: inherit; font-size: 14px; font-weight: 750; white-space: nowrap;
}
body.cokoon-app .header-icon-action {
  width: 40px; height: 40px; min-width: 40px; padding: 0; display: grid; place-items: center; border-radius: 50%;
  background: var(--header-highlight); border: 1px solid var(--header-highlight); color: var(--on-accent);
  box-shadow: 0 4px 9px color-mix(in srgb, var(--shadow-color) 10%, transparent);
}
body.cokoon-app .header-icon-action svg { width: 20px; height: 20px; }
/* Route sheets (pet, mood, note): the back pill is dressed as the sheet's X, title left like a sheet. */
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .page-header.compact-header { display: block; margin: 0 0 14px; padding-right: 52px; }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .compact-header .header-title { text-align: left; }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .compact-header h1 { font-size: var(--type-sheet-title); line-height: 25px; padding-right: 0; }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .compact-header .header-right:empty { display: none; }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .page-lead { text-align: left; margin: -8px 0 16px; }
body.cokoon-app .back-pill.route-sheet-close { width: 36px; height: 36px; min-height: 36px; padding: 0; justify-content: center; border-radius: 50%; }
/* A step inside a route sheet (an entry opened from its list, its editor): a small back arrow left of the
   title, the step's own action (edit) on the right; swipe down still closes the whole sheet. */
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .page-header.compact-header.route-sheet-step { display: flex; align-items: center; gap: 10px; padding-right: 0; }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .route-sheet-step .header-nav { position: static; margin: 0; }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .route-sheet-step .header-title { flex: 1 1 auto; min-width: 0; }
/* A sheet with its own way out in the header (Cancel): it takes the X's place, top right. */
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .route-sheet-own-exit .header-nav { display: none; }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .route-sheet-own-exit .header-right { position: absolute; top: 14px; right: 16px; z-index: 4; }
body.cokoon-app .back-pill.route-sheet-back { width: 36px; height: 36px; min-height: 36px; padding: 0; justify-content: center; border-radius: 50%; }
/* Detents (native-ui.js detent:'medium'): the sheet opens at about 70% and scrolls inside; dragged up it
   grows to the large detent. Its pinned action bar sits on the sheet's own paper. */
body.cokoon-app #phone.route-sheet.route-sheet-medium:not(.route-sheet-large) > #app-scroll { max-height: min(72%, calc(100% - env(safe-area-inset-top) - 10px)); }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .flow-actions { background: var(--modal-background); }
body.cokoon-app :is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .flow-actions::before { background: linear-gradient(color-mix(in srgb, var(--modal-background) 0%, transparent), var(--modal-background)); }

/* ---------- 2. Focused flow: no tab bar, the main action pinned at the bottom ---------- */
body.cokoon-app .phone.focused-flow #app-screen { min-height: 100%; display: flex; flex-direction: column; padding-bottom: 0; }
body.cokoon-app .phone.focused-flow #app-screen > :is(.flow-page, section) { flex: 1 0 auto; }
body.cokoon-app .flow-page { display: flex; flex-direction: column; }
body.cokoon-app .flow-body { flex: 1 0 auto; }
body.cokoon-app #app-screen .flow-actions {
  position: sticky; bottom: 0; z-index: 6; display: flex; flex-direction: column; gap: 8px;
  margin: 14px 0 0; padding: 14px 0 calc(16px + env(safe-area-inset-bottom));
  background: var(--page-background);
}
body.cokoon-app #app-screen .flow-actions::before {
  content: ''; position: absolute; left: 0; right: 0; bottom: 100%; height: 16px; pointer-events: none;
  background: linear-gradient(color-mix(in srgb, var(--page-background) 0%, transparent), var(--page-background));
}
body.cokoon-app #app-screen .flow-actions > :is(.primary, .secondary, form, .act-two-actions) { width: 100%; margin: 0; }
body.cokoon-app :is(#app-screen .flow-actions, .sheet-actions) :is(.primary, .secondary) { min-height: 52px; border-radius: 99px; font-size: var(--type-button); }
body.cokoon-app :is(#app-screen .flow-actions, .sheet-actions) .primary {
  background: linear-gradient(var(--header-highlight), var(--accent)); border-color: transparent;
  box-shadow: 0 4px 9px color-mix(in srgb, var(--accent) 10%, transparent), inset 0 1px 0 color-mix(in srgb, var(--on-accent) 38%, transparent);
}
body.cokoon-app :is(#app-screen .flow-actions, .sheet-actions) .primary:disabled { background: var(--surface-muted); color: var(--text-secondary); box-shadow: none; }
body.cokoon-app .flow-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; }
body.cokoon-app .flow-links :is(.text-button, button) {
  min-height: 40px; padding: 8px 4px; border: 0; background: none; color: var(--accent);
  font: inherit; font-size: 14px; font-weight: 750; width: auto;
}
body.cokoon-app .flow-links .text-button.muted { color: var(--text-secondary); }

/* ---------- 3. Type scale on inner pages and sheets ---------- */
body.cokoon-app #modal-root .modal-card > h2:first-of-type,
body.cokoon-app #modal-root .modal-card > :is(div, section, header) > h2:first-child,
body.cokoon-app .sheet-title {
  font-size: var(--type-sheet-title); line-height: 25px; font-weight: 800; letter-spacing: -.4px;
}
body.cokoon-app .sheet-title small { display: block; margin-top: 2px; font-size: var(--type-row-sub); line-height: 17px; font-weight: 650; letter-spacing: 0; color: var(--text-secondary); }
body.cokoon-app #modal-root .modal-card > h2:first-of-type + p { font-size: 14px; line-height: 20px; color: var(--text-secondary); }
body.cokoon-app :is(.phone.pushed-page, .phone.focused-flow) #app-screen h2:not(.act-big-question):not(.ui-card h2) { font-size: 18px; line-height: 1.3; letter-spacing: -.3px; }
body.cokoon-app :is(.phone.pushed-page, .phone.focused-flow, #modal-root) .field > label,
body.cokoon-app .field-label { font-size: var(--type-label); font-weight: 780; color: var(--text-primary); }
body.cokoon-app .section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 0 10px; font-size: var(--type-section); font-weight: 800; letter-spacing: -.2px; }
body.cokoon-app .section-title small { font-size: var(--type-row-sub); font-weight: 650; color: var(--text-secondary); }
body.cokoon-app .ui-count { display: block; margin-top: 5px; text-align: right; font-size: 11.5px; font-weight: 650; color: var(--text-secondary); }
body.cokoon-app .ui-note { margin: 10px 4px 0; font-size: 12.5px; line-height: 18px; color: var(--text-secondary); }

/* ---------- 3. Grouped list rows ---------- */
body.cokoon-app .ui-list {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--card-background); border: 1px solid var(--border-default); border-radius: 20px; box-shadow: var(--card-shadow);
}
body.cokoon-app .ui-list + .ui-list { margin-top: 12px; }
body.cokoon-app .ui-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 12px 14px; margin: 0;
  border: 0; border-top: 1px solid var(--row-divider); border-radius: 0; background: none; box-shadow: none;
  color: var(--text-primary); font: inherit; text-align: left;
}
body.cokoon-app .ui-list > .ui-row:first-child, body.cokoon-app .ui-list > :first-child .ui-row { border-top: 0; }
body.cokoon-app button.ui-row:active { background: var(--surface-tinted); }
body.cokoon-app .ui-row-main { flex: 1; min-width: 0; }
body.cokoon-app .ui-row-main b { display: block; font-size: var(--type-row-title); line-height: 20px; font-weight: 750; }
body.cokoon-app .ui-row-main small { display: block; margin-top: 1px; font-size: var(--type-row-sub); line-height: 17px; color: var(--text-secondary); }
body.cokoon-app .ui-row-main .clip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.cokoon-app .ui-chev { flex: none; display: grid; color: var(--chevron); }
body.cokoon-app .ui-chev svg { width: 18px; height: 18px; }
body.cokoon-app .ui-tile {
  flex: none; width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  background: var(--tile-background); color: var(--header-highlight);
}
body.cokoon-app .ui-tile svg { width: 22px; height: 22px; }
body.cokoon-app .ui-tile.sky { background: var(--partner-background); color: var(--partner-accent); }
body.cokoon-app .ui-tile.sage { background: var(--success-background); color: var(--success-text); }
body.cokoon-app .ui-tile.cocoa { background: var(--surface-muted); color: var(--text-primary); }
body.cokoon-app .ui-tile.lg { width: 52px; height: 52px; border-radius: 16px; }
body.cokoon-app .ui-pill {
  flex: none; display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 99px;
  font-size: var(--type-pill); font-weight: 780; white-space: nowrap; background: var(--tag-background); color: var(--tag-text);
}
body.cokoon-app .ui-pill.new { background: var(--accent); color: var(--on-accent); }
body.cokoon-app .ui-pill:is(.played, .sent, .success) { background: var(--success-background); color: var(--success-text); }
body.cokoon-app .ui-pill.partner { background: var(--partner-background); color: var(--partner-text); }
body.cokoon-app .ui-pill.dark { background: var(--secret-background); color: var(--on-secret); }

/* Segmented control (replaces outlined button groups) */
body.cokoon-app .ui-seg { display: flex; gap: 3px; padding: 4px; border-radius: 14px; background: var(--segment-background); }
body.cokoon-app .ui-seg > button {
  flex: 1; min-width: 0; height: 34px; min-height: 34px; margin: 0; padding: 0 6px; border: 0; border-radius: 10px; background: none; box-shadow: none;
  color: var(--segment-text); font: inherit; font-size: 13px; font-weight: 750; white-space: nowrap;
}
body.cokoon-app .ui-seg > button:is([aria-pressed="true"], .selected) {
  background: var(--card-background); color: var(--text-primary); box-shadow: 0 5px 15px color-mix(in srgb, var(--shadow-color) 4%, transparent), 0 2px 3px color-mix(in srgb, var(--shadow-color) 2%, transparent);
}

/* Switch (replaces checkboxes): a real checkbox with role=switch */
body.cokoon-app .ui-switch-row {
  display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 12px 14px; margin: 0 0 16px;
  background: var(--card-background); border: 1px solid var(--border-default); border-radius: 18px; box-shadow: var(--card-shadow); cursor: pointer;
}
body.cokoon-app .ui-list > .ui-switch-row { margin: 0; border: 0; border-top: 1px solid var(--row-divider); border-radius: 0; box-shadow: none; }
body.cokoon-app .ui-list > .ui-switch-row:first-child { border-top: 0; }
body.cokoon-app .ui-switch-row .ui-row-main b { font-size: 14.5px; }
body.cokoon-app input.ui-switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 50px; height: 30px; min-height: 30px; margin: 0; padding: 0;
  border: 0; border-radius: 99px; background: var(--switch-off); transition: background .2s; cursor: pointer;
}
body.cokoon-app input.ui-switch::after {
  content: ''; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--switch-knob); box-shadow: 0 2px 4px color-mix(in srgb, var(--text-primary) 19%, transparent); transition: transform .2s;
}
body.cokoon-app input.ui-switch:checked { background: var(--switch-on); }
body.cokoon-app input.ui-switch:checked::after { transform: translateX(20px); }
body.cokoon-app input.ui-switch:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
body.cokoon-app .reduced-motion input.ui-switch, body.cokoon-app .reduced-motion input.ui-switch::after { transition: none; }

/* Sheet actions: the sheet's main action stays reachable at the bottom while its body scrolls */
body.cokoon-app #modal-root .sheet-actions {
  position: sticky; bottom: calc(-22px - env(safe-area-inset-bottom)); z-index: 4; display: flex; flex-direction: column; gap: 8px;
  margin: 16px 0 calc(-22px - env(safe-area-inset-bottom)); padding: 14px 0 calc(18px + env(safe-area-inset-bottom));
  background: var(--modal-background);
  /* the sheet's paper continues under the bar, so no row ever peeks out below it */
  box-shadow: 0 60px 0 0 var(--modal-background);
}
body.cokoon-app #modal-root .sheet-actions::before {
  content: ''; position: absolute; left: 0; right: 0; bottom: 100%; height: 16px; pointer-events: none;
  background: linear-gradient(color-mix(in srgb, var(--modal-background) 0%, transparent), var(--modal-background));
}
body.cokoon-app #modal-root .sheet-actions > :is(.primary, .secondary) { width: 100%; margin: 0; }

/* ---------- 4. Semantic colour cards ---------- */
body.cokoon-app .ui-card { border-radius: 24px; padding: 18px; margin: 0 0 14px; text-align: left; }
body.cokoon-app .ui-card-prompt {
  background: linear-gradient(160deg, var(--prompt-background), var(--prompt-background-end)); border: 1px solid var(--prompt-border); color: var(--text-primary);
}
body.cokoon-app .ui-card-prompt .ui-eyebrow { color: var(--prompt-eyebrow); }
body.cokoon-app .ui-card-prompt :is(h2, .act-big-question, .act-round-prompt) {
  margin: 6px 0 0; font-size: var(--type-prompt); line-height: 28px; font-weight: 820; letter-spacing: -.4px; color: var(--text-primary);
}
body.cokoon-app .ui-card-partner {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 16px;
  background: var(--partner-background); border: 1px solid var(--partner-border); color: var(--partner-text);
  font-size: 13.5px; line-height: 19px; font-weight: 650;
}
body.cokoon-app .ui-card-partner svg { flex: none; width: 19px; height: 19px; margin-top: 1px; color: var(--partner-accent); }
body.cokoon-app .ui-card-success {
  background: var(--success-background); border: 1px solid var(--success-border); color: var(--success-text);
}
body.cokoon-app .ui-card-success :is(h2, strong) { color: var(--success-text); }
body.cokoon-app .ui-card-secret {
  background: linear-gradient(150deg, var(--secret-background), var(--secret-background-end)); border: 0; color: var(--on-secret);
}
body.cokoon-app .ui-card-secret :is(h2, h3, strong, p, span, small) { color: var(--on-secret); }
body.cokoon-app .ui-card-secret :is(p, small, .act-support) { color: var(--on-secret-muted); }
body.cokoon-app .ui-eyebrow { display: block; font-size: 12px; font-weight: 800; letter-spacing: .2px; color: var(--accent); }
body.cokoon-app .ui-stars-badge {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 5px 12px 5px 9px; border-radius: 99px;
  background: var(--navigation-background); border: 1px solid var(--border-default); color: var(--text-primary);
  font-size: 12.5px; font-weight: 800; white-space: nowrap;
}
body.cokoon-app .ui-stars-badge svg { width: 16px; height: 16px; color: var(--star-icon); fill: var(--star-fill); stroke-width: 1.2; }

/* Inner-page buttons follow the spec's pill shape (Home's own controls are not inner pages). */
body.cokoon-app :is(.phone.pushed-page, .phone.focused-flow) #app-screen :is(.primary, .secondary),
body.cokoon-app #modal-root :is(.primary, .secondary) { border-radius: 99px; }
