/*
 * app.css - the whole look of the LingoWorks web app shell.
 *
 * The palette, radii and type scale are the Android app's own (Theme.kt: Brand, GameColors, LightScheme, DarkScheme,
 * Radius 8/16/24/full, the "glow" shadow tinted with the element's colour), as CSS custom properties, light and dark.
 * Dark follows the system (prefers-color-scheme) unless the learner chose a theme: js/frame.js then sets data-theme on
 * <html>, which wins either way.
 *
 * Layout: NO width media queries here. js/layout.js (the one layout table) sets data-layout (compact / medium /
 * expanded) on <html>, and js/frame.js sets data-nav (tabbar / rail / sidebar) and data-frame (on / off) on .shell;
 * this file only reacts to those attributes. The content widths come from variables the layout sets (--content-max,
 * --lesson-max, --option-cols).
 *
 * Sections: 1 tokens - 2 base - 3 shell (top bar, sidebar, rail, tab bar) - 4 components - 5 screens (bare page,
 * placeholder) - 6 motion.
 * Fonts: the app's Roboto (Apache-2.0, fonts/LICENSE-Roboto.txt), subset to Latin + German + Albanian as WOFF.
 * No inline styles anywhere (the CSP forbids them); dynamic values are set through the CSSOM.
 */

/* ------------------------------------------------------------------ 1. Tokens (Theme.kt) */
@font-face { font-family: "Roboto"; src: url("../fonts/Roboto-Regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Roboto"; src: url("../fonts/Roboto-Medium.woff") format("woff"); font-weight: 500 600; font-display: swap; }
@font-face { font-family: "Roboto"; src: url("../fonts/Roboto-Bold.woff") format("woff"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Roboto"; src: url("../fonts/Roboto-Black.woff") format("woff"); font-weight: 800 900; font-display: swap; }

:root {
  /* Brand (Theme.kt Brand) */
  --violet: #6A4BE3; --violet-dark: #4E33B8; --violet-light: #B9A8FF; --wing: #3B2C86;
  --amber: #FFC94D; --amber-light: #FFE58A; --amber-deep: #A35F00;
  --teal: #0B7F72; --teal-dark: #07665C; --coral: #C0392B; --coral-dark: #A5301F;
  --sky: #1F78C8; --plum: #8E3C8C; --ink: #2B2350; --night: #17142A; --blush: #FF9C8F;

  /* LightScheme + LightGame */
  --bg: #FBF7FF; --on-bg: #2B2350; --surface: #FFFFFF; --surface-low: #F7F3FE; --surface-c: #F3EEFC; --surface-high: #ECE6F8;
  --surface-var: #EDE8F7; --on-var: #5B5478; --outline: #7F76A8; --outline-var: #CFC7E6;
  --primary: var(--violet); --on-primary: #fff; --primary-c: #E8E1FF; --on-primary-c: var(--ink);
  --secondary-c: #FFEFC7; --on-secondary-c: var(--ink);
  --correct: var(--teal-dark); --correct-bg: #D7F5F0; --wrong: var(--coral-dark); --wrong-bg: #FFE3DF;
  --scene-a: #EFE8FF; --scene-b: #FFF4D6;

  /* Shape and type (Radius S/M/L, AppTypography) */
  --r-s: 8px; --r-m: 16px; --r-l: 24px; --r-xl: 32px;
  --font: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.08rem);
  --step-1: clamp(1.1rem, 1rem + 0.45vw, 1.35rem);
  --step-2: clamp(1.35rem, 1.15rem + 0.9vw, 1.9rem);
  --step-3: clamp(1.75rem, 1.4rem + 1.6vw, 2.8rem);

  /* Set by js/layout.js from the layout table; these are only the values before it has run. */
  --content-max: 720px; --lesson-max: 640px; --option-cols: 2;
  --sidebar: 248px; --rail: 88px; --topbar: 60px; --tabbar: 68px;
  color-scheme: light;
}

/* Dark: the app's DarkScheme + DarkGame. Same values twice: for the system preference and for the learner's choice. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17142A; --on-bg: #EDE8FF; --surface: #211D36; --surface-low: #1B1830; --surface-c: #211D36; --surface-high: #2A2544;
    --surface-var: #2A2544; --on-var: #C4BDE0; --outline: #7F77B4; --outline-var: #4B4470;
    --primary: var(--violet-light); --on-primary: var(--ink); --primary-c: #3B2C86; --on-primary-c: #E8E1FF;
    --secondary-c: #5A4512; --on-secondary-c: #FFEFC7;
    --correct: #5FE0CF; --correct-bg: #113A36; --wrong: #FF8F82; --wrong-bg: #45201D;
    --scene-a: #231E3F; --scene-b: #2B2240;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17142A; --on-bg: #EDE8FF; --surface: #211D36; --surface-low: #1B1830; --surface-c: #211D36; --surface-high: #2A2544;
  --surface-var: #2A2544; --on-var: #C4BDE0; --outline: #7F77B4; --outline-var: #4B4470;
  --primary: var(--violet-light); --on-primary: var(--ink); --primary-c: #3B2C86; --on-primary-c: #E8E1FF;
  --secondary-c: #5A4512; --on-secondary-c: #FFEFC7;
  --correct: #5FE0CF; --correct-bg: #113A36; --wrong: #FF8F82; --wrong-bg: #45201D;
  --scene-a: #231E3F; --scene-b: #2B2240;
  color-scheme: dark;
}

/* ------------------------------------------------------------------ 2. Base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--step-0); line-height: 1.45; color: var(--on-bg);
  background: radial-gradient(1200px 600px at 85% -10%, color-mix(in srgb, var(--violet) 12%, transparent), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, color-mix(in srgb, var(--amber) 14%, transparent), transparent 60%),
              var(--bg);
  background-attachment: fixed; min-height: 100dvh;
}
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: var(--step-3); font-weight: 900; }
h2 { font-size: var(--step-2); font-weight: 800; }
h3 { font-size: var(--step-1); font-weight: 700; }
p { margin: 0; }
button, select { font: inherit; color: inherit; }
a { color: inherit; }
kbd {
  font: 600 0.78em var(--font); padding: 0.1em 0.45em; border-radius: 6px; border: 1px solid var(--outline-var);
  background: var(--surface); box-shadow: 0 1px 0 var(--outline-var);
}
/* The focus ring: amber, thick, offset: visible on every surface, light and dark. */
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; border-radius: var(--r-s); }
.skip { position: absolute; left: -999px; top: 8px; z-index: 80; background: var(--surface); padding: 8px 12px; border-radius: var(--r-s); }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--on-var); }
.ico { width: 26px; height: 26px; flex: none; fill: currentColor; }

