:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --secondary: #f2f2f7;
  --input-bg: #f8f8fa;
  --ink: #1d1d1f;
  --muted: #64646a;
  --line: #e5e5ea;
  --blue: #007aff;
  --blue-label: #0066d8;
  --blue-dark: #0066d8;
  --primary-fill: #0066d8;
  --blue-soft: #e8f2ff;
  --danger: #c92d2d;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100vh; margin: 0; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell { max-width: 1040px; min-height: 100vh; margin: auto; padding: 0 32px; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: calc(76px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: var(--bg); }
.brand-mark { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 11px; background: #ff3b30; color: white; font-size: 23px; line-height: 1; font-weight: 780; letter-spacing: -.08em; }
.brand-name { font-size: 19px; font-weight: 750; letter-spacing: -.035em; }
.support-links { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.support-link { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 13px; background: var(--secondary); text-decoration: none; }
.support-link:hover { background: var(--blue-soft); }
.support-link img { display: block; width: 28px; height: 28px; object-fit: contain; }
.text-button { min-width: 64px; min-height: 44px; padding: 0 8px; border: 0; background: transparent; color: var(--blue-label); font-size: 16px; font-weight: 600; }
.text-button:hover { color: var(--blue-dark); }

main { flex: 1; }
.login-layout { min-height: min(760px, calc(100vh - 150px)); display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 420px); align-items: center; gap: 64px; padding: 64px 0 80px; }
.hero { max-width: 510px; }
.step-label { color: var(--blue-label); font-size: 12px; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
.hero h1 { margin: 14px 0 20px; font-size: clamp(42px, 4.5vw, 56px); line-height: 1.08; font-weight: 760; letter-spacing: -.055em; }
.hero h1 em { font-style: normal; }
.hero p { max-width: 430px; margin: 0; color: var(--muted); font-size: 18px; line-height: 1.45; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 12px 36px rgba(0,0,0,.055); }
.login-panel { padding: 32px; }
.login-panel h2 { margin: 10px 0 7px; font-size: 28px; line-height: 1.2; font-weight: 720; letter-spacing: -.035em; }
.panel-intro { margin: 0 0 24px; color: var(--muted); font-size: 15px; line-height: 1.4; }
form label { display: block; margin: 18px 0 8px; font-size: 15px; font-weight: 650; }
input { appearance: none; width: 100%; min-height: 52px; padding: 13px 16px; border: 1px solid var(--line); border-radius: 12px; outline: 0; background: var(--input-bg); color: var(--ink); font-size: 17px; }
input::placeholder { color: var(--muted); opacity: .8; }
input:focus-visible { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(0,122,255,.16); }
.field-hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.verification-copy { margin: 18px 0 0; color: var(--muted); font-size: 16px; line-height: 1.45; }
.code-help { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.code-help summary { width: fit-content; min-height: 44px; padding: 11px 0; color: var(--blue-label); font-weight: 650; cursor: pointer; }
.code-help summary:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.code-help p { margin: 5px 0 10px; }
.code-help a { color: var(--blue-label); }
.retry-password { min-height: 44px; margin-top: 2px; padding: 0; border: 0; background: transparent; color: var(--blue-label); font-size: 14px; font-weight: 650; }
.primary-button { width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; margin-top: 28px; padding: 0 18px; border: 0; border-radius: 13px; background: var(--primary-fill); color: white; font-size: 17px; font-weight: 680; }
.primary-button:hover { filter: brightness(.92); }
.primary-button span:last-child { font-size: 22px; line-height: 1; font-weight: 400; }
.message { min-height: 1.2em; margin: 12px 0 0; color: var(--danger); font-size: 14px; line-height: 1.4; }

.library-view { padding: 48px 0 80px; }
.library-heading h1 { margin: 8px 0 10px; font-size: clamp(38px, 4.2vw, 52px); line-height: 1.1; font-weight: 760; letter-spacing: -.05em; }
.account-line { margin: 0; color: var(--muted); font-size: 16px; }
.library-description { max-width: 680px; margin: 12px 0 0; color: var(--muted); font-size: 15px; line-height: 1.45; }
.restore-guidance { display: flex; align-items: flex-start; gap: 12px; margin: 20px 0 0; padding: 16px; border-radius: 16px; background: var(--blue-soft); }
.restore-guidance-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 11px; background: var(--primary-fill); color: #fff; font-size: 25px; line-height: 1; font-weight: 600; }
.restore-guidance p { margin: 0; color: var(--ink); font-size: 15px; line-height: 1.45; }
.restore-guidance strong { display: block; margin-bottom: 3px; font-size: 16px; line-height: 1.3; }
.library-controls { display: flex; gap: 12px; margin: 24px 0 18px; }
.catalog-filter-section { margin-bottom: 8px; }
.filter-label { margin: 0 0 8px; color: var(--muted); font-size: 13px; font-weight: 650; }
.catalog-filter { width: fit-content; max-width: 100%; display: flex; align-items: stretch; gap: 10px; }
.catalog-filter-button { min-height: 48px; padding: 9px 16px; border: 1.5px solid var(--muted); border-radius: 12px; background: var(--surface); color: var(--ink); font-size: 15px; font-weight: 650; white-space: normal; line-height: 1.2; text-align: center; transition: background-color .2s ease, border-color .2s ease, box-shadow .2s ease, transform .2s ease; }
.catalog-filter-button:not(.is-active):hover { background: var(--secondary); border-color: var(--blue); }
.catalog-filter-button.is-active { background: var(--primary-fill); border-color: var(--primary-fill); color: #fff; box-shadow: 0 3px 10px rgba(0,102,216,.22); }
.catalog-filter-button.is-active::before { content: "✓"; display: inline-block; margin-right: 7px; font-weight: 800; }
.catalog-note { margin: 8px 0 12px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.search-field { flex: 1; position: relative; display: block; }
.search-field span { position: absolute; left: 17px; top: 50%; transform: translateY(-53%); color: var(--muted); font-size: 27px; line-height: 1; pointer-events: none; }
.search-field input { min-height: 50px; padding-left: 49px; border: 0; border-radius: 13px; background: var(--secondary); font-size: 17px; }
.secondary-button { min-height: 48px; padding: 0 19px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); color: var(--ink); font-size: 15px; font-weight: 650; }
.secondary-button:hover { background: var(--secondary); }
.refresh-symbol { display: none; }
.list-summary { min-height: 32px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; margin-bottom: 8px; color: var(--muted); font-size: 15px; font-weight: 550; }
.list-status { font-size: 13px; line-height: 1.35; }
.list-status.is-complete { color: var(--ink); }
.list-status.is-warning { color: var(--danger); }
.list-progress { height: 4px; overflow: hidden; margin-bottom: 18px; border-radius: 999px; background: var(--secondary); }
.list-progress-fill { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--blue); transition: width .3s ease; }
.app-list { display: grid; gap: 10px; }
.app-row { min-height: 110px; display: flex; align-items: center; gap: 18px; padding: 17px 18px; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); }
.app-icon { width: 72px; height: 72px; flex: none; position: relative; overflow: hidden; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 17px; background: var(--blue); color: white; font-size: 32px; font-weight: 750; }
.app-icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.app-info { min-width: 0; flex: 1; }
.app-name { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 19px; line-height: 1.25; font-weight: 690; letter-spacing: -.018em; overflow-wrap: anywhere; }
.app-name.has-brand { -webkit-line-clamp: 4; }
.row-button { min-width: 116px; min-height: 44px; flex: none; padding: 0 16px; border: 0; border-radius: 999px; background: var(--blue-soft); color: var(--blue-label); font-size: 15px; font-weight: 740; }
.row-button:hover { background: rgba(0,122,255,.17); }
.empty { padding: 42px 24px; border-radius: 19px; background: var(--secondary); color: var(--muted); font-size: 16px; line-height: 1.45; text-align: center; }
.empty .direct-action { margin: 18px auto 0; }
.footnote { max-width: 750px; margin: 24px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.footer { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.footer span:first-child { color: var(--ink); font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 10; width: min(520px, calc(100% - 32px)); transform: translateX(-50%); padding: 16px 18px; border-radius: 15px; background: var(--ink); color: var(--bg); box-shadow: 0 12px 32px rgba(0,0,0,.18); font-size: 15px; line-height: 1.45; }

.install-ring { width: 48px; height: 48px; min-width: 48px; flex: none; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 2px solid var(--blue); border-radius: 50%; background: var(--surface); color: var(--blue); font: 700 27px/1 system-ui, sans-serif; text-decoration: none; }
.install-ring--busy { border-color: var(--line); }
.install-ring--busy::before { content: ""; width: 25px; height: 25px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: install-spin .8s linear infinite; }
.install-ring--ready { background: var(--primary-fill); color: white; }
.install-ring--retry { font-size: 26px; }
.install-status { margin-top: 6px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.install-status--error { color: var(--danger); }
@keyframes install-spin { to { transform: rotate(360deg); } }

button:focus-visible, a:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
@media (prefers-reduced-motion: no-preference) { button, a { transition: background-color .2s ease, transform .2s ease; } button:active { transform: scale(.98); } }
@media (prefers-reduced-motion: reduce) { .install-ring--busy::before { animation: none; border-color: var(--blue); } }

@media (max-width: 800px) {
  .app-shell { padding: 0 20px; }
  .topbar { height: calc(68px + env(safe-area-inset-top)); }
  .login-layout { min-height: auto; grid-template-columns: 1fr; gap: 34px; padding: 44px 0 60px; }
  .login-layout.is-verification { padding-top: 24px; }
  .login-layout.is-verification .hero { display: none; }
  .hero h1 { font-size: 44px; }
  .login-panel { max-width: 520px; }
  .library-view { padding-top: 38px; }
}

@media (max-width: 520px) {
  .app-shell { padding: 0 16px; }
  .topbar { height: calc(62px + env(safe-area-inset-top)); gap: 8px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 10px; font-size: 21px; }
  .brand-name { font-size: 18px; }
  .login-layout { gap: 28px; padding: 28px 0 48px; }
  .hero h1 { margin: 9px 0 12px; font-size: 37px; }
  .hero p { font-size: 16px; }
  .login-panel { padding: 22px 20px; border-radius: 21px; }
  .login-panel h2 { font-size: 25px; }
  .panel-intro { margin-bottom: 18px; }
  .library-view { padding: 30px 0 56px; }
  .library-heading h1 { font-size: 36px; }
  .library-controls { gap: 8px; margin: 28px 0 14px; }
  .catalog-filter { width: 100%; }
  .catalog-filter-button { flex: 1; min-width: 0; min-height: 52px; padding: 6px 8px; font-size: 14px; }
  .library-controls .secondary-button { padding: 0 12px; font-size: 14px; }
  .search-field input { font-size: 16px; }
  .app-row { min-height: 100px; gap: 12px; padding: 13px 12px; border-radius: 17px; }
  .app-icon { width: 64px; height: 64px; border-radius: 15px; font-size: 29px; }
  .app-name { font-size: 17px; }
  .row-button { min-width: 93px; padding: 0 10px; font-size: 13px; }
  .footer span:last-child { display: none; }
}

@media (max-width: 360px) {
  .brand-name { display: none; }
  .library-controls .secondary-button { width: 48px; min-width: 48px; padding: 0; display: grid; place-items: center; }
  .refresh-symbol { display: block; font-size: 25px; line-height: 1; }
  .refresh-label { display: none; }
  .app-row { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px 12px; min-height: 122px; }
  .app-icon { grid-column: 1; grid-row: 1 / 3; }
  .app-info { grid-column: 2; grid-row: 1; }
  .app-row > .row-button, .app-row > .install-ring { grid-column: 2; grid-row: 2; justify-self: start; }
}

@media (max-width: 800px) and (max-height: 620px) {
  .login-layout { padding-top: 16px; }
  .login-layout .hero { display: none; }
  .login-layout.is-verification .step-label,
  .login-layout.is-verification .panel-intro { display: none; }
  .login-layout.is-verification .login-panel h2 { margin-top: 0; }
}

@media (max-width: 320px) and (max-height: 620px) {
  .login-layout.is-verification .login-panel { padding-top: 14px; }
  .login-layout.is-verification form label { margin-top: 14px; }
  .login-layout.is-verification .primary-button { margin-top: 12px; }
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg: #000000; --surface: #1c1c1e; --secondary: #1c1c1e; --input-bg: #2c2c2e; --ink: #f5f5f7; --muted: #aeaeb2; --line: #38383a; --blue: #0a84ff; --blue-label: #409cff; --blue-dark: #409cff; --primary-fill: #0a66c2; --blue-soft: #152a3f; --danger: #ff6961; }
  .panel { box-shadow: none; }
  .search-field input { background: var(--secondary); }
  .app-row { background: var(--surface); }
  .toast { background: #2c2c2e; color: var(--ink); }
}
@media (prefers-reduced-motion: reduce) {
  .list-progress-fill, .catalog-filter-button { transition: none; }
}
