:root {
  color-scheme: light;
  --canvas: #f5f5f8;
  --surface: #fff;
  --line: #dedee6;
  --text: #20202b;
  --muted: #595968;
  --primary: #4e3a90;
  --primary-text: #fff;
  --selected: #eae4fc;
  --selected-text: #372564;
  --focus: #6045b1;
  --danger: #941934;
  font: 100%/1.5 system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { color-scheme: dark; }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #17171e;
  --surface: #202029;
  --line: #383845;
  --text: #f3f2f8;
  --muted: #b8b6c5;
  --primary: #ccb8ff;
  --primary-text: #251735;
  --selected: #3c3156;
  --selected-text: #e4d8ff;
  --focus: #c3abff;
  --danger: #ff9eac;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100svh; background: var(--canvas); color: var(--text); }
a { color: inherit; }
button, input { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.13; letter-spacing: -.04em; }
h2 { font-size: 1.1rem; line-height: 1.2; letter-spacing: -.015em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

.topbar { border-bottom: 1px solid var(--line); background: var(--surface); padding-top: env(safe-area-inset-top); }
.top-inner, .dashboard { max-width: 74rem; margin-inline: auto; padding-inline: clamp(.75rem, 4vw, 2rem); }
.top-inner { min-height: 4rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 750; white-space: nowrap; text-decoration: none; }
.brand img { width: 1.75rem; height: 1.75rem; border-radius: .42rem; }
.actions { display: flex; align-items: center; gap: .25rem; }
.action { min-height: 2.75rem; border: 0; border-radius: .55rem; background: transparent; color: var(--text); padding: .35rem .62rem; white-space: nowrap; }
.action:hover, .chip:hover { background: var(--canvas); }
.theme { min-width: 2.75rem; font-size: 1.1rem; }
.dashboard { padding-top: clamp(1.25rem, 4vw, 2.25rem); padding-bottom: max(2rem, env(safe-area-inset-bottom)); }
.dashboard-title { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .4rem 1rem; }
.dashboard-title p, .empty, .sign-in p, dialog p { color: var(--muted); font-size: .95rem; }
.filters { margin-top: 1rem; }
.filters input, .password-field { width: 100%; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); color: var(--text); min-height: 3rem; }
.filters input { padding: .65rem .85rem; max-width: 33rem; }
.filters input::placeholder { color: var(--muted); }
.categories { display: flex; gap: .45rem; overflow-x: auto; padding: .75rem .2rem .45rem; margin-inline: -.2rem; scrollbar-width: thin; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 2rem; min-height: 2.75rem; padding: .4rem .85rem; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--selected); color: var(--selected-text); border-color: transparent; font-weight: 650; }
.group { margin-top: 1.6rem; }
.group h2 { margin-bottom: .65rem; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .55rem; }
.tile { min-width: 0; min-height: 4.25rem; padding: .55rem .65rem; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .55rem; border: 1px solid var(--line); border-radius: .8rem; background: var(--surface); text-decoration: none; }
.tile:hover { border-color: var(--focus); }
.tile-text { min-width: 0; }
.tile strong, .tile small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }
.tile strong { font-size: .9rem; font-weight: 680; }
.tile small { color: var(--muted); font-size: .71rem; margin-top: .14rem; }
.app-icon { width: 2.35rem; height: 2.35rem; display: grid; place-items: center; border-radius: .58rem; background: var(--selected); font-size: 1.25rem; }
.app-icon > * { grid-area: 1 / 1; }
.app-icon img { width: 1.65rem; height: 1.65rem; object-fit: contain; background: var(--selected); }
.outbound { align-self: start; font-size: .8rem; color: var(--muted); }
.empty { padding-block: 1.2rem; }

.gate { display: grid; place-items: start center; padding: clamp(2rem, 10vh, 7rem) 1rem 2rem; }
.sign-in, dialog { width: min(100%, 26rem); border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); color: var(--text); padding: clamp(1.15rem, 5vw, 2rem); }
.sign-in h1 { margin-top: 1rem; }
.sign-in p, dialog p { margin-top: .6rem; }
.gate-icon { display: block; width: 3.25rem; height: 3.25rem; border-radius: .82rem; }
.sign-in form { margin-top: 1.3rem; }
.sign-in label { display: block; font-weight: 650; margin-bottom: .38rem; }
.password-field { display: flex; align-items: center; padding: .15rem; }
.password-field input { flex: 1; min-width: 0; background: transparent; color: var(--text); border: 0; border-radius: .45rem; padding: .55rem .65rem; }
.sign-in .error { color: var(--danger); }
.primary { display: block; min-height: 2.75rem; margin-top: 1rem; padding: .6rem .9rem; border: 0; border-radius: .65rem; background: var(--primary); color: var(--primary-text); text-align: center; text-decoration: none; font-weight: 700; }
.sign-in button.primary { width: 100%; }
.primary:hover { opacity: .9; }
dialog { max-width: calc(100% - 2rem); }
dialog::backdrop { background: rgb(20 16 30 / 60%); }

@media (max-width: 64rem) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 46rem) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 29rem) {
  .tile { gap: .4rem; padding: .45rem; }
  .app-icon { width: 1.95rem; height: 1.95rem; font-size: 1.1rem; }
  .app-icon img { width: 1.48rem; height: 1.48rem; }
  .tile strong { font-size: .8rem; }
  .tile small { font-size: .66rem; }
  .outbound { display: none; }
}
@media (max-width: 21rem) {
  .brand { font-size: .85rem; gap: .35rem; }
  .action { padding-inline: .35rem; font-size: .78rem; }
  .theme { min-width: 2rem; }
}
