/* Theme tokens. Light by default, dark follows the system unless the
   toggle has forced a theme through html[data-theme] (see js/theme.js). */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --bg-glow: rgba(99, 102, 241, .14);
  --surface: #ffffff;
  --border: #e3e5ea;
  --text: #15171c;
  --muted: #646b78;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --ring: rgba(79, 70, 229, .35);
  --danger: #c2413b;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 12px 32px -12px rgba(16, 24, 40, .14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0d10;
    --bg-glow: rgba(129, 140, 248, .12);
    --surface: #15171c;
    --border: #262a32;
    --text: #e8eaee;
    --muted: #8b93a1;
    --accent: #818cf8;
    --accent-text: #0c0d10;
    --ring: rgba(129, 140, 248, .4);
    --danger: #f08a84;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0d10;
  --bg-glow: rgba(129, 140, 248, .12);
  --surface: #15171c;
  --border: #262a32;
  --text: #e8eaee;
  --muted: #8b93a1;
  --accent: #818cf8;
  --accent-text: #0c0d10;
  --ring: rgba(129, 140, 248, .4);
  --danger: #f08a84;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .6);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5; text-align: center;
  color: var(--text);
  background:
    radial-gradient(60rem 40rem at 50% -10%, var(--bg-glow), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

/* Card shared by both pages. Centred on the viewport rather than in the
   body, so elements that extensions inject into <body> can't shift it. */
body > form, main {
  position: fixed; inset: 0; margin: auto;
  height: fit-content;
  width: min(22rem, 100% - 3rem);
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow);
}

/* Login form (index.php) */
body > form { display: flex; flex-direction: column; gap: .75rem; }
input, button {
  font: inherit; padding: .7rem .9rem;
  border-radius: .6rem;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease, transform .1s ease;
}
input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
}
input::placeholder { color: var(--muted); }
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
button[type="submit"] {
  background: var(--accent); color: var(--accent-text);
  border: 0; font-weight: 600; cursor: pointer;
}
button[type="submit"]:hover { filter: brightness(1.08); }
button[type="submit"]:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }
/* Out of the flow, under the card, so an error doesn't resize or move it. */
.err {
  position: absolute; top: calc(100% + .75rem); left: 0; right: 0;
  color: var(--danger); margin: 0; font-size: .9rem;
}

/* Menu page (menu.php) */
main {
  width: min(32rem, 100% - 3rem); padding: 2.5rem 2rem;
  /* Many apps: scroll inside the card instead of off screen. */
  max-height: calc(100% - 2rem); overflow-y: auto;
}
h1 { font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.2; letter-spacing: -.02em; margin: 0 0 .5rem; }
p { color: var(--muted); margin: 0; }
main a {
  display: inline-block; margin-top: 2rem;
  color: var(--muted); font-size: .85rem; text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: color .15s ease, border-color .15s ease;
}
main a:hover { color: var(--accent); border-color: var(--accent); }

/* App grid: one tile (a submit button posting the app name) per app. */
.apps {
  display: grid; gap: .75rem; margin-top: 1.5rem;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
}
.apps button[type="submit"] {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: 1rem .5rem .75rem;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); font-weight: 500;
}
.apps button[type="submit"]:hover { filter: none; border-color: var(--accent); }
.apps img, .apps .placeholder {
  width: 3.5rem; height: 3.5rem; border-radius: .8rem; object-fit: contain;
}
.apps .placeholder {
  display: grid; place-items: center;
  font-size: 1.5rem; font-weight: 700;
  color: var(--accent-text); background: var(--accent);
}
.apps .label { font-size: .85rem; line-height: 1.2; overflow-wrap: anywhere; }

/* Theme toggle, top right */
.theme-toggle {
  position: fixed; top: 1rem; right: 1rem;
  display: grid; place-items: center;
  width: 2.5rem; height: 2.5rem; padding: 0;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  box-shadow: var(--shadow); cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 1.15rem; height: 1.15rem; }
/* Show the sun in dark mode (click for light) and the moon in light mode. */
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
