/* =============================================================================
   ui/kit.css — the component layer.
   Every class here is the web twin of a Compose composable in the Android app
   (AppCard, GlassRadioGroup, SettingsRow, SkeletonBox, FireStreak, …), so a
   change on one client has an obvious counterpart on the other.
   ========================================================================== */

/* ------------------------------- card ----------------------------------- */
.card {
  background:var(--surface);
  border:1px solid var(--outline-v);
  border-radius:var(--r-md);
  padding:var(--s4);
  box-shadow:var(--shadow-sm);
  transition:border-color var(--t-fast) var(--e-standard),
             transform var(--t-fast) var(--e-standard),
             box-shadow var(--t-fast) var(--e-standard);
}
.card.tonal { background:var(--surface-v); box-shadow:none; }
.card.glass {
  background:var(--glass);
  border-color:var(--glass-edge);
  backdrop-filter:blur(16px) saturate(1.35);
  -webkit-backdrop-filter:blur(16px) saturate(1.35);
}
.card.pad0 { padding:0; overflow:hidden; }
.card.click { cursor:pointer; }
/* hover only where a real pointer exists — never on touch */
@media (hover:hover) and (pointer:fine) {
  .card.click:hover { border-color:var(--outline); transform:translateY(-2px); box-shadow:var(--shadow); }
}
.card.click:active { transform:scale(.985); }

.card-title { display:flex; align-items:center; gap:var(--s2); font-weight:800; font-size:15px; margin-bottom:var(--s3); }
.card-title .ic { color:var(--primary); }
.card-title .more { margin-inline-start:auto; font-size:12px; color:var(--on-surface-v); font-weight:600; }

.section-head { display:flex; align-items:center; gap:var(--s2); margin:var(--s6) 0 var(--s3); }
.section-head h2 { font-size:17px; font-weight:800; }
.section-head .rest { margin-inline-start:auto; }

.divider { height:1px; background:var(--outline-v); margin:var(--s3) 0; border:0; }

/* ------------------------------ buttons --------------------------------- */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:var(--s2);
  min-height:44px; padding:0 var(--s4);
  border:1px solid var(--outline);
  border-radius:var(--r-full);
  background:var(--surface-v);
  color:var(--on-surface);
  font-weight:700; font-size:14px;
  cursor:pointer;
  transition:transform var(--t-fast) var(--e-standard),
             filter var(--t-fast) var(--e-standard),
             background var(--t-fast) var(--e-standard),
             border-color var(--t-fast) var(--e-standard);
  user-select:none;
}
.btn:active { transform:scale(.96); }
.btn[disabled] { opacity:.45; pointer-events:none; }
@media (hover:hover) and (pointer:fine) { .btn:hover { filter:brightness(1.08); border-color:var(--primary); } }

.btn-p { background:var(--primary); color:var(--on-primary); border-color:transparent; }
.btn-s { background:var(--secondary); color:var(--on-secondary); border-color:transparent; }
.btn-t { background:var(--tertiary-c); color:var(--on-tertiary-c); border-color:transparent; }
.btn-danger { background:var(--error); color:var(--on-error); border-color:transparent; }
.btn-ghost { background:transparent; border-color:transparent; }
.btn-ghost:hover { background:var(--surface-v); }
.btn-outline { background:transparent; }
.btn-sm { min-height:34px; padding:0 var(--s3); font-size:12.5px; }
.btn-lg { min-height:52px; padding:0 var(--s6); font-size:15.5px; }
.btn-block { width:100%; }

.icon-btn {
  display:inline-flex; align-items:center; justify-content:center;
  width:42px; height:42px; flex:none;
  border:1px solid transparent; border-radius:var(--r-sm);
  background:transparent; color:var(--on-surface);
  cursor:pointer;
  transition:background var(--t-fast) var(--e-standard), transform var(--t-fast) var(--e-standard);
}
.icon-btn:active { transform:scale(.92); }
@media (hover:hover) and (pointer:fine) { .icon-btn:hover { background:var(--surface-v); } }
.icon-btn.solid { background:var(--surface-v); border-color:var(--outline-v); }
.icon-btn.p { background:var(--primary); color:var(--on-primary); }
.icon-btn.sm { width:34px; height:34px; border-radius:var(--r-xs); }

