:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --label: #1d1d1f;
  --secondary: #6e6e73;
  --separator: rgba(60, 60, 67, .16);
  --tile: #f5f5f8;
  --track: rgba(120, 120, 128, .16);
  --fill: #007aff;
  --high: #ff9500;
  --full: #ff3b30;
  --active: #34c759;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
  color-scheme: light;
  --app-css: 1;  /* index.html lifts the startup cover only once this applies */
}
/* data-theme is set before first paint (index.html): the saved choice, else the system theme. */
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --label: #f5f5f7;
  --secondary: #98989d;
  --separator: rgba(84, 84, 88, .55);
  --tile: #2c2c2e;
  --track: rgba(120, 120, 128, .28);
  --fill: #0a84ff;
  --high: #ff9f0a;
  --full: #ff453a;
  --active: #30d158;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--label);
  font: 15px/1.5 -apple-system, "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
/* The panel has a fixed size: content scrolls inside it, without a visible scrollbar. */
/* Safe-area insets keep the content clear of the notch, the home indicator and the landscape sensor housing. */
.app { height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; max-width: 460px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
    calc(18px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
h1 {
  margin: 0;
  font: 700 30px/1.1 -apple-system, "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  letter-spacing: -.02em;
}
.top-right { display: flex; align-items: center; gap: 8px; }
.stamp { color: var(--secondary); font-size: 13px; }
.refresh, .theme {
  width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: var(--card); color: var(--label); box-shadow: var(--shadow);
  display: grid; place-items: center; cursor: pointer;
}
.refresh svg, .theme svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.refresh.spin svg { animation: spin .9s linear infinite; }
.refresh:focus-visible, .theme:focus-visible { outline: 3px solid color-mix(in srgb, #0a84ff 60%, transparent); outline-offset: 2px; }
/* Moon in light mode, sun in dark. */
.theme .sun, :root[data-theme="dark"] .theme .moon { display: none; }
:root[data-theme="dark"] .theme .sun { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--card);
  border-radius: 22px;
  padding: 16px 18px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-width: 0; }
.card-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.card-head .note { margin-left: auto; color: var(--secondary); font-size: 12.5px; white-space: nowrap; }
.logo { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.logo svg { width: 18px; height: 18px; }
.logo.claude { background: #d97757; }
.logo.claude svg { fill: #fff8ef; }
.logo.openai { background: #000; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14); }
.logo.openai svg { fill: #fff; width: 17px; height: 17px; }

/* One limit: name and percent used on top, the bar, then the reset time. */
.limits { display: grid; gap: 16px; }
.limit-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.limit-name { font-weight: 500; }
.limit-used { color: var(--secondary); font-size: 14px; white-space: nowrap; }
.limit-used b { color: var(--label); font-weight: 600; }
.meter { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; margin: 8px 0 6px; }
.meter i { display: block; height: 100%; width: 0; border-radius: 4px; background: var(--fill);
  transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.limit.high .meter i { background: var(--high); }
.limit.full .meter i { background: var(--full); }
.limit.full .limit-used b { color: var(--full); }
.limit-reset { color: var(--secondary); font-size: 13px; }

/* Each account is its own tile: a 1px separator renders uneven at fractional display scaling. */
.accounts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.account { padding: 12px 14px 14px; min-width: 0; border-radius: 16px; background: var(--tile); }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 28px; margin-bottom: 10px; }
.who .email { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.who .actions { display: flex; gap: 4px; margin-left: auto; }
.who .actions + .chev { margin-left: 0; }

/* Edit mode (footer button): rename, remove and add; rows stop opening details. */
.rename { flex: none; display: none; place-items: center; width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 8px; background: var(--track); color: var(--label); cursor: pointer; }
.rename svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.editing .rename { display: grid; }
.rename:focus-visible { outline: 2px solid var(--fill); outline-offset: 1px; }
.rename.remove { color: var(--full); }
.editing .who .chev { display: none; }
.editing .account.opens { cursor: default; }
.account.add { display: none; background: none; padding: 4px 0 0; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.editing .account.add { display: flex; }
.add-account { border: 0; border-radius: 999px; padding: 5px 12px; background: var(--track); color: var(--label);
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.add-account:focus-visible { outline: 2px solid var(--fill); outline-offset: 2px; }
.rename-input { min-width: 0; flex: 0 1 220px; font: inherit; font-weight: 600; color: var(--label); background: var(--track);
  border: 0; border-radius: 6px; padding: 2px 6px; margin: -2px 0; outline: 2px solid var(--fill); }
.pill { flex: none; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; line-height: 1.4; }
.pill.on { color: var(--active); background: color-mix(in srgb, var(--active) 15%, transparent); }
.pill.plan { color: var(--secondary); background: var(--track); text-transform: capitalize; }
.err, .empty { color: var(--secondary); font-size: 13px; }
.account .err { margin-top: 10px; overflow-wrap: anywhere; }  /* long paths in errors must wrap */
.empty code { white-space: nowrap; font: 12px "Cascadia Mono", Consolas, monospace; color: var(--label); background: var(--track); padding: 1px 5px; border-radius: 5px; }

/* Cards that open details: the Claude card and each Codex account. */
.opens { cursor: pointer; border-radius: 16px; transition: background-color .15s; }
.opens:focus-visible { outline: 3px solid color-mix(in srgb, #0a84ff 60%, transparent); outline-offset: 4px; }

.bottom { display: flex; justify-content: center; padding: 0 0 4px; }
/* Quiet until needed: faint grey text; "Done" in edit mode is blue so the way out is obvious. */
.edit-btn { border: 0; border-radius: 999px; padding: 4px 12px; background: none; color: var(--secondary);
  font: inherit; font-size: 12.5px; cursor: pointer; opacity: .45; transition: opacity .15s; }
.edit-btn:focus-visible { opacity: 1; }
.editing .edit-btn { color: var(--fill); font-size: 14px; font-weight: 600; opacity: 1; }
.edit-btn:focus-visible { outline: 2px solid var(--fill); outline-offset: 1px; }
.chev { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--secondary); stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round; opacity: .7; }
.card-head .note + .chev { margin-left: 2px; }
.who .chev { margin-left: auto; }

/* Details sheet: slides over the panel from the right while the panel steps back a little (iOS push). */
:root { --push: cubic-bezier(.32, .72, 0, 1); --push-time: .5s; }
.app { transition: transform var(--push-time) var(--push), opacity var(--push-time) var(--push); }
.sheet-open .app { transform: translateX(-22%); opacity: .55; }
.sheet {
  position: fixed; inset: 0; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  transform: translateX(100%); visibility: hidden; box-shadow: -8px 0 32px rgba(0, 0, 0, .08);
  transition: transform var(--push-time) var(--push), visibility 0s var(--push-time);
}
.sheet.open { transform: none; visibility: visible; transition: transform var(--push-time) var(--push); }
.sheet-inner { max-width: 460px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
    calc(18px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
.back {
  display: inline-flex; align-items: center; gap: 2px; margin: 0 0 10px -6px; padding: 4px 8px 4px 2px;
  border: 0; border-radius: 8px; background: none; color: var(--fill); font: inherit; font-size: 15px; cursor: pointer;
}
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.back:focus-visible { outline: 3px solid color-mix(in srgb, #0a84ff 60%, transparent); }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; min-width: 0; }
.sheet-head .logo { width: 36px; height: 36px; border-radius: 9px; }
.sheet-head .logo svg { width: 22px; height: 22px; }
.sheet-names { min-width: 0; }
.sheet-names h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.015em; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-names .note { color: var(--secondary); font-size: 13px; }

.sheet-names { flex: 1; }

/* The selection is one pill that slides between the halves (data-w is set by pickWindow). */
.seg { position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 2px; border-radius: 9px; background: var(--track); margin-bottom: 12px; }
.seg::before { content: ""; position: absolute; top: 2px; bottom: 2px; left: 2px; width: calc(50% - 2px); border-radius: 7px;
  background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); transition: transform .4s var(--push); }
.seg[data-w="10080"]::before { transform: translateX(100%); }
.seg button { position: relative; border: 0; border-radius: 7px; padding: 5px 0; background: none; color: var(--secondary);
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: color .2s; }
.seg button[aria-checked="true"] { color: var(--label); }
.seg button:focus-visible { outline: 2px solid var(--fill); outline-offset: -2px; }

/* Old numbers stay, dimmed, until the other window's numbers arrive. */
#sheet-body { transition: opacity .25s ease; }
#sheet-body.stale { opacity: .45; }

/* Edit mode: its buttons fade and grow in instead of popping. */
@keyframes appear { from { opacity: 0; transform: scale(.85); } }
.edit-enter .rename, .edit-enter .phone-setup, .edit-enter .account.add { animation: appear .28s var(--push) both; }

.total-used { font: 700 28px/1.15 -apple-system, "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif; letter-spacing: -.02em; }
.total-used span { font-size: 15px; font-weight: 500; color: var(--secondary); letter-spacing: 0; margin-left: 4px; }
.total-meta { color: var(--secondary); font-size: 13px; margin-top: 2px; }

.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.group h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--secondary); text-transform: uppercase; letter-spacing: .04em; }
.group-legend { color: var(--secondary); font-size: 12px; white-space: nowrap; }
/* minmax(0, 1fr): long chat titles shrink to an ellipsis instead of widening the card */
.uses { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.use-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; min-width: 0; }
.use-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.use-value { flex: none; color: var(--secondary); font-size: 13px; white-space: nowrap; }
.use-value b { color: var(--label); font-weight: 600; font-size: 14px; }
.mini { height: 5px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 5px; }
.mini i { display: block; height: 100%; min-width: 2px; border-radius: 3px; background: var(--fill); }
.use.top1 .use-name { font-weight: 600; }
.use.quiet .use-name, .use.quiet .use-value b { color: var(--secondary); font-weight: 500; }
.use.quiet .mini i { background: color-mix(in srgb, var(--secondary) 55%, transparent); }

.other summary { list-style: none; cursor: pointer; }
.other summary::-webkit-details-marker { display: none; }
.other summary .use-name::after { content: " \203A"; display: inline-block; margin-left: 2px; transition: transform .15s; }
.other[open] summary .use-name::after { transform: rotate(90deg); }
.other ol { list-style: none; margin: 10px 0 0; padding: 0 0 0 12px; border-left: 2px solid var(--separator); display: grid; gap: 6px; }
.other li { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--secondary); min-width: 0; }
.other li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.other li span:last-child { flex: none; }

.foot { color: var(--secondary); font-size: 12px; line-height: 1.45; margin: 4px 4px 0; }

/* ---------- pointer and touch ---------- */

/* Hover looks only where there is a mouse: on iOS a :hover rule turns the first tap into a hover. */
@media (hover: hover) {
  .rename:hover { background: color-mix(in srgb, var(--track) 70%, var(--label)); }
  .add-account:hover { background: color-mix(in srgb, var(--track) 80%, var(--label)); }
  .card.opens:hover { background: color-mix(in srgb, var(--card) 94%, var(--label)); }
  .account.opens:hover { background: color-mix(in srgb, var(--tile) 96%, var(--label)); }
  .account.opens:hover .email { color: var(--fill); }
  .editing .account.opens:hover { background: var(--tile); }
  .editing .account.opens:hover .email { color: inherit; }
  .edit-btn:hover { opacity: 1; }
  .editing .edit-btn:hover, .phone-setup:hover { background: var(--track); }
}
button, .opens { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* A press shows at once on touch, like a table row in iOS. */
@media (hover: none) {
  .card.opens:active { background: color-mix(in srgb, var(--card) 92%, var(--label)); }
  .account.opens:active { background: color-mix(in srgb, var(--tile) 92%, var(--label)); }
  .editing .account.opens:active { background: var(--tile); }
  .refresh:active, .theme:active, .rename:active { opacity: .6; }
}
/* Fingers need bigger targets than a mouse; 16px inputs keep iOS from zooming in on focus. */
@media (pointer: coarse) {
  .refresh, .theme { width: 36px; height: 36px; }
  .rename { width: 36px; height: 36px; border-radius: 10px; }
  .who .actions { gap: 8px; }
  .rename-input { font-size: 16px; }
  .edit-btn { padding: 10px 18px; font-size: 14px; opacity: .6; }
  .back { padding: 8px 10px 8px 2px; }
  .seg button { padding: 8px 0; }
}

/* ---------- iPhone setup (PC) ---------- */

.phone-setup { display: none; border: 0; border-radius: 999px; padding: 4px 12px; background: none; color: var(--fill);
  font: inherit; font-size: 14px; cursor: pointer; }
.editing .phone-setup { display: inline-block; }
.phone .phone-setup { display: none; }
.phone-setup:focus-visible { outline: 2px solid var(--fill); outline-offset: 1px; }
.pairing { width: min(340px, calc(100vw - 32px)); border: 0; border-radius: 22px; padding: 22px 20px 18px;
  background: var(--card); color: var(--label); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); text-align: center; }
.pairing::backdrop { background: rgba(0, 0, 0, .35); }
.pairing h2 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.pairing p { margin: 0; color: var(--secondary); font-size: 13.5px; line-height: 1.45; }
.pairing-url { display: block; margin: 8px 0 0; color: var(--fill); font-weight: 600; overflow-wrap: anywhere; text-decoration: none; }
.pairing-code { margin: 16px 0 4px; font: 600 34px/1.1 -apple-system, "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  letter-spacing: .08em; user-select: all; }
.pairing .pairing-hint { margin-top: 12px; font-size: 12.5px; }
.pairing-actions { display: grid; gap: 8px; margin-top: 18px; }

/* Pills: blue is the action, quiet is the alternative (University OS, Codex and GPT Images sign-in). */
.pill-blue, .pill-quiet { border-radius: 999px; padding: 11px 18px; font: inherit; font-weight: 600; cursor: pointer; }
.pill-blue { border: 0; background: var(--fill); color: #fff; }
.pill-quiet { border: 1px solid var(--separator); background: transparent; color: var(--label); font-weight: 500; }
.pill-blue:disabled, .pill-quiet:disabled { opacity: .5; cursor: default; }
.pill-blue:focus-visible, .pill-quiet:focus-visible { outline: 3px solid color-mix(in srgb, #0a84ff 60%, transparent); outline-offset: 2px; }
@media (hover: hover) {
  .pill-blue:not(:disabled):hover { background: color-mix(in srgb, var(--fill) 88%, #000); }
  .pill-quiet:not(:disabled):hover { background: var(--track); }
}

/* ---------- sign-in (phone) ---------- */

.login-body { overflow: auto; }
.login { box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; width: min(340px, 100%);
  min-height: 100dvh; margin: 0 auto; text-align: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
.login.pending { visibility: hidden; }
.login-icon { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 15px; }
.login h1 { margin: 0; font: 700 28px/1.15 -apple-system, "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif; letter-spacing: -.02em; }
.login-hint { margin: 8px 0 22px; color: var(--secondary); font-size: 14px; white-space: pre-line; text-wrap: balance; }
.login .pill-blue, .login .pill-quiet { width: 100%; }
.login-note { margin: 8px 0 0; color: var(--full); font-size: 13px; text-wrap: balance; }
.login-or { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--secondary); font-size: 13px; }
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--separator); }
.login form { display: grid; gap: 12px; }
.login input { box-sizing: border-box; width: 100%; padding: 11px 14px; border: 1px solid var(--separator); border-radius: 12px;
  background: var(--card); color: var(--label); font: inherit; font-size: 16px; outline: none; }
.login input::placeholder { color: var(--secondary); }
.login input:focus { border-color: var(--fill); }
.login-issue { margin-top: 18px; padding: 16px; border-radius: 16px; background: var(--card); }
.login-issue p { margin: 0 0 12px; color: var(--secondary); font-size: 14px; }
.login-dots { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; gap: 9px; pointer-events: none; }
.login-dots span { width: 10px; height: 10px; border-radius: 50%; background: #8e8e93; animation: login-dot 1.2s ease-in-out infinite; }
.login-dots span:nth-child(2) { animation-delay: .15s; }
.login-dots span:nth-child(3) { animation-delay: .3s; }
.login:not(.pending) ~ .login-dots { display: none; }
@keyframes login-dot { 0%, 70%, 100% { opacity: .25; } 35% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .login-dots span { animation: none; opacity: .6; }
  .meter i { transition: none; }
  .refresh.spin svg { animation: none; }
  .sheet, .sheet.open, .app { transition: none; }
  .sheet-open .app { transform: none; }
  .edit-enter .rename, .edit-enter .phone-setup, .edit-enter .account.add { animation: none; }
  .seg::before, .seg button, #sheet-body { transition: none; }
}
