/* StudyPlanner — dark-mode design system (SPEC §6). Logical properties everywhere so RTL flips for free. */
:root {
  --bg: #0e1117;
  --surface: #161b26;
  --surface-2: #1e2533;
  --border: #2a3345;
  --text: #e8ecf4;
  --text-muted: #9aa5bc;
  --primary: #7c6cff;
  --primary-glow: rgba(124, 108, 255, 0.35);
  --accent: #3ddbd9;
  --ok: #3ddc97;
  --warn: #ffb454;
  --urgent: #ff6b7a;
  --radius: 16px;
  --radius-sm: 12px;
  --gutter: 16px;
  --shadow-glow: 0 0 0 1px var(--border);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 96px;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: 0 0 0 4px var(--primary-glow); }
bdi { unicode-bidi: isolate; }

.skip { position: absolute; inset-inline-start: -999px; top: 8px; background: var(--surface-2); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { inset-inline-start: 8px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px var(--gutter);
  background: rgba(14, 17, 23, 0.86);
  backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
}
.logo { font-weight: 800; font-size: 20px; letter-spacing: -0.2px; margin-inline-end: auto; display: flex; align-items: center; gap: 8px; }
.logo i {
  width: 28px; height: 28px; border-radius: 9px; display: inline-grid; place-items: center; font-style: normal; font-size: 15px;
  background: linear-gradient(135deg, var(--primary), var(--accent)); color: #0e1117;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
button.chip:hover { background: var(--surface-2); }
.chip strong { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chip-avg { border-color: rgba(61, 219, 217, 0.4); }
.chip-status { color: var(--text-muted); font-size: 13px; }
.chip-status.err { color: var(--warn); border-color: rgba(255, 180, 84, 0.5); }
.chip-icon { min-width: 40px; justify-content: center; padding-inline: 10px; }

/* ---------- layout ---------- */
.page { padding: var(--gutter); max-width: 1080px; margin-inline: auto; outline: none; }
.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
.col-side { display: grid; gap: 16px; align-content: start; }
@media (min-width: 900px) {
  .grid { grid-template-columns: 1.15fr 1fr; align-items: start; }
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; position: relative;
}
@media (min-width: 768px) { .card { padding: 24px; } }
.card-title { font-size: 14px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.2px; margin-block-end: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--text-muted); }

/* ---------- 7-day banner ---------- */
.banner {
  border-radius: var(--radius); padding: 14px 16px; margin-block-end: 16px;
  background: linear-gradient(135deg, rgba(124, 108, 255, 0.18), rgba(61, 219, 217, 0.1));
  border: 1px solid rgba(124, 108, 255, 0.45);
}
.banner-head { display: flex; align-items: center; gap: 10px; }
.banner-head h2 { font-size: 16px; font-weight: 700; flex: 1; }
.banner-head .ico { font-size: 20px; }
.banner button.link { background: none; border: 0; color: var(--text-muted); font-size: 13px; text-decoration: underline; padding: 6px; min-height: 32px; }
.banner ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.banner li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.banner .cluster { margin-block-start: 10px; padding-block-start: 10px; border-block-start: 1px dashed var(--border); font-size: 14px; color: var(--warn); display: flex; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.banner .when { margin-inline-start: auto; color: var(--text-muted); white-space: nowrap; font-size: 13px; }
.banner.collapsed ul, .banner.collapsed .cluster { display: none; }

/* ---------- hero ---------- */
.hero { padding: 20px 16px; border: 1px solid transparent; background:
  linear-gradient(var(--surface), var(--surface)) padding-box,
  linear-gradient(135deg, var(--primary), var(--accent)) border-box; }
@media (min-width: 768px) { .hero { padding: 28px; } }
.hero[data-level='urgent'] { background: linear-gradient(var(--surface), var(--surface)) padding-box, linear-gradient(135deg, var(--urgent), var(--warn)) border-box; box-shadow: 0 0 32px rgba(255, 107, 122, 0.22); }
.hero[data-level='soon'] { background: linear-gradient(var(--surface), var(--surface)) padding-box, linear-gradient(135deg, var(--warn), var(--primary)) border-box; box-shadow: 0 0 28px rgba(255, 180, 84, 0.16); }
.hero[data-level='far'] { background: linear-gradient(var(--surface), var(--surface)) padding-box, linear-gradient(135deg, var(--accent), var(--primary)) border-box; }
.hero-top { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 14px; font-weight: 600; }
.hero-subject { display: flex; align-items: center; gap: 10px; margin-block: 8px 2px; }
.hero-subject h2 { font-size: 24px; font-weight: 800; line-height: 1.2; }
.hero-meta { color: var(--text-muted); font-size: 14px; }
.cd { display: flex; gap: 10px; margin-block: 18px 16px; }
.cd-box { flex: 1; text-align: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 6px 8px; border: 1px solid var(--border); }
.cd-num { font-size: 40px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
@media (min-width: 768px) { .cd-num { font-size: 52px; } }
.cd-lbl { font-size: 12px; color: var(--text-muted); margin-block-start: 4px; }
.hero[data-level='urgent'] .cd-num { color: var(--urgent); }
.hero[data-level='soon'] .cd-num { color: var(--warn); }
.hero[data-level='mid'] .cd-num { color: var(--text); }
.hero[data-level='far'] .cd-num { color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .hero[data-level='urgent'] { animation: pulse 2.6s ease-in-out infinite; }
  @keyframes pulse { 50% { box-shadow: 0 0 44px rgba(255, 107, 122, 0.34); } }
}

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px;
  font-size: 14px; font-weight: 600; border: 1px solid;
}
.badge.ontrack { color: var(--ok); border-color: rgba(61, 220, 151, 0.5); background: rgba(61, 220, 151, 0.1); }
.badge.tight { color: var(--warn); border-color: rgba(255, 180, 84, 0.5); background: rgba(255, 180, 84, 0.08); }
.badge.boost { color: #1b1305; border-color: var(--warn); background: var(--warn); }
.hint { margin-block-start: 8px; font-size: 14px; color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-block: 14px 16px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--text-muted); }

.btn {
  min-height: 44px; padding: 8px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600;
}
.btn:hover { background: #262e40; }
.btn-primary { border: 0; color: #0e1117; background: linear-gradient(135deg, var(--primary), var(--accent)); }
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--primary), var(--accent)); }
.btn-block { width: 100%; }
.btn-danger { color: var(--urgent); }

.later { margin-block-start: 16px; padding-block-start: 14px; border-block-start: 1px solid var(--border); }
.later-title { font-size: 12px; color: var(--text-muted); margin-block-end: 8px; }
.later-row { display: flex; gap: 8px; overflow-x: auto; padding-block-end: 4px; scrollbar-width: thin; }
.later-chip { flex: none; display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; min-width: 132px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.later-chip b { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.later-chip span { color: var(--text-muted); }

.tag { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted); }

/* ---------- schedule ---------- */
.lessons { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lesson { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid transparent; }
.lesson .bar { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.lesson .time { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 92px; direction: ltr; text-align: start; }
[dir='rtl'] .lesson .time { text-align: end; }
.lesson .name { font-weight: 600; flex: 1; }
.lesson .room { font-size: 12px; color: var(--text-muted); }
.lesson.current { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.lesson.past { opacity: 0.5; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.now { background: var(--primary); color: #0e1117; }
.pill.next { background: rgba(61, 219, 217, 0.18); color: var(--accent); }
.pill.test { background: rgba(255, 180, 84, 0.18); color: var(--warn); }
.empty { text-align: center; padding: 8px 0; color: var(--text-muted); font-size: 14px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-block-end: 2px; }

/* ---------- mission ---------- */
.mission-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-block-end: 12px; }
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); min-height: 56px; }
.task input { width: 22px; height: 22px; accent-color: var(--ok); flex: none; margin: 0; }
.task label { flex: 1; cursor: pointer; display: grid; }
.task .t-name { font-weight: 600; }
.task .t-sub { font-size: 12px; color: var(--text-muted); }
.task .t-min { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.task.done .t-name { text-decoration: line-through; color: var(--text-muted); }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-block-start: 6px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: inherit; transition: width 0.25s ease-out; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; inset-inline-end: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  width: 56px; height: 56px; border-radius: 50%; border: 0; font-size: 30px; line-height: 1; color: #0e1117;
  background: linear-gradient(135deg, var(--primary), var(--accent)); box-shadow: 0 6px 24px rgba(124, 108, 255, 0.45);
}
.fab:hover { filter: brightness(1.08); }

/* ---------- dialogs ---------- */
.dlg { border: 1px solid var(--border); border-radius: 20px; background: var(--surface); color: var(--text); padding: 0; width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
.dlg-wide { width: min(620px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(5, 7, 11, 0.7); backdrop-filter: blur(3px); }
.dlg-body { padding: 20px; display: grid; gap: 14px; }
.dlg h2 { font-size: 20px; font-weight: 800; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--text-muted); }
.field input, .field select {
  min-height: 44px; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); width: 100%;
}
.field input[type='date'], .field input[type='time'] { color-scheme: dark; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.note { font-size: 13px; color: var(--text-muted); }
.warn-box { font-size: 13px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid rgba(255, 180, 84, 0.5); background: rgba(255, 180, 84, 0.08); color: var(--warn); }
.err-box { font-size: 14px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid rgba(255, 107, 122, 0.5); background: rgba(255, 107, 122, 0.08); }
.issues { margin: 0; padding-inline-start: 18px; font-size: 13px; color: var(--text-muted); max-height: 160px; overflow: auto; }

.timer-face { font-size: 64px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; direction: ltr; line-height: 1.1; padding-block: 8px; }

.g-overall { display: flex; align-items: baseline; gap: 10px; }
.g-overall b { font-size: 48px; font-weight: 800; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.g-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.g-row { display: grid; grid-template-columns: 8px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.g-row .bar { width: 8px; height: 100%; min-height: 36px; border-radius: 4px; }
.g-row .g-name { font-weight: 600; }
.g-row .g-sub { font-size: 12px; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.g-avg { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.trend { font-weight: 600; }
.trend.rising { color: var(--ok); }
.trend.falling { color: var(--warn); }

.toast {
  position: fixed; inset-inline: 16px; bottom: 88px; margin-inline: auto; width: fit-content; max-width: calc(100vw - 32px);
  background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 60;
}
.toast.show { opacity: 1; transform: none; }

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

/* ---------- data sources dialog ---------- */
.src { display: grid; gap: 10px; padding-block: 14px; border-block-start: 1px solid var(--border); }
.src:first-of-type { border-block-start: 0; padding-block-start: 0; }
.src h3 { font-size: 16px; font-weight: 700; }
.ok-box { font-size: 14px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid rgba(61, 220, 151, 0.5); background: rgba(61, 220, 151, 0.08); color: var(--ok); }
.chip-status { white-space: normal; text-align: center; line-height: 1.25; max-width: 100%; }

/* ---------- manual entry ---------- */
.daychips { display: flex; gap: 6px; flex-wrap: wrap; }
.daychip { position: relative; }
.daychip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.daychip span {
  display: inline-grid; place-items: center; min-width: 44px; min-height: 40px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 14px; font-weight: 600;
}
.daychip input:checked + span { background: var(--primary); border-color: var(--primary); color: #0e1117; }
.daychip input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: 0 0 0 4px var(--primary-glow); }
.card-title .chip { flex: none; }

/* ---------- calendar filter ---------- */
.filterbox { display: grid; gap: 6px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 14px; }
.opt { display: flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.opt input { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; flex: none; }
.pickgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 12px; }

/* ---------- study videos screen (Apify) ---------- */
.vscreen { display: grid; gap: 14px; }
.vform .field { min-width: 180px; }
.vlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.vcard { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.vcard.demo { border: 1px dashed var(--border); }
.vthumb { flex: none; width: 112px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--bg); display: grid; place-items: center; color: var(--text-muted); }
.vthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vbody { flex: 1; min-width: 0; display: grid; gap: 2px; }
.vtitle { font-weight: 600; line-height: 1.3; }
.vtitle a { color: var(--text); text-decoration: none; }
.vtitle a:hover { color: var(--accent); text-decoration: underline; }
@media (max-width: 520px) {
  .vcard { flex-wrap: wrap; }
  .vthumb { width: 96px; }
  .vcard .tag { margin-inline-start: auto; }
}
[hidden] { display: none !important; }