/* FAB — phone only, the study timer entry point */
.fab {
  position:fixed; z-index:46;
  inset-inline-end:var(--s5);
  bottom:calc(var(--nav-h) + var(--safe-b) + var(--s5));
  width:58px; height:58px;
  border:0; border-radius:20px;
  background:linear-gradient(140deg, var(--primary), var(--grad-a));
  color:var(--on-primary);
  box-shadow:0 12px 28px rgba(var(--primary-rgb)/.34);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
  transition:transform var(--t-med) var(--e-spring);
}
.fab:active { transform:scale(.9); }
.fab.ticking { animation:fabPulse 2.4s ease-in-out infinite; }
@keyframes fabPulse {
  0%,100% { box-shadow:0 12px 28px rgba(var(--primary-rgb)/.34); }
  50%     { box-shadow:0 12px 40px rgba(var(--primary-rgb)/.62); }
}

/* ------------------------------- chips ---------------------------------- */
.chip {
  display:inline-flex; align-items:center; gap:6px;
  height:32px; padding:0 var(--s3);
  border-radius:var(--r-full);
  background:var(--surface-v);
  border:1px solid var(--outline-v);
  font-size:12.5px; font-weight:600;
  cursor:pointer; white-space:nowrap;
  transition:all var(--t-fast) var(--e-standard);
}
.chip.on { background:var(--primary-c); border-color:var(--primary); color:var(--on-primary-c); }
.chip.static { cursor:default; }
.chip-row { display:flex; gap:var(--s2); overflow-x:auto; padding-bottom:2px; scrollbar-width:none; }
.chip-row::-webkit-scrollbar { display:none; }

/* GlassRadioGroup — sliding glider, same spring as UiverseKit.kt */
.seg {
  position:relative; display:flex; align-items:center;
  padding:4px; gap:2px;
  background:var(--surface-v);
  border:1px solid var(--outline-v);
  border-radius:var(--r-full);
}
.seg > button {
  position:relative; z-index:1;
  flex:1; min-height:36px; padding:0 var(--s3);
  border:0; background:transparent; cursor:pointer;
  font-size:13px; font-weight:700; color:var(--on-surface-v);
  border-radius:var(--r-full);
  transition:color var(--t-med) var(--e-standard);
  white-space:nowrap;
}
.seg > button.on { color:var(--on-primary); }
/* Latin ratios such as 25 / 5 must not be reordered by the RTL context. */
.seg.seg-ltr > button { direction:ltr; unicode-bidi:isolate; }
.seg .glider {
  position:absolute; z-index:0; top:4px; bottom:4px;
  border-radius:var(--r-full);
  background:linear-gradient(140deg, var(--primary), var(--grad-a));
  transition:left 420ms var(--e-spring), width 420ms var(--e-spring);
  will-change:left,width;
}

/* ------------------------------- inputs --------------------------------- */
.input, .textarea, select.input {
  width:100%;
  min-height:46px;
  padding:var(--s3) var(--s4);
  background:var(--surface-v);
  border:1px solid var(--outline-v);
  border-radius:var(--r-sm);
  color:var(--on-surface);
  transition:border-color var(--t-fast) var(--e-standard), background var(--t-fast) var(--e-standard);
  outline:none;
}
.input::placeholder, .textarea::placeholder { color:var(--on-surface-v); }
.input:focus, .textarea:focus { border-color:var(--primary); background:var(--surface); }
.textarea { min-height:96px; resize:vertical; line-height:1.8; }
.field { display:flex; flex-direction:column; gap:6px; }
.field > label { font-size:12.5px; font-weight:700; color:var(--on-surface-v); }
.input-icon { position:relative; }
.input-icon .ic { position:absolute; inset-inline-start:var(--s3); top:50%; transform:translateY(-50%); color:var(--on-surface-v); pointer-events:none; }
.input-icon .input { padding-inline-start:44px; }

/* switch */
.switch { position:relative; width:48px; height:28px; flex:none; cursor:pointer; }
.switch input { position:absolute; opacity:0; width:100%; height:100%; margin:0; cursor:pointer; }
.switch .track {
  position:absolute; inset:0; border-radius:99px;
  background:var(--surface-v); border:1px solid var(--outline);
  transition:background var(--t-med) var(--e-standard), border-color var(--t-med) var(--e-standard);
}
.switch .thumb {
  position:absolute; top:4px; inset-inline-start:4px;
  width:20px; height:20px; border-radius:99px;
  background:var(--on-surface-v);
  transition:transform var(--t-med) var(--e-spring), background var(--t-med) var(--e-standard);
}
.switch input:checked ~ .track { background:var(--primary); border-color:transparent; }
.switch input:checked ~ .thumb { background:var(--on-primary); transform:translateX(-20px); }
[dir=ltr] .switch input:checked ~ .thumb { transform:translateX(20px); }

