*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f1ea;
  --bg-card: #fffcf7;
  --bg-ruled: #ebe6dc;
  --ink: #1a1814;
  --ink-muted: #6b6560;
  --ink-faint: #a39e97;
  --accent: #c45c3e;
  --accent-soft: #e8d5cf;
  --border: #ddd6cb;
  --shadow: 0 1px 3px rgba(26, 24, 20, 0.06), 0 8px 24px rgba(26, 24, 20, 0.04);
  --radius: 12px;
  --font-serif: 'Literata', Georgia, serif;
  --font-sans: 'Inter', system-ui, sans-serif;
  --max-w: 720px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(245, 241, 234, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  max-width: calc(var(--max-w) + 80px);
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header__right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 4px;
  text-decoration: none;
  color: var(--ink);
}

.logo__num {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.logo__text {
  font-size: 0.8rem;
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 4px;
  background: var(--bg-ruled);
  padding: 4px;
  border-radius: 10px;
}

.nav__btn {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.nav__btn:hover { color: var(--ink); }

.nav__btn--active {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* Main */
.main {
  max-width: calc(var(--max-w) + 80px);
  margin: 0 auto;
  padding: 48px 24px 80px;
}

.section { display: none; animation: fadeIn 0.35s ease; }
.section--active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section__head {
  margin-bottom: 40px;
}

.section__title {
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}

.section__desc {
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.section__link {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.section__link:hover { text-decoration: underline; }

/* Subjects */
.subjects-nav {
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.subject-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: all 0.2s;
  flex: 1;
  min-width: 200px;
}

.subject-btn:hover {
  border-color: var(--accent);
}

.subject-btn--active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--shadow);
}

.subject-btn__icon { font-size: 1.5rem; }

.subject-btn__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
}

.subject-btn__text strong {
  font-size: 0.95rem;
  font-weight: 600;
}

/* Grades */
.grades-nav {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  background: var(--bg-ruled);
  padding: 6px;
  border-radius: 10px;
}

.grade-btn {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.grade-btn:hover { color: var(--ink); }

.grade-btn--active {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.grade-btn__count {
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 10px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-muted);
}

.empty-state a {
  color: var(--accent);
  font-weight: 500;
}

/* Materials grid */
.materials-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

a.material-card,
button.material-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
  text-decoration: none;
}

button.material-card {
  appearance: none;
  -webkit-appearance: none;
}

a.material-card:hover,
button.material-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(26, 24, 20, 0.08);
}

.back-link {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.back-link:hover { color: var(--ink); }

.material-card__icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 1.25rem;
}

.material-card__body { flex: 1; min-width: 0; }

.material-card__tag {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 4px;
}

.material-card__title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.material-card__meta {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.material-card__arrow {
  flex-shrink: 0;
  color: var(--ink-faint);
  font-size: 1.25rem;
}

/* Examiners */
.examiners-list {
  display: flex;
  flex-direction: column;
  gap: 32px;
  margin-bottom: 48px;
}

.examiner-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.examiner-card__top {
  display: flex;
  gap: 20px;
  padding: 24px;
  border-bottom: 1px solid var(--border);
}

.examiner-card__photo {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--bg-ruled);
}

.examiner-card__info { flex: 1; }

.examiner-card__name {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.examiner-card__role {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.examiner-card__rating {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.examiner-card__stars { color: #d4a017; letter-spacing: 1px; }

.examiner-card__comments {
  padding: 16px 24px 24px;
}

.comments-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 16px;
}

.comment {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.comment:last-child { border-bottom: none; }

.comment__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.comment__author {
  font-weight: 600;
  font-size: 0.9rem;
}

.comment__date {
  font-size: 0.75rem;
  color: var(--ink-faint);
}

.comment__text {
  font-size: 0.9rem;
  color: var(--ink-muted);
  line-height: 1.55;
}

/* Comment form */
.comment-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.comment-form__title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  margin-bottom: 20px;
}

.comment-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.comment-form label span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.comment-form input,
.comment-form select,
.comment-form textarea {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  transition: border-color 0.2s;
}

.comment-form input:focus,
.comment-form select:focus,
.comment-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.comment-form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 520px) {
  .comment-form__row { grid-template-columns: 1fr; }
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn--primary {
  background: var(--ink);
  color: var(--bg-card);
}

.btn--primary:hover { background: #2e2b26; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal[hidden] { display: none; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 24, 20, 0.5);
  backdrop-filter: blur(4px);
}

#ticket-modal .modal__dialog {
  max-width: min(960px, 96vw);
  height: calc(100dvh - 48px);
  max-height: calc(100dvh - 48px);
}

#ticket-modal .modal__header {
  flex-shrink: 0;
}

.modal__dialog {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal__tag {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.modal__title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
}

.modal__close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ink-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.modal__close:hover { color: var(--ink); }

/* Protected viewer */
.protected-viewer {
  position: relative;
  flex: 1;
  overflow: auto;
  min-height: 300px;
  max-height: 50vh;
  background: var(--bg);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.protected-viewer--locked canvas,
.protected-viewer--locked .pdf-page-wrap {
  visibility: hidden !important;
  pointer-events: none;
}

.protected-viewer canvas {
  display: block;
  width: 100%;
  height: auto;
}

.protected-viewer canvas.pdf-page {
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.pdf-page-wrap {
  position: relative;
}

.pdf-page-block {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: auto;
  -webkit-touch-callout: none;
}

.protected-viewer__noise {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

.viewer-fallback {
  padding: 24px;
  color: var(--ink-muted);
  text-align: center;
}

.protected-viewer__watermark {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.wm-item {
  position: absolute;
  font-size: 11px;
  font-weight: 600;
  color: rgba(196, 92, 62, 0.2);
  transform: rotate(-25deg);
  white-space: nowrap;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.protected-viewer__shield {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg);
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.protected-viewer__shield p {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--ink);
  font-weight: 600;
}

.protected-viewer__shield[hidden] { display: none; }

.shield-btn {
  margin-top: 12px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg-card);
  cursor: pointer;
}

.protected-viewer__shield {
  cursor: pointer;
}

.modal__notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 0.75rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.ticket-viewer {
  flex: 1 1 0;
  min-height: 0;
  padding: 16px 24px 24px;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ticket-viewer img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.2s;
  -webkit-user-drag: none;
  user-select: none;
}

.ticket-viewer img:hover {
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.16);
  transform: scale(1.01);
}

#ticket-modal .modal__notice {
  flex-shrink: 0;
}

.ticket-viewer__error {
  padding: 24px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

/* Auth */
.auth-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-header__email {
  font-size: 0.75rem;
  color: var(--ink-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-header__btn {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-header__btn:hover { border-color: var(--ink-muted); }

.auth-header__btn--primary {
  background: var(--ink);
  color: var(--bg-card);
  border-color: var(--ink);
}

.auth-page {
  display: flex;
  justify-content: center;
  padding-top: 32px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.auth-card__title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.auth-card__desc {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.auth-card__back {
  display: inline-block;
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--ink-muted);
  text-decoration: none;
}

.auth-card__back:hover { color: var(--ink); }

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-ruled);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 20px;
}

.auth-tabs__btn {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
}

.auth-tabs__btn--active {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.auth-form label span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.auth-form input {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-form__submit { width: 100%; margin-top: 4px; }

.auth-form__error {
  font-size: 0.85rem;
  color: #b42318;
  margin-bottom: 12px;
}

.auth-form__hint {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: 12px;
}

.auth-gate {
  text-align: center;
  padding: 48px 24px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.auth-gate__icon { font-size: 2rem; margin-bottom: 12px; }

.auth-gate__title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.auth-gate__desc {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

/* Footer */
.footer {
  text-align: center;
  padding: 24px;
  font-size: 0.75rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.footer__tg {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.2s;
}

.footer__tg:hover { opacity: 0.75; }

/* Protection blur state */
body.protection-screenshot .protected-viewer canvas,
body.protection-screenshot .protected-viewer .pdf-page-wrap {
  visibility: hidden !important;
  filter: blur(30px);
}

@media print {
  body * { display: none !important; }
}
