:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d1b22;
  --muted: #6b6875;
  --border: #e4e0d8;
  --accent: #5a4fcf;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(20, 16, 40, 0.05), 0 6px 20px rgba(20, 16, 40, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161c;
    --surface: #221f2a;
    --text: #eeebf3;
    --muted: #a19cad;
    --border: #34303e;
    --accent: #948bf2;
    --accent-text: #14121a;
    --danger: #f2b8b5;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 960px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-weight: 700;
  text-decoration: none;
}

.brand img { width: 28px; height: 28px; }

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 16px calc(48px + env(safe-area-inset-bottom));
}

h1 {
  margin: 16px 0 4px;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.lede { margin: 0 0 24px; color: var(--muted); }

/* App selector */

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-tile {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 84px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.12s, transform 0.12s;
}

.app-tile:hover { border-color: var(--accent); }
.app-tile:active { transform: scale(0.98); }
.app-tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

img.app-icon { background: none; }

.app-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--tile-color, var(--accent));
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 700;
}

.app-text { display: flex; flex-direction: column; min-width: 0; }
.app-name { font-weight: 600; }
.app-desc { color: var(--muted); font-size: 0.9rem; line-height: 1.35; }

/* Cards, forms, buttons */

.card {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login, .message { max-width: 380px; margin: 8vh auto 0; }
.login h1, .message h1 { margin-top: 0; margin-bottom: 16px; }

label { display: block; margin-bottom: 6px; font-weight: 600; }

input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
}

input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.button {
  width: 100%;
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.button:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

.error { margin: 0 0 12px; color: var(--danger); }

.link-button {
  padding: 8px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.link-button:hover { color: var(--text); }

.back {
  display: inline-block;
  padding: 4px 0;
  color: var(--muted);
  text-decoration: none;
}

.back:hover { color: var(--text); }

/* Shared form controls */

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
}

.pill-button {
  display: inline-block;
  flex: none;
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.pill-button:hover { border-color: var(--accent); }
.pill-button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