/* slider */
.slider { -webkit-appearance:none; appearance:none; width:100%; height:6px; border-radius:99px; background:var(--outline-v); outline:none; }
.slider::-webkit-slider-thumb { -webkit-appearance:none; width:22px; height:22px; border-radius:99px; background:var(--primary); border:3px solid var(--surface); box-shadow:var(--shadow-sm); cursor:pointer; }
.slider::-moz-range-thumb { width:22px; height:22px; border-radius:99px; background:var(--primary); border:3px solid var(--surface); cursor:pointer; }

/* ------------------------------ settings rows ---------------------------- */
.srow {
  display:flex; align-items:center; gap:var(--s3);
  padding:var(--s3) var(--s4);
  border-radius:var(--r-sm);
  cursor:pointer;
  transition:background var(--t-fast) var(--e-standard);
}
.srow:not(.static):hover { background:var(--surface-v); }
.srow .lead {
  width:38px; height:38px; flex:none; border-radius:var(--r-xs);
  display:flex; align-items:center; justify-content:center;
  background:var(--surface-v); color:var(--primary);
}
.srow .body { flex:1; min-width:0; }
.srow .body b { display:block; font-size:14px; font-weight:700; }
.srow .body span { display:block; font-size:12px; color:var(--on-surface-v); }
.srow .trail { flex:none; color:var(--on-surface-v); }
.sgroup { background:var(--surface); border:1px solid var(--outline-v); border-radius:var(--r-md); padding:var(--s2); }
.sgroup + .sgroup { margin-top:var(--s4); }
.sgroup-title { font-size:12.5px; font-weight:800; color:var(--on-surface-v); margin:var(--s5) var(--s2) var(--s2); }

/* ------------------------------- avatar ---------------------------------- */
.av-wrap { position:relative; flex:none; display:inline-block; }
.avatar {
  display:flex; align-items:center; justify-content:center;
  font-weight:800; color:#fff; overflow:hidden;
  background-size:cover;
}
.avatar img { width:100%; height:100%; object-fit:cover; }
.online-dot {
  position:absolute; inset-inline-end:-1px; bottom:-1px;
  width:12px; height:12px; border-radius:99px;
  background:#34D399; border:2.5px solid var(--surface);
}

/* ------------------------------- badges ---------------------------------- */
.badge {
  min-width:19px; height:19px; padding:0 5px;
  display:inline-flex; align-items:center; justify-content:center;
  border-radius:99px; background:var(--error); color:var(--on-error);
  font-size:10.5px; font-weight:800;
}
.pill {
  display:inline-flex; align-items:center; gap:5px;
  padding:3px var(--s2); border-radius:99px;
  background:var(--surface-v); border:1px solid var(--outline-v);
  font-size:11.5px; font-weight:700;
}
.pill.p { background:var(--primary-c); color:var(--on-primary-c); border-color:transparent; }
.pill.t { background:var(--tertiary-c); color:var(--on-tertiary-c); border-color:transparent; }
.pill.s { background:var(--secondary-c); color:var(--on-secondary-c); border-color:transparent; }

