/* Phone layout: screens up to 650 px wide. iPads (744 px and wider) and computers keep the wide layout untouched.
   Loaded last on every page. Rules start with :root so `npm run build:themes` scopes their colours to each theme;
   :root also lifts them above the per-theme picture placement in scripts/<theme>-theme/layout.css.
   Rules of the layout: a row of buttons stays one row; pictures sit beside the words, never on them;
   sections that stand side by side on a wide screen are stacked whole, one under another. */

/* Wide screens: the phone-only parts of the account menu stay out of sight. */
.account-menu-tools,.account-menu-lock,.month-step,.phone-back{display:none}

@media(max-width:650px){
  /* ---------- Header: one row — back arrow, brand, child, menu ---------- */
  :root body .topbar,:root body .account-header{position:relative;z-index:60;display:flex;flex-wrap:nowrap;align-items:center;gap:8px;min-height:0;padding:12px 0;border-bottom:1px solid #eee5e9}
  :root body :is(.top-actions,.account-header-actions,.calendar-header-actions,.rewards-header-actions){display:contents}
  :root body :is(.topbar,.account-header) .brand{order:1;flex:1 1 auto;min-width:0;flex-basis:auto;gap:8px;font-size:16px}
  :root body :is(.topbar,.account-header) .brand img{width:34px;height:34px}
  :root body :is(.topbar,.account-header) .brand>span,:root body .brand-copy>span:first-child{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
  :root body .brand-copy{min-width:0;gap:2px}
  :root body .today-label{font-size:10.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  /* Sub-pages: "back to today" becomes a round arrow before the brand. */
  :root body :is(.rewards-back,.calendar-back){order:0;flex:none;width:38px;min-height:38px;height:38px;margin:0;padding:0;justify-content:center;border-radius:13px;font-size:0}
  :root body :is(.rewards-back,.calendar-back)>span{display:none}
  :root body :is(.rewards-back,.calendar-back) svg{width:18px;height:18px}
  :root body .phone-back{order:0;display:inline-flex;align-items:center;justify-content:center;flex:none;width:38px;height:38px;border:1px solid #e6dceb;border-radius:13px;background:#fffdf8;color:#7b649d}
  :root body #stats-back{display:none}
  /* Language and Parents/Child live in the menu sheet once the menu is there (phone.js). */
  :root body header:has(.account-picker:not([hidden])) :is(.language-switch,.parent-mode-toggle){display:none}
  :root body header .language-switch{order:2}
  :root body header .parent-mode-toggle{order:2;min-height:38px;padding:7px 10px;font-size:11px}
  /* Child: only the avatar and a small arrow; the name is on the page itself. */
  :root body header .user-picker{order:3;flex:none;width:auto}
  :root body header .user-switcher{flex:none;width:auto;min-width:0;min-height:42px;gap:3px;padding:3px 6px 3px 3px;border-radius:14px}
  :root body header .user-switcher .user-copy{display:none}
  :root body header .user-switcher .user-avatar{width:34px;height:34px;border-radius:11px;font-size:15px}
  :root body header .user-switcher .user-chevron{width:14px;height:14px}
  :root body header div.user-picker[data-user=""]>.user-switcher .user-copy{display:block}
  :root body header .user-menu{left:auto;right:0;top:calc(100% + 8px);width:min(230px,calc(100vw - 32px))}
  /* Menu button: three lines; a gold ring while Parents mode is open. */
  :root body header .account-picker{order:4;flex:none}
  :root body header .account-menu-trigger{width:42px;height:42px;min-height:42px;padding:0;border-radius:14px;gap:0}
  :root body header .account-menu-trigger>*{display:none}
  :root body header .account-menu-trigger>.account-menu-dot:not([hidden]){display:block;top:6px;left:auto;right:6px}
  :root body header .account-menu-trigger::before{content:"";width:18px;height:14px;color:#765a90;background:linear-gradient(currentColor,currentColor) 0 0/100% 2px no-repeat,linear-gradient(currentColor,currentColor) 0 6px/100% 2px no-repeat,linear-gradient(currentColor,currentColor) 0 12px/100% 2px no-repeat}
  :root body header .account-picker:not(.is-locked) .account-menu-trigger{border-color:#e6c27e;box-shadow:0 0 0 2px #f8e3b5}
  :root body header .parent-mode-notice{position:fixed;z-index:1200;top:10px;left:16px;right:16px;padding:10px 14px;border:1px solid #ecd2da;border-radius:14px;background:#fffaf6;box-shadow:0 10px 30px #4b306b24;text-align:center;font-size:13px}

  /* ---------- Account menu: a sheet from the bottom of the screen ---------- */
  :root body .account-dropdown{position:fixed;z-index:1000;inset:auto 0 0 0;width:auto;max-width:none;max-height:88vh;max-height:88dvh;overflow-y:auto;overscroll-behavior:contain;padding:8px 16px calc(14px + env(safe-area-inset-bottom));border:0;border-top:1px solid #e4d6ed;border-radius:24px 24px 0 0;box-shadow:0 0 0 100vmax #2b1d4252,0 -12px 40px #2b1d422e}
  :root body .account-dropdown::before{content:"";display:block;width:40px;height:4px;margin:2px auto 10px;border-radius:2px;background:#ded2e9}
  :root body .account-dropdown-heading{flex-direction:row;align-items:center;gap:12px;margin:0 2px 8px;padding:4px 4px 12px}
  :root body .account-dropdown-heading .account-menu-crown{flex:none}
  :root body .account-menu-identity{display:grid;gap:1px;min-width:0}
  :root body .account-menu-chips{display:none}
  :root body .account-menu-tools{display:flex;gap:8px;margin:0 2px 10px}
  :root body .account-menu-language{display:flex;flex:1 1 0;gap:3px;padding:3px;border:1px solid #e3d8ee;border-radius:14px;background:#f4eef9}
  :root body .account-menu-language button{flex:1;min-height:38px;border:0;border-radius:11px;background:transparent;color:#a18cb2;font:inherit;font-size:13px;font-weight:700}
  :root body .account-menu-language button[aria-pressed=true]{background:#fffdf9;color:#7853b1;box-shadow:0 2px 7px #7657b814}
  :root body .account-menu-mode{flex:1 1 0;min-height:44px;padding:6px 10px;border:1px solid #ddcbea;border-radius:14px;background:#f2eafa;color:#79579f;font:inherit;font-size:13px;font-weight:800;white-space:nowrap}
  :root body .account-menu-mode[data-mode=child]{border-color:#e6c27e;background:#fff3da;color:#8d6526}
  :root body .account-menu-mode[hidden]{display:none}
  :root body .account-menu-lock{display:flex;align-items:center;gap:8px;margin:0 2px 8px;padding:10px 12px;border-radius:14px;background:#fff6e4;color:#8d6a35;font-size:12px;line-height:1.5}
  :root body .account-menu-lock[hidden]{display:none}
  :root body .account-menu-lock svg{flex:none;width:18px;height:18px}
  /* Two columns of pages so the whole menu fits on one screen. */
  :root body .account-menu-group{display:grid;grid-template-columns:1fr 1fr;gap:2px 6px;padding:6px 0;border-top:1px solid #f0e8f1}
  :root body .account-menu-group-label{grid-column:1/-1;padding:2px 8px 4px}
  :root body .account-menu-group .account-menu-item{min-width:0;min-height:44px;padding:6px 8px;gap:8px;font-size:13px}
  :root body .account-menu-group .account-menu-item>span:not(.account-menu-icon){min-width:0;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
  :root body .account-menu-group .account-menu-soon{display:none}
  :root body .account-picker.is-locked .account-menu-item[aria-disabled=true]{opacity:.42;pointer-events:none}
  :root body .account-menu-footer{padding-top:6px;border-top:1px solid #f0e8f1}

  /* ---------- Page banners: words on the left, the picture beside them ---------- */
  :root .frozen-page .frozen-banner,:root .frozen-page .frozen-banner--tall{display:grid;grid-template-columns:minmax(0,1fr) 92px;grid-template-rows:auto auto 1fr auto;column-gap:10px;min-height:0;margin:14px 0 18px;padding:18px 14px 16px 18px;border-radius:22px}
  :root body .frozen-banner>.frozen-banner-copy{display:contents}
  :root body .frozen-banner-copy>:is(.section-kicker,.eyebrow){grid-column:1;grid-row:1;margin:0}
  :root body .frozen-banner-copy>h1{grid-column:1;grid-row:2}
  :root body .frozen-banner-copy>:is(.account-description,.calendar-description){grid-column:1;grid-row:3;align-self:start}
  :root body .frozen-banner-copy>.frozen-banner-actions{grid-column:1/-1;grid-row:4;margin-top:14px}
  :root .frozen-page .frozen-banner h1{margin:6px 0 0;font-size:26px;line-height:1.2}
  :root .frozen-page .frozen-banner :is(.account-description,.calendar-description){margin:6px 0 0;font-size:12.5px;line-height:1.6;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden}
  :root body .frozen-banner::before{opacity:.45}
  :root body .frozen-banner-clip{position:relative;inset:auto;grid-column:2;grid-row:1/4;align-self:stretch;min-height:112px;overflow:visible;border-radius:0}
  :root body .frozen-banner[data-art] .frozen-banner-art{position:absolute;inset:auto 0 0 auto;width:100%;height:100%;max-height:150px;object-fit:contain;object-position:center bottom;opacity:1;transform:none;-webkit-mask-image:none;mask-image:none}
  /* Decorations without a character (tiles, passes, coin → crystal) give their room to the words. */
  :root body .frozen-banner:has(.frozen-banner-group){grid-template-columns:minmax(0,1fr)}
  :root body .frozen-banner:has(.frozen-banner-group) .frozen-banner-clip{display:none}
  /* Banner buttons and chips: one row; long chips shorten instead of wrapping. */
  :root body .frozen-banner-actions{flex-wrap:nowrap;gap:8px;min-width:0}
  :root body .frozen-banner-actions>*{min-width:0;flex:0 1 auto}
  :root body .frozen-banner-actions .frozen-pill{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
  :root body .frozen-banner :is(.simple-child-picker,.settings-child-picker){min-width:0}
  :root body .frozen-banner .simple-child-picker select{min-width:0}
  :root body .frozen-banner .settings-child-picker .user-picker{width:170px}

  /* ---------- Home: today's card with the buddy beside the words ---------- */
  :root body .hero{display:grid;grid-template-columns:minmax(0,1fr) 96px;column-gap:10px;min-height:0;margin:14px 0 16px;padding:20px 14px 16px 18px;border-radius:22px;align-items:start}
  :root body .hero>.hero-copy{display:contents}
  :root body .hero-copy>.eyebrow{grid-column:1;grid-row:1;margin:0;font-size:9.5px}
  :root body .hero-copy>h1{grid-column:1;grid-row:2;margin:6px 0 0;font-size:28px;line-height:1.18}
  :root body .hero-copy>.hero-description{grid-column:1;grid-row:3;margin:8px 0 0;font-size:12.5px;line-height:1.6;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden}
  :root body .hero-copy>.hero-stats{grid-column:1/-1;grid-row:4;flex-wrap:nowrap;justify-content:space-between;gap:8px;margin-top:14px;padding-top:12px;border-top:1px solid #ebe1ee}
  :root body .hero-stats>*{min-width:0;white-space:nowrap}
  /* Each figure sits over its label, so the three still fit one row in English. */
  :root body .hero-stats>div{display:grid;gap:1px}
  :root body .hero-stats .hero-coins-link{display:grid;grid-template-columns:auto auto;justify-content:start;align-items:center;column-gap:5px;row-gap:1px}
  :root body .hero-stats .hero-coins-link>span{grid-column:1/-1}
  :root body .hero-stats :is(div,.hero-coins-link)>span{font-size:10px;line-height:1.3}
  :root body .hero-art{display:none}
  :root body .hero::before{content:"";position:relative;inset:auto;grid-column:2;grid-row:1/4;align-self:stretch;width:auto;min-height:118px;border-radius:18px;background-image:url('/theme-art/home');background-size:cover;background-position:50% 12%;background-repeat:no-repeat;opacity:1}

  /* Banner buttons keep their words on one line. */
  :root .frozen-page .frozen-banner-actions :is(.account-secondary,.account-primary){display:block;flex:0 1 auto;min-width:0;min-height:40px;padding:0 12px;font-size:12px;line-height:38px;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

  /* ---------- Calendar: one month at a time — swipe, or the arrows beside the month ---------- */
  :root body .calendar-months{position:relative;display:flex;gap:12px;overflow-x:auto;scroll-snap-type:x mandatory;overscroll-behavior-x:contain;scrollbar-width:none;align-items:flex-start}
  :root body .calendar-months::-webkit-scrollbar{display:none}
  :root body .calendar-months>.month-card{flex:0 0 100%;scroll-snap-align:start;scroll-snap-stop:always}
  :root body .month-heading{gap:8px;margin-bottom:14px}
  :root body .month-heading h2{flex:1;text-align:center}
  :root body .month-step{display:grid;place-items:center;flex:none;width:38px;height:38px;padding:0;border:1px solid #e6dceb;border-radius:13px;background:#fffdf8;color:#7b649d;font-size:22px;line-height:1}
  :root body .month-step-prev{order:-1}
  :root body .month-step:disabled{opacity:.3}
  :root body .month-heading .month-note{order:1}
  :root body .month-step-next{order:2}

  /* ---------- Spacing: the first card sits close under the header ---------- */
  :root body main:is(.rewards-main,.calendar-main,.family-main,.settings-main,.account-settings-main){padding-top:14px}
  :root .frozen-page main>.frozen-banner:first-child{margin-top:0}
  :root body .account-card{padding:18px 16px;border-radius:20px}

  /* ---------- Rewards: each treat is one compact row ---------- */
  :root body .reward-grid:not(.weekly-grid){grid-template-columns:minmax(0,1fr);gap:10px}
  :root body .reward-grid:not(.weekly-grid) .reward-card{display:grid;grid-template-columns:48px minmax(0,1fr) auto;grid-template-rows:auto auto;column-gap:12px;row-gap:2px;align-items:center;padding:12px 12px 12px 14px;border-radius:18px}
  :root body .reward-grid:not(.weekly-grid) .reward-emoji{grid-row:1/3;width:48px;height:48px}
  :root body .reward-grid:not(.weekly-grid) .reward-card h3{grid-column:2;grid-row:1;margin:0;font-size:15px;line-height:1.35}
  :root body .reward-grid:not(.weekly-grid) .reward-description{grid-column:2;grid-row:2;margin:0;font-size:11.5px;line-height:1.5;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}
  :root body .reward-grid:not(.weekly-grid) .reward-card-bottom{grid-column:3;grid-row:1/3;flex-direction:column;align-items:flex-end;gap:6px;margin:0}
  :root body .reward-grid:not(.weekly-grid) .reward-button{width:auto;min-width:76px;min-height:34px;padding:0 12px;white-space:nowrap}

  /* ---------- Parent settings: shorter forms ---------- */
  :root body :is(.editor-task,.wish-row){padding:14px 12px;border-radius:16px}
  :root body .wish-row-heading{margin-bottom:12px}
  /* Short fields share a row: coins beside the category (tasks), coins beside the time (rewards). */
  :root body .editor-task{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);column-gap:10px}
  :root body .editor-task>*{grid-column:1/-1}
  :root body .editor-task>:is(.editor-category,.editor-task-coins){grid-column:auto;max-width:none;margin-top:12px}
  :root body .wish-fields{grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px 10px}
  :root body .wish-fields>*{grid-column:1/-1}
  :root body .wish-fields:has(>label>select)>:nth-child(2),:root body .wish-fields:has(>label>select)>:nth-child(4){grid-column:auto}
  :root body .wish-fields:has(>label>select)>:nth-child(2){order:1}
  :root body .wish-fields:has(>label>select)>:nth-child(4){order:2}
  :root body .wish-fields:has(>label>select)>:nth-child(3){order:3}
  :root body .wish-fields:has(>label>select)>:nth-child(5){order:4}
  /* Photo: a small picture with its buttons beside it; the long hint is left out. */
  :root body .wish-photo-controls{flex-wrap:nowrap;gap:10px}
  :root body .wish-photo-preview{flex:none;width:72px;height:64px}
  :root body .wish-photo-note{display:none}
  /* Weekdays stay one row of seven. */
  :root body .editor-weekdays{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:4px}
  :root body .editor-weekdays legend{grid-column:1/-1}
  :root body .editor-weekdays label{position:relative;justify-content:center;gap:0;padding:9px 0;font-size:12px}
  :root body .editor-weekdays input{position:absolute;opacity:0;pointer-events:none}
  :root body .editor-icon-choices{gap:6px}
  :root body .editor-icon-choice{width:44px;height:44px}
  /* Passes: the count and the price limit share a row. */
  :root body .pass-card-fields{grid-template-columns:minmax(0,1fr) minmax(0,1fr);column-gap:10px}
  :root body .pass-card-fields>*{grid-column:1/-1}
  :root body .pass-card-fields>:is(.pass-card-count,.pass-card-limit){grid-column:auto}
  :root body .pass-card-fields select{width:100%}
  /* Save bars stay slim at the bottom of the screen: the message line only appears when it says something. */
  :root body .editor-save-bar{flex-direction:column;align-items:stretch;gap:8px;padding:10px 12px;border-radius:16px}
  :root body .editor-save-bar>p:empty{display:none}
  :root body .editor-save-bar>p{margin:0;text-align:center}
  /* Save bars: one row, words never broken in two. */
  :root body :is(#wishes-form,form,main) .editor-save-actions{flex-wrap:nowrap;gap:8px}
  :root body .editor-save-actions>*{flex:1 1 auto;min-width:0;padding-left:8px;padding-right:8px;font-size:12.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  /* "查看奖励 ↗" shrinks to its arrow so the three buttons keep one row. */
  :root body #wishes-view-rewards{flex:none;width:44px;padding:0;font-size:0}
  :root body #wishes-view-rewards::after{content:"↗";font-size:17px}

  /* ---------- Task tracking: today and coins side by side; one button under the week ---------- */
  :root body .tracking-stats{grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px}
  :root body .tracking-stats>div{min-width:0;padding:14px}
  :root body .tracking-stats strong{font-size:26px}
  :root body .tracking-note{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  /* "查看日历 ↗" already sits beside 最近七天. */
  :root body .tracking-actions .tracking-calendar{display:none}

  /* Banner child pickers keep room for the name; an open menu sits above the cards below the banner. */
  :root body .frozen-banner-actions>:is(.simple-child-picker,.settings-child-picker,.user-picker){flex:none;width:auto;min-width:128px;max-width:52%}
  :root body .frozen-banner-actions>:is(.simple-child-picker,.settings-child-picker) :is(.user-picker,.user-switcher){width:100%}
  :root body .frozen-banner .user-switcher .user-copy{min-width:0}
  :root body .frozen-banner .user-switcher strong{display:block;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
  :root .frozen-page .frozen-banner:has(details[open],[aria-expanded=true]){z-index:40}
  /* Confirmation dialogs open in the middle of the screen. */
  :root body dialog.delete-child-panel{margin:auto}

  /* Home: the passes go under the title; the category chips stay one row (they slide sideways if they must). */
  :root body .dashboard-grid{grid-template-columns:minmax(0,1fr)}
  :root body .dashboard-grid>*,:root body .tasks-panel .routine-meta{min-width:0}
  :root body .tasks-panel>.section-heading{flex-wrap:wrap;row-gap:12px}
  :root body .tasks-panel .task-pass-cards{flex-basis:100%;flex-wrap:nowrap;gap:8px}
  :root body .tasks-panel .task-pass-cards>*{flex:0 1 66px;min-width:0}
  :root body .tasks-panel .routine-meta{flex-wrap:nowrap}
  :root body .task-filters{flex:1 1 auto;flex-wrap:nowrap;min-width:0;overflow-x:auto;scrollbar-width:none}
  :root body .task-filters::-webkit-scrollbar{display:none}
  :root body .task-filters>button{flex:none}
  /* "1/1 完成" repeats the count at the top of the page and the progress bar under the list. */
  :root body .routine-meta #task-count{display:none}
  /* My family: title and "add" stay on one line. */
  :root body .family-section-heading{flex-wrap:nowrap;gap:10px}
  :root body .family-section-title{min-width:0}
  :root body .family-section-title h2{white-space:nowrap}
  :root body .family-add-button{flex:none;white-space:nowrap}
  :root body:lang(en) #children-count,:root:lang(en) #children-count{display:none}
}