/* ------------------------------------------------------------------ 3. Shell */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; grid-template-rows: auto 1fr; min-height: 100dvh; }
.shell[data-nav="sidebar"][data-frame="on"] { grid-template-columns: var(--sidebar) minmax(0, 1fr); grid-template-areas: "side main"; grid-template-rows: 1fr; }
.shell[data-nav="rail"][data-frame="on"] { grid-template-columns: var(--rail) minmax(0, 1fr); grid-template-areas: "side main"; grid-template-rows: 1fr; }
.topbar { grid-area: top; position: sticky; top: 0; z-index: 20; height: var(--topbar); display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 0 clamp(12px, 2vw, 32px); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(12px); }
.sidebar {
  grid-area: side; position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 8px; padding: 20px 14px;
  background: color-mix(in srgb, var(--surface-low) 85%, transparent); backdrop-filter: blur(12px);
  border-right: 1px solid var(--outline-var);
}
.view { grid-area: main; min-width: 0; padding: clamp(16px, 2.4vw, 40px); outline: none; }
.shell[data-nav="tabbar"][data-frame="on"] .view { padding-bottom: calc(var(--tabbar) + 28px + env(safe-area-inset-bottom)); }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 4px 8px 16px; }
.brand.small { padding: 0; }
.brand-lumi { width: 56px; height: 56px; animation: bob 2.6s ease-in-out infinite; filter: drop-shadow(0 6px 14px color-mix(in srgb, var(--amber) 55%, transparent)); }
.brand.small .brand-lumi { width: 36px; height: 36px; }
.brand-name { font-weight: 900; font-size: 1.35rem; color: var(--primary); letter-spacing: -0.02em; }
.brand.small .brand-name { font-size: 1.15rem; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: var(--r-m); text-decoration: none;
  font-weight: 600; color: var(--on-var); transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-high); color: var(--on-bg); }