/* streak flame, mirrors FireStreak */
.streak { display:inline-flex; align-items:center; gap:5px; color:#FBBF24; font-weight:800; }
.streak .ic { animation:flicker 2.6s ease-in-out infinite; transform-origin:50% 90%; }
@keyframes flicker { 0%,100% { transform:scale(1) rotate(0); } 40% { transform:scale(1.1) rotate(-3deg); } 70% { transform:scale(.96) rotate(2deg); } }

/* ------------------------------ progress --------------------------------- */
.bar { height:8px; border-radius:99px; background:var(--outline-v); overflow:hidden; }
.bar > i {
  display:block; height:100%; border-radius:99px;
  background:linear-gradient(90deg, var(--primary), var(--secondary));
  transition:width 620ms var(--e-decel);
}

.ring { display:block; transform:rotate(-90deg); }
.ring circle { fill:none; stroke-linecap:round; }
.ring .track { stroke:var(--outline-v); }
.ring .val { stroke:url(#ringGrad); transition:stroke-dashoffset 720ms var(--e-decel); }

/* --------------------------- skeleton / empty ---------------------------- */
.skel {
  border-radius:var(--r-sm);
  background:linear-gradient(90deg, var(--surface-v) 25%, var(--outline-v) 37%, var(--surface-v) 63%);
  background-size:400% 100%;
  animation:shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position:100% 0; } to { background-position:-100% 0; } }

.empty { text-align:center; padding:var(--s10) var(--s4); color:var(--on-surface-v); }
.empty .e { font-size:44px; display:block; margin-bottom:var(--s2); }
.empty b { display:block; color:var(--on-surface); font-size:15px; }

/* ------------------------------- toast ----------------------------------- */
#toasts {
  position:fixed; z-index:90;
  inset-inline:0; bottom:calc(var(--nav-h) + var(--safe-b) + var(--s4));
  display:flex; flex-direction:column; align-items:center; gap:var(--s2);
  pointer-events:none; padding-inline:var(--s4);
}
@media (min-width:900px) { #toasts { bottom:var(--s6); inset-inline-start:auto; inset-inline-end:var(--s6); align-items:flex-end; } }
.toast {
  max-width:min(92vw, 420px);
  padding:var(--s3) var(--s4);
  border-radius:var(--r-sm);
  background:var(--surface);
  border:1px solid var(--outline);
  box-shadow:var(--shadow);
  font-size:13.5px; font-weight:600;
  display:flex; align-items:center; gap:var(--s2);
  pointer-events:auto;
  animation:toastIn 320ms var(--e-decel) both;
}
.toast.out { animation:toastOut 220ms var(--e-accel) both; }
.toast.err { border-color:var(--error); color:var(--error); }
.toast.ok  { border-color:var(--primary); }
@keyframes toastIn { from { opacity:0; transform:translateY(14px) scale(.96); } to { opacity:1; transform:none; } }
@keyframes toastOut { to { opacity:0; transform:translateY(8px) scale(.98); } }

/* --------------------------- modal / sheet -------------------------------- */
#scrim {
  position:fixed; inset:0; z-index:60;
  background:var(--scrim);
  opacity:0; pointer-events:none;
  transition:opacity var(--t-med) var(--e-standard);
  backdrop-filter:blur(3px);
  -webkit-backdrop-filter:blur(3px);
}
#scrim.open { opacity:1; pointer-events:auto; }

.sheet {
  position:fixed; z-index:70;
  inset-inline:0; bottom:0;
  max-height:88dvh;
  display:flex; flex-direction:column;
  background:var(--surface);
  border-top:1px solid var(--outline-v);
  border-radius:var(--r-xl) var(--r-xl) 0 0;
  padding:var(--s3) var(--s4) calc(var(--safe-b) + var(--s5));
  transform:translateY(102%);
  transition:transform 420ms var(--e-decel);
  box-shadow:var(--shadow-lg);
}
.sheet.open { transform:none; }
.sheet:not(.open) { pointer-events:none; }
.sheet.gone { display:none !important; }
.sheet .grip { width:44px; height:5px; border-radius:99px; background:var(--outline); margin:0 auto var(--s3); flex:none; }
.sheet .sheet-body { overflow-y:auto; overscroll-behavior:contain; }

/* On a wide screen a bottom sheet is wrong — it becomes a centred dialog. */
@media (min-width:900px) {
  .sheet {
    inset:auto; top:50%; left:50%; right:auto;
    transform:translate(-50%,-46%) scale(.96);
    width:min(560px, 92vw);
    max-height:84dvh;
    border-radius:var(--r-lg);
    border:1px solid var(--outline-v);
    padding:var(--s5);
    opacity:0;
    transition:transform 320ms var(--e-decel), opacity 200ms var(--e-standard);
  }
  .sheet.open { transform:translate(-50%,-50%) scale(1); opacity:1; }
  .sheet .grip { display:none; }
  .sheet.wide { width:min(880px, 94vw); }
}

/* --------------------------- context menu -------------------------------- */
.ctxmenu {
  position:fixed; z-index:80;
  min-width:190px; padding:6px;
  background:var(--surface);
  border:1px solid var(--outline);
  border-radius:var(--r-sm);
  box-shadow:var(--shadow-lg);
  animation:ctxIn 160ms var(--e-decel) both;
}
@keyframes ctxIn { from { opacity:0; transform:scale(.94); } to { opacity:1; transform:none; } }
.ctxmenu button {
  display:flex; align-items:center; gap:var(--s2);
  width:100%; padding:9px var(--s3);
  border:0; background:transparent; border-radius:10px;
  font-size:13.5px; font-weight:600; cursor:pointer; text-align:start;
}
.ctxmenu button:hover { background:var(--surface-v); }
.ctxmenu button.danger { color:var(--error); }
.ctxmenu .sep { height:1px; background:var(--outline-v); margin:5px 4px; }

/* ------------------------------ tooltip ---------------------------------- */
[data-tip] { position:relative; }
@media (hover:hover) and (pointer:fine) {
  [data-tip]::after {
    content:attr(data-tip);
    position:absolute; z-index:85;
    inset-inline-start:calc(100% + 10px); top:50%;
    transform:translateY(-50%) scale(.9);
    padding:5px 10px; border-radius:8px;
    background:var(--on-surface); color:var(--surface);
    font-size:11.5px; font-weight:700; white-space:nowrap;
    opacity:0; pointer-events:none;
    transition:opacity var(--t-fast) var(--e-standard), transform var(--t-fast) var(--e-standard);
  }
  [data-tip]:hover::after { opacity:1; transform:translateY(-50%) scale(1); }
}

/* ------------------------------ lightbox --------------------------------- */
#lightbox {
  position:fixed; inset:0; z-index:95;
  background:rgba(0,0,0,.92);
  display:none; align-items:center; justify-content:center;
  padding:var(--s4);
}
#lightbox.open { display:flex; animation:pageIn 240ms var(--e-decel) both; }
#lightbox img { max-width:96vw; max-height:92dvh; border-radius:var(--r-sm); object-fit:contain; }
#lightbox .close { position:absolute; top:var(--s4); inset-inline-end:var(--s4); color:#fff; }

