:root {
  --bg: #eef3f8;
  --card: #ffffff;
  --ink: #1a2b3c;
  --muted: #5a6f82;
  --line: #d5e0ea;
  --accent: #1b6ca8;
  --accent-2: #0e4d7a;
  --good: #2f9e6b;
  --mid: #d4a017;
  --bad: #c44;
  --shadow: 0 10px 30px rgba(20, 50, 80, 0.08);
  --radius: 16px;
  --diary-navy: #163a6b;
  --diary-ink: #1e2a3a;
  --diary-paper: #f4efe4;
  --diary-line: #c9d6e4;
  --diary-gold: #b8892d;
  --diary-red: #b4232c;
  font-family: "Segoe UI", "PT Sans", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d7e9f8 0%, transparent 60%),
    radial-gradient(900px 400px at 100% 0%, #f7efe3 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
.wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px 48px; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 18px;
}
.brand {
  font-weight: 800; letter-spacing: 0.02em; font-size: 1.25rem; color: var(--accent-2);
}
.brand span { color: var(--muted); font-weight: 600; font-size: 0.9rem; margin-left: 8px; }
.nav {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px;
}
.nav a {
  padding: 8px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line);
  color: var(--ink); font-size: 0.92rem;
}
.nav a.active, .nav a:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 18px 8px; margin-bottom: 14px;
}
.card h1, .card h2 { margin: 0 0 10px; font-size: 1.15rem; }
.muted { color: var(--muted); }
.week {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 12px 0 4px;
}
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 2px;
  padding: 6px 4px;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.week-nav__label {
  font-weight: 650;
  font-size: 0.92rem;
  text-align: center;
  flex: 1;
  color: var(--accent-2);
  letter-spacing: 0.01em;
}
.week-nav__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 0;
  background: var(--diary-navy);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(22, 58, 107, 0.22);
  transition: filter 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.week-nav__btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(22, 58, 107, 0.28);
}
.week-nav__btn:active { transform: translateY(0); }
.week-nav__btn svg { display: block; width: 22px; height: 22px; }
.lesson__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}
.lesson__marks { display: inline-flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.mark {
  display: inline-flex; min-width: 30px; height: 30px; align-items: center; justify-content: center;
  border-radius: 9px; font-weight: 800; margin: 0; padding: 0 7px; color: #fff;
  font-variant-numeric: tabular-nums; box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.mark.m5 { background: var(--good); }
.mark.m4 { background: #2f7ec0; }
.mark.m3 { background: var(--mid); color: #222; }
.mark.m2, .mark.m1 { background: var(--bad); }
.mark.mn { background: #888; }
.week a {
  text-align: center; padding: 10px 6px; border-radius: 12px; background: #f5f8fb;
  border: 1px solid var(--line); color: var(--ink);
}
.week a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.week a.today:not(.active) { outline: 2px solid var(--accent); }
.lesson {
  display: grid; grid-template-columns: 96px 1fr; gap: 10px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.lesson:first-of-type { border-top: 0; }
.time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.subj { font-weight: 700; }
.hw { margin-top: 4px; color: var(--ink); white-space: pre-wrap; font-size: 0.95rem; }
.hw.empty { color: var(--muted); font-style: italic; }
.row {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.row:first-of-type { border-top: 0; }
.avg {
  font-weight: 800; font-size: 1.2rem; min-width: 52px; text-align: right;
}
.bar {
  height: 8px; border-radius: 99px; background: #e6eef5; overflow: hidden; margin-top: 8px;
}
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #49a3df); }

/* Progress / analysis */
.prog-hero__grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 18px;
  align-items: center;
}
.prog-gauge__ring {
  --deg: 0deg;
  width: 112px; height: 112px; border-radius: 50%;
  background: conic-gradient(var(--accent) var(--deg), #dce7f1 0);
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(27, 108, 168, 0.15);
}
.prog-gauge__core {
  width: 86px; height: 86px; border-radius: 50%; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.prog-gauge__val { font-size: 1.55rem; font-weight: 800; color: var(--accent-2); line-height: 1; }
.prog-gauge__sub { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.prog-notes { margin: 10px 0 0; padding-left: 18px; color: var(--ink); }
.prog-notes li { margin: 4px 0; }
.prog-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.prog-chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.prog-chip__k { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.prog-chip__v { font-weight: 700; font-size: 0.95rem; }
.prog-chip--good { border-color: rgba(47,158,107,0.35); }
.prog-chip--warn { border-color: rgba(212,160,23,0.45); }
.prog-chip--up { border-color: rgba(47,158,107,0.35); }
.prog-chip--down { border-color: rgba(204,68,68,0.35); }
.prog-timeline {
  display: flex; align-items: flex-end; gap: 10px;
  min-height: 160px; padding: 8px 4px 0; overflow-x: auto;
}
.prog-timeline__col {
  flex: 1 1 48px; min-width: 44px; max-width: 72px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.prog-timeline__bar-wrap {
  width: 100%; height: 110px;
  background: #eef3f8; border-radius: 10px 10px 4px 4px;
  display: flex; align-items: flex-end; overflow: hidden;
}
.prog-timeline__bar {
  width: 100%;
  background: linear-gradient(180deg, #49a3df 0%, var(--accent-2) 100%);
  border-radius: 10px 10px 4px 4px;
  min-height: 6px;
}
.prog-timeline__val { font-size: 0.78rem; font-weight: 700; color: var(--accent-2); }
.prog-timeline__label { font-size: 0.72rem; color: var(--muted); }
.prog-timeline__n { font-size: 0.68rem; color: #8aa0b4; }
.prog-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  padding: 14px 0; border-top: 1px solid var(--line);
}
.prog-row:first-of-type { border-top: 0; }
.prog-row__main { flex: 1; min-width: 0; }
.prog-row__title {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin-bottom: 2px;
}
.prog-trend {
  font-size: 0.78rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: #eef3f8; color: var(--muted);
}
.prog-trend.trend-up { background: rgba(47,158,107,0.12); color: #1f7a4d; }
.prog-trend.trend-down { background: rgba(204,68,68,0.12); color: #a12b2b; }
.prog-trend.trend-flat { background: #eef3f8; color: var(--muted); }
.prog-spark { margin-top: 8px; color: var(--accent); opacity: 0.9; }
.prog-row.level-great .bar > i { background: linear-gradient(90deg, #2f9e6b, #49c48a); }
.prog-row.level-warn .bar > i { background: linear-gradient(90deg, #d4a017, #e8c35a); }
.prog-row.level-bad .bar > i { background: linear-gradient(90deg, #c44, #e07070); }

@media (max-width: 640px) {
  .prog-hero__grid { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .prog-notes { text-align: left; }
}
.login-box { max-width: 420px; margin: 8vh auto; }
input[type=text], input[type=number], input[type=password] {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  font-size: 1rem; margin: 8px 0 14px;
}
button, .btn {
  appearance: none; border: 0; background: var(--accent); color: #fff;
  padding: 12px 16px; border-radius: 12px; font-weight: 700; cursor: pointer;
}
button.secondary { background: #fff; color: var(--accent); border: 1px solid var(--line); }
.error {
  background: #fde8e8; color: #8a1f1f; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px;
}
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs a {
  padding: 8px 12px; border-radius: 10px; background: #f3f7fb; border: 1px solid var(--line); color: var(--ink);
}
.tabs a.active { background: var(--accent); color: #fff; }
.foot { margin-top: 20px; color: var(--muted); font-size: 0.85rem; }

/* ——— Auth / school diary login ——— */
.auth-body {
  /* System stack only — no Google Fonts (Safari/iOS often stalls on fonts.googleapis) */
  font-family: "Segoe UI", "Helvetica Neue", "PT Sans", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--diary-ink);
  background: #0f2748;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
.diary-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 520px at 18% 12%, rgba(74, 130, 190, 0.35), transparent 60%),
    radial-gradient(700px 480px at 88% 78%, rgba(184, 137, 45, 0.18), transparent 55%),
    linear-gradient(160deg, #0d2240 0%, #163a6b 48%, #0f2c4f 100%);
}
.diary-grid {
  position: absolute; inset: 0; opacity: 0.14;
  background-image:
    linear-gradient(rgba(255,255,255,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(ellipse at center, #000 35%, transparent 80%);
}
.diary-glow {
  position: absolute; width: 55vw; height: 55vw; max-width: 520px; max-height: 520px;
  left: 50%; top: 42%; transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(244, 239, 228, 0.16), transparent 70%);
  opacity: 0.7;
  animation: diary-breathe 7s ease-in-out infinite;
}
@keyframes diary-breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.06); }
}

.diary-stage {
  position: relative; z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}
.diary-book {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) 1.15fr;
  min-height: min(560px, calc(100vh - 56px));
  border-radius: 18px;
  overflow: hidden;
  /* Always visible — do NOT use opacity:0 + animation-fill-mode:both (Safari blank page) */
  opacity: 1;
  box-shadow:
    0 28px 60px rgba(4, 16, 36, 0.45),
    0 2px 0 rgba(255,255,255,0.08) inset;
  animation: diary-enter 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes diary-enter {
  from { transform: translateY(12px); }
  to { transform: none; }
}

.diary-cover {
  position: relative;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.08), transparent 40%),
    linear-gradient(180deg, #1c4a86 0%, var(--diary-navy) 55%, #10284c 100%);
  color: #f6f1e6;
  padding: 36px 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  isolation: isolate;
}
.diary-cover::before {
  content: "";
  position: absolute; inset: 14px;
  border: 1px solid rgba(184, 137, 45, 0.55);
  border-radius: 8px;
  pointer-events: none;
}
.diary-cover::after {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 14px;
  background: linear-gradient(90deg, rgba(0,0,0,0.35), transparent);
}
.cover-band {
  height: 4px; width: 72px;
  background: linear-gradient(90deg, var(--diary-gold), #e8d39a);
  border-radius: 2px;
}
.cover-stamp { position: relative; z-index: 1; margin-top: 48px; }
.cover-school {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(246, 241, 230, 0.72);
  margin-bottom: 14px;
}
.cover-brand {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 7vw, 4.4rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: #fff8e8;
  text-shadow: 0 2px 0 rgba(0,0,0,0.18);
}
.cover-pupil {
  display: block;
  margin-top: 18px;
  font-size: 1rem;
  font-weight: 500;
  color: rgba(246, 241, 230, 0.88);
}
.cover-corner {
  width: 54px; height: 54px;
  margin-top: auto;
  border-right: 2px solid rgba(184, 137, 45, 0.65);
  border-bottom: 2px solid rgba(184, 137, 45, 0.65);
  align-self: flex-end;
  opacity: 0.85;
}

.diary-page {
  position: relative;
  background-color: var(--diary-paper);
  background-image:
    linear-gradient(90deg, transparent 39px, rgba(180, 50, 50, 0.18) 39px, rgba(180, 50, 50, 0.18) 41px, transparent 41px),
    repeating-linear-gradient(
      transparent 0,
      transparent 31px,
      var(--diary-line) 31px,
      var(--diary-line) 32px
    );
  background-position: 0 0;
  padding: 36px 36px 28px 52px;
  display: flex;
  flex-direction: column;
  opacity: 1;
  animation: page-slide 0.55s 0.05s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes page-slide {
  from { transform: translateX(10px); }
  to { transform: none; }
}
.page-head { margin-bottom: 18px; }
.page-eyebrow {
  margin: 0 0 8px;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--diary-red);
  font-weight: 600;
}
.page-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 3.5vw, 2.15rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--diary-navy);
  line-height: 1.15;
}
.page-lead {
  margin: 10px 0 0;
  max-width: 34ch;
  color: #4d5d70;
  font-size: 0.98rem;
  line-height: 1.45;
}
.diary-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 6px;
}
.diary-form label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #3d5166;
  margin-top: 6px;
}
.diary-form input[type=text],
.diary-form input[type=password] {
  margin: 4px 0 10px;
  background: rgba(255,255,255,0.72);
  border: 1px solid #c5d0dc;
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  color: var(--diary-ink);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.diary-form input:focus {
  outline: none;
  border-color: #2f6fad;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 111, 173, 0.18);
}
.diary-form .code-input {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.35em;
  text-align: center;
  font-weight: 700;
  padding: 14px 12px;
  /* ≥16px prevents iOS Safari zoom on focus */
  font-size: 1.5rem;
}
.diary-btn {
  margin-top: 10px;
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 14px 16px;
  background: linear-gradient(180deg, #245fa0 0%, var(--diary-navy) 100%);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.diary-btn:hover { filter: brightness(1.06); }
.diary-btn:active { transform: translateY(1px); }
.diary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}
.diary-btn-secondary {
  background: linear-gradient(180deg, #5a6f82 0%, #3d5166 100%);
  margin-top: 8px;
}
.lolka-resend { margin-top: 8px; }
.lolka-hint { margin: 6px 0 0; font-size: 0.85rem; }
.diary-error {
  background: rgba(180, 35, 44, 0.1);
  color: #8a1c24;
  border: 1px solid rgba(180, 35, 44, 0.22);
  border-radius: 10px;
}
.diary-info {
  background: rgba(22, 58, 107, 0.1);
  color: #163a6b;
  border: 1px solid rgba(22, 58, 107, 0.22);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.diary-back {
  margin: 16px 0 0;
  font-size: 0.92rem;
}
.diary-back a { color: var(--diary-navy); font-weight: 600; }
.page-foot {
  margin-top: auto;
  padding-top: 22px;
  font-size: 0.8rem;
  color: #6b7c8f;
}
.admin-proxies h1 { font-size: 1.4rem; margin: 0 0 8px; }
.admin-proxies .lead { font-size: 0.92rem; color: #3d5166; margin-bottom: 16px; }
.admin-form textarea {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #c5d0db;
  margin-bottom: 8px;
}
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th, .admin-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}
.admin-table tr.is-active { background: rgba(22, 58, 107, 0.08); }
.admin-table tr.is-mt { opacity: 0.85; }
.admin-actions button {
  font-size: 0.75rem;
  margin: 2px 2px 2px 0;
  padding: 4px 8px;
}

@media (prefers-reduced-motion: reduce) {
  .diary-book,
  .diary-page,
  .diary-glow,
  .cover-band {
    animation: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}

@media (max-width: 760px) {
  .diary-book {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .diary-cover {
    min-height: 180px;
    padding: 24px 22px 20px;
  }
  .cover-stamp { margin-top: 18px; }
  .cover-brand { font-size: 2.6rem; }
  .cover-corner { display: none; }
  .diary-page {
    padding: 28px 22px 24px 44px;
    min-height: 420px;
  }
  .diary-form input[type=text],
  .diary-form input[type=password] {
    font-size: 16px; /* prevent iOS input zoom */
  }
}
@media (max-width: 640px) {
  .lesson { grid-template-columns: 1fr; }
  .week { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
