/* Мудрица: shared design for the portal, nalog and every workbook (source: mudrica.rs/shared/, copied into
   <project>/public/mudrica/ by `make shared`; never edit the copies).
   Tokens, the two papers and the shared header (<mudrica-header>, header.js) with its account menu and the
   logout confirmation. A page only adds its own content styles. */

:root {
  color-scheme: light dark;
  --paper: #fbfcfa;
  --paper-raised: #ffffff;
  --grid-line: #d3e0ec;
  --grid-strong: #b4c8dc;
  --margin-line: rgba(215, 38, 47, 0.55);
  --ink: #1f3d99;
  --ink-soft: #5a74c4;
  --ink-deep: #142a6e;
  --on-ink: #ffffff;
  --text: #1c2847;
  --red: #d42a33;
  --on-red: #ffffff;
  --marker: #ffe94a;
  --marker-soft: rgba(255, 233, 74, 0.55);
  --pencil: #5c6371;
  --muted: #8b929e;
  --star: #f5b700;
  --star-edge: #b67b00;
  --heart: #e2416c;
  --note: #fff3a1;
  --note-edge: #ecd86a;
  --note-ink: #2b2a1c;
  --shadow: 0 14px 22px -16px rgba(28, 40, 71, 0.55);
  --focus: #1f3d99;

  --font-hand: "Caveat", "Segoe Print", "Bradley Hand", "Chalkboard SE", "Comic Sans MS", cursive;
  --font-body: "Nunito", "Trebuchet MS", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;

  --cell: 22px;          /* one square of the squared (math) paper */
  --line: 30px;          /* one line of the lined (language) paper */
  --margin: 132px;       /* x of the red margin line on wide screens */
  --header-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #162034;
    --paper-raised: #1d2942;
    --grid-line: #233150;
    --grid-strong: #33466d;
    --margin-line: rgba(255, 120, 116, 0.45);
    --ink: #9fbcff;
    --ink-soft: #7790cf;
    --ink-deep: #6b88d8;
    --on-ink: #0f1830;
    --text: #e3e9f7;
    --red: #ff7a74;
    --on-red: #2a0b0a;
    --marker: #e9cf45;
    --marker-soft: rgba(233, 207, 69, 0.28);
    --pencil: #a6afc2;
    --muted: #7c879c;
    --star: #ffc940;
    --star-edge: #c78f00;
    --note: #3a3620;
    --note-edge: #575032;
    --note-ink: #f4ecc4;
    --shadow: 0 16px 24px -16px rgba(0, 0, 0, 0.8);
    --focus: #ffe066;
  }
}

@media (max-width: 720px) {
  :root { --margin: 44px; }
}

/* ------------------------------------------------------------------ papers (class on <body>)
   paper-grid:  squared paper (math, the portal)        paper-lines: lined paper (Serbian, English)
   Both carry the red margin line at --margin. */

.paper-grid,
.paper-lines {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background-color: var(--paper);
  background-attachment: local;
}
.paper-grid {
  background-image:
    linear-gradient(90deg, transparent calc(var(--margin) - 2px), var(--margin-line) calc(var(--margin) - 2px), var(--margin-line) var(--margin), transparent var(--margin)),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 100% 100%, var(--cell) var(--cell), var(--cell) var(--cell);
  background-position: 0 0, -1px -1px, -1px -1px;
}
.paper-lines {
  background-image:
    linear-gradient(90deg, transparent calc(var(--margin) - 2px), var(--margin-line) calc(var(--margin) - 2px), var(--margin-line) var(--margin), transparent var(--margin)),
    linear-gradient(transparent calc(var(--line) - 1px), var(--grid-strong) calc(var(--line) - 1px));
  background-size: 100% 100%, 100% var(--line);
  background-position: 0 0, 0 var(--header-h);
}

/* ------------------------------------------------------------------ header: <mudrica-header subject="..."> */

mudrica-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  min-height: var(--header-h);
  padding: 8px 16px;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--grid-strong);
  font-family: var(--font-body);
}
/* hidden until header.js defines it (no flash of the raw page nav); if the script never loads, shown anyway */
mudrica-header:not(:defined) { visibility: hidden; animation: mh-reveal 0s linear 1.5s forwards; }
@keyframes mh-reveal { to { visibility: visible; } }
.mh-brand {
  display: flex; align-items: center; gap: 10px; flex: none;
  min-width: calc(var(--margin) + 8px);
  color: var(--ink); text-decoration: none;
}
.mh-brand:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }
.mh-owl { width: 44px; height: 44px; flex: none; }
.mh-titles { display: flex; flex-direction: column; line-height: 1; }
.mh-name { font-family: var(--font-hand); font-size: 2rem; font-weight: 700; color: var(--ink); }
.mh-subject {
  margin-top: 2px; font-family: var(--font-hand); font-size: 1.25rem; font-weight: 700; color: var(--red);
}
.mh-slot { display: flex; align-items: center; gap: 16px; flex: 1 1 auto; min-width: 0; }
.mh-account { position: relative; flex: none; margin-left: auto; }