/* ---------------------------- progress bar -------------------------------- */
#progbar {
  position:fixed; top:0; inset-inline:0; z-index:99;
  height:2.5px; width:0;
  background:linear-gradient(90deg, var(--primary), var(--secondary));
  transition:width 240ms var(--e-decel), opacity 240ms;
}

/* ------------------------------ grids ------------------------------------ */
.grid { display:grid; gap:var(--s3); }
.grid.g2 { grid-template-columns:repeat(2,minmax(0,1fr)); }
.grid.g3 { grid-template-columns:repeat(3,minmax(0,1fr)); }
.grid.g4 { grid-template-columns:repeat(2,minmax(0,1fr)); }
.grid.auto { grid-template-columns:repeat(auto-fill,minmax(168px,1fr)); }
@media (min-width:700px) {
  .grid.g4 { grid-template-columns:repeat(4,minmax(0,1fr)); }
  .grid.auto { grid-template-columns:repeat(auto-fill,minmax(200px,1fr)); }
}

/* two-pane list+detail layout used by chat and flashcards */
.pane { display:grid; grid-template-columns:1fr; height:calc(100dvh - var(--topbar-h)); }
@media (min-width:900px) {
  .pane { grid-template-columns:minmax(280px,340px) minmax(0,1fr); height:100dvh; }
  .pane > .pane-list { border-inline-start:1px solid var(--outline-v); }
}
.pane > .pane-list { overflow-y:auto; min-width:0; }
.pane > .pane-detail { overflow:hidden; min-width:0; display:flex; flex-direction:column; }
@media (max-width:899px) {
  .pane[data-view=detail] > .pane-list { display:none; }
  .pane[data-view=list] > .pane-detail { display:none; }
}

/* Intrinsic sizing: wrap text instead of clipping it or widening grid tracks. */
#content { max-width:min(100%, var(--maxw)); min-width:0; }
/* Do not replace screen-specific max-widths (home, courses, auth) here. */
#content > * { min-width:0; }
img, video, canvas, svg { max-inline-size:100%; }
pre { max-width:100%; white-space:pre-wrap; overflow-wrap:anywhere; }
code, a[href] { overflow-wrap:anywhere; }
.card, .field, .input, .textarea, select, .btn { min-width:0; max-width:100%; }
.row > *, .col > *, .grid > *, .card-title > *, .section-head > * { min-width:0; }
/* Sheets must also scroll when a long heading is outside .sheet-body. */
.sheet { overflow-y:auto; }
.sheet > * { flex-shrink:0; min-width:0; }
.sheet .sheet-body { min-height:0; }
.ctxmenu { min-width:min(190px, calc(100vw - 24px)); max-width:calc(100vw - 24px); max-height:calc(100dvh - 24px); overflow-y:auto; }
.seg > button { min-width:0; white-space:normal; }
.chip-row > .chip { flex-shrink:0; }
.grid.auto { grid-template-columns:repeat(auto-fill,minmax(min(100%,168px),1fr)); }
@media (min-width:700px) {
  .grid.auto { grid-template-columns:repeat(auto-fill,minmax(min(100%,200px),1fr)); }
}