.nav a[aria-current="page"], .tabbar a[aria-current="page"] { color: var(--on-primary-c); }
.nav a[aria-current="page"] { background: var(--primary-c); }
.nav a[aria-current="page"] .ico, .tabbar a[aria-current="page"] .ico { color: var(--primary); filter: drop-shadow(0 0 8px color-mix(in srgb, var(--amber) 70%, transparent)); }
.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }

.tools { display: flex; align-items: center; gap: 8px; }
.sidebar .tools { flex-direction: column; align-items: stretch; }
.sidebar .tools > * { width: 100%; }
.theme-toggle, .lang-picker {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--outline-var); background: var(--surface);
  border-radius: 99px; padding: 8px 14px; cursor: pointer; font-weight: 600; width: fit-content; min-height: 44px;
}
.lang-picker .ico { width: 20px; height: 20px; color: var(--on-var); }
.lang-picker select { border: 0; background: transparent; cursor: pointer; font-weight: 600; padding: 4px 0; }
.lang-picker select option { background: var(--surface); color: var(--on-bg); }

/* Rail: the same sidebar, icons with small labels, no brand name. Scoped to .sidebar: the top bar keeps its own look. */
.shell[data-nav="rail"] .sidebar { padding: 16px 8px; align-items: stretch; }
.shell[data-nav="rail"] .sidebar .brand { justify-content: center; padding-inline: 0; }
.shell[data-nav="rail"] .sidebar .brand-name, .shell[data-nav="rail"] .sidebar .theme-toggle .label { display: none; }
.shell[data-nav="rail"] .sidebar .nav a { flex-direction: column; gap: 4px; padding: 10px 4px; font-size: .72rem; text-align: center; }
.shell[data-nav="rail"] .sidebar .theme-toggle { justify-content: center; padding: 8px; }
.shell[data-nav="rail"] .sidebar .lang-picker { justify-content: center; padding: 8px 4px; }
.shell[data-nav="rail"] .sidebar .lang-picker .ico { display: none; }
.shell[data-nav="rail"] .sidebar .lang-picker select { width: 100%; font-size: .72rem; text-align: center; appearance: none; }
.theme-toggle .label { white-space: nowrap; }
/* Compact top bar: icon-only theme toggle, so the brand keeps its name. */
html[data-layout="compact"] .topbar .theme-toggle .label { display: none; }
html[data-layout="compact"] .topbar .theme-toggle, html[data-layout="compact"] .topbar .lang-picker { padding: 8px 12px; }

/* Tab bar: like the app's HomeBar. */
.tabbar {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; z-index: 30;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface-low) 92%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--outline-var);
}
.tabbar a { display: grid; justify-items: center; gap: 2px; padding: 6px 0; text-decoration: none; font-size: .74rem; font-weight: 600; color: var(--on-var); }

/* ------------------------------------------------------------------ 4. Components */
.btn {
  --c: var(--primary); --on: var(--on-primary);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 0 28px;
  border: 0; border-radius: 99px; cursor: pointer; font-weight: 800; font-size: 1.05rem; letter-spacing: .01em;
  color: var(--on); background: linear-gradient(180deg, color-mix(in srgb, var(--c) 88%, white), var(--c));
  box-shadow: 0 8px 22px -8px color-mix(in srgb, var(--c) 70%, transparent), 0 2px 0 color-mix(in srgb, var(--c) 70%, black) inset;
  transition: transform .12s, box-shadow .12s, filter .12s; text-decoration: none;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.teal { --c: var(--teal); --on: #fff; }
.btn.soft { --c: var(--surface-high); --on: var(--on-bg); box-shadow: none; }
.btn.big { min-height: 60px; font-size: 1.15rem; padding: 0 36px; }
.card {
  background: var(--surface); border-radius: var(--r-l); border: 1px solid color-mix(in srgb, var(--outline-var) 60%, transparent);
  box-shadow: 0 10px 30px -18px color-mix(in srgb, var(--violet) 55%, transparent);
}
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 99px; background: var(--primary-c);
  color: var(--on-primary-c); font-weight: 600; font-size: .95rem;
}
.chip .ico { width: 20px; height: 20px; color: var(--primary); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 160%); visibility: hidden; opacity: 0; z-index: 60;
  display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-radius: 99px; background: var(--ink); color: #fff;
  font-weight: 600; max-width: calc(100vw - 32px); transition: transform .25s, opacity .25s, visibility .25s;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; opacity: 1; }