.mh-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 6px 16px;
  border: 2px solid var(--ink); border-radius: 999px;
  background: var(--paper-raised); color: var(--ink);
  font: inherit; font-weight: 800; text-decoration: none; cursor: pointer;
}
.mh-btn-ink { background: var(--ink); color: var(--on-ink); }
.mh-btn:hover { background: var(--marker-soft); }
.mh-btn-ink:hover { background: var(--ink-deep); border-color: var(--ink-deep); }
.mh-btn:focus-visible, .mh-item:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.mh-avatar {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--marker); color: #2b2a1c; font-family: var(--font-hand); font-size: 1.25rem; font-weight: 700;
}
.mh-user-name { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mh-chevron { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid currentColor; }

.mh-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 15rem; max-height: calc(100vh - var(--header-h) - 24px); overflow-y: auto;
  padding: 8px; display: grid; gap: 2px;
  background: var(--paper-raised); border: 2px solid var(--ink-soft); border-radius: 12px; box-shadow: var(--shadow);
}
.mh-menu-top:empty { display: none; }
.mh-menu-top { padding: 6px 8px 10px; border-bottom: 2px dashed var(--grid-strong); margin-bottom: 4px; }
.mh-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 8px; background: none;
  color: var(--text); font: inherit; font-weight: 700; text-align: left; text-decoration: none; cursor: pointer;
}
.mh-item:hover { background: var(--marker-soft); }
.mh-item[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.mh-item[aria-current="page"] { font-weight: 800; background: var(--marker-soft); box-shadow: inset 4px 0 0 var(--ink); }
.mh-item-icon { display: inline-flex; width: 20px; height: 20px; color: var(--ink); }
.mh-item-icon svg { width: 100%; height: 100%; }
.mh-badge { margin-left: auto; padding: 1px 8px; border-radius: 999px; background: var(--marker); color: #2b2a1c; font-size: 0.8125rem; }
.mh-group { margin: 4px 10px 2px; font-family: var(--font-hand); font-size: 1.25rem; font-weight: 700; color: var(--red); }
.mh-sep { height: 0; margin: 6px 4px; border-top: 2px dashed var(--grid-strong); }
.mh-logout { color: var(--red); }

/* ------------------------------------------------------------------ logout confirmation (always asked) */

.mh-confirm {
  max-width: min(26rem, calc(100vw - 32px)); padding: 22px 24px;
  border: 2px solid var(--ink-soft); border-radius: 14px;
  background: var(--paper-raised); color: var(--text); box-shadow: var(--shadow);
  font-family: var(--font-body);
}
.mh-confirm::backdrop { background: rgba(20, 30, 60, 0.45); }
.mh-confirm-title { margin: 0; font-size: 1.25rem; font-weight: 800; color: var(--ink-deep); }
.mh-confirm-text { margin: 10px 0 0; }
.mh-confirm-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.mh-danger { border-color: var(--red); background: var(--red); color: var(--on-red); }
.mh-danger:hover { background: color-mix(in srgb, var(--red) 85%, #000000); }

@media (max-width: 720px) {
  mudrica-header { gap: 10px; padding: 6px 10px; }
  .mh-brand { min-width: 0; }
  .mh-owl { width: 36px; height: 36px; }
  .mh-name { font-size: 1.625rem; }
  .mh-subject { font-size: 1.0625rem; }
  .mh-user-name { max-width: 7rem; }
}

/* compact: for screens that need the room (a workbook's running test); no effect from 760 px up */
@media (max-width: 759.98px) {
  mudrica-header[compact] .mh-titles,
  mudrica-header[compact] .mh-user-name,
  mudrica-header[compact] .mh-chevron { display: none; }
  mudrica-header[compact] .mh-user { padding-left: 4px; padding-right: 4px; gap: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  .mh-menu { animation: mh-in 120ms ease-out; }
  @keyframes mh-in { from { opacity: 0; transform: translateY(-4px); } }
}