.shell[data-nav="tabbar"][data-frame="on"] ~ .toast { bottom: calc(var(--tabbar) + 20px + env(safe-area-inset-bottom)); }
.toast-action { border: 0; border-radius: 99px; padding: 8px 16px; cursor: pointer; font-weight: 800; background: var(--amber); color: var(--ink); }
.boot { display: grid; place-items: center; align-content: center; gap: 12px; min-height: 70vh; color: var(--on-var); text-align: center; }
.boot img { animation: bob 2.4s ease-in-out infinite; }
.boot-error { display: grid; gap: 14px; justify-items: center; max-width: 30em; color: var(--on-bg); }

/* ------------------------------------------------------------------ 5. Screens */
/* The bare page (welcome, sign-in, invite): Lumi above one calm card, centred. */
.bare { max-width: 600px; margin: clamp(0px, 3vh, 32px) auto 0; display: grid; justify-items: center; gap: 0; }
.bare-lumi { width: clamp(150px, 26vw, 220px); height: auto; margin-bottom: -28px; position: relative; z-index: 1;
  animation: bob 3s ease-in-out infinite; filter: drop-shadow(0 18px 24px color-mix(in srgb, var(--amber) 45%, transparent)); }
.bare-body {
  width: 100%; display: grid; gap: 18px; justify-items: center; text-align: center; padding: 48px clamp(20px, 5vw, 44px) 36px;
  background: var(--surface); border-radius: var(--r-xl); border: 1px solid color-mix(in srgb, var(--outline-var) 60%, transparent);
  box-shadow: 0 30px 60px -36px color-mix(in srgb, var(--violet) 70%, transparent);
}
.bare .lead { font-size: var(--step-1); color: var(--on-var); }
.bare .actions { display: grid; gap: 12px; width: 100%; max-width: 360px; margin-top: 6px; }
.bare .actions .btn { width: 100%; }
.bare .note { font-size: .92rem; max-width: 34em; }
.methods { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* In-app placeholder screens. */
.page { max-width: var(--content-max); margin: 0 auto; display: grid; gap: 24px; }
.page-head { display: flex; align-items: center; gap: 16px; }
.page-grid { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr); }
.page-grid:has(> .panel) { grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); }
.soon { display: flex; align-items: center; gap: clamp(16px, 3vw, 32px); padding: clamp(20px, 3vw, 36px); background: linear-gradient(135deg, var(--scene-a), var(--scene-b)); }
.soon-lumi { width: clamp(96px, 18vw, 150px); height: auto; flex: none; animation: bob 3s ease-in-out infinite; filter: drop-shadow(0 14px 18px color-mix(in srgb, var(--amber) 40%, transparent)); }
.soon-text { display: grid; gap: 10px; justify-items: start; }
.soon .chip { background: var(--surface); }
.panel { padding: 22px; display: grid; gap: 12px; align-content: start; }
.panel p { display: flex; gap: 10px; align-items: center; }
.shell[data-nav="tabbar"] .soon { flex-direction: column; text-align: center; }
.shell[data-nav="tabbar"] .soon-text { justify-items: center; }

/* ------------------------------------------------------------------ 6. Motion */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
/* Learners who ask for less motion get none: no bobbing Lumi, no sliding toast, no button lift. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .btn:hover, .btn:active { transform: none; }
}
