:root {
  --c-bg: #0a0a0f;
  --c-surface: #ffffff;
  --c-border: #e5e7eb;
  --c-border-hover: #d1d5db;
  --c-text: #0f172a;
  --c-text-secondary: #475569;
  --c-text-muted: #94a3b8;
  --c-primary: #009767;
  --c-primary-hover: #007956;
  --c-primary-dark: #005f46;
  --c-primary-light: #d0fae5;
  --c-primary-border: #a4f4cf;
  --c-accent: #009588;
  --c-accent-light: #cbfbf1;
  --c-warm: #dd7400;
  --c-warm-light: #fef3c6;
  --c-danger: #dc2626;
  --c-danger-light: #fee2e2;
  --c-star: #eab308;
  --c-gradient: linear-gradient(135deg, #009767, #009588);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.35);
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: #2a2a3e; color: var(--c-text); min-height: 100vh; }
body::before {
  content: ""; position: fixed; inset: 0; z-index: -3; pointer-events: none;
  background:
    radial-gradient(600px circle at var(--mx,50%) var(--my,50%), rgba(255,255,255,.07), transparent 50%),
    radial-gradient(1000px circle at var(--mx,50%) var(--my,50%), rgba(255,255,255,.04), transparent 50%),
    linear-gradient(160deg, #2a2a3e 0%, #34344a 40%, #2e2e40 100%);
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 25%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 25%, transparent 70%);
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.section { padding: 32px 0; }

/* ── Header ── */
.header { height: 60px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--c-border); position: sticky; top: 0; z-index: 100; }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 100%; }
.header-logo { display: flex; align-items: center; gap: 8px; text-decoration: none; font-size: 20px; font-weight: 900; background: var(--c-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.header-logo img { width: 24px; height: 24px; -webkit-text-fill-color: initial; }
.header-nav { display: flex; align-items: center; gap: 4px; }
.header-nav a { text-decoration: none; font-size: 13px; font-weight: 600; color: var(--c-text-secondary); padding: 6px 12px; border-radius: var(--radius-sm); transition: all .15s; }
.header-nav a:hover { color: var(--c-primary); background: var(--c-primary-light); }
.header-hamburger { display: none; background: none; border: none; padding: 8px; cursor: pointer; color: var(--c-text); border-radius: var(--radius-sm); }
.header-hamburger:hover { background: var(--c-bg); }
.header-mobile-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 200; }
.header-mobile-overlay.open { display: block; }
.header-mobile-nav { position: fixed; top: 0; left: 0; bottom: 0; width: 280px; background: var(--c-surface); z-index: 201; padding: 20px; transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg); }
.header-mobile-nav.open { transform: translateX(0); }
.header-mobile-nav a { display: block; padding: 12px 8px; font-size: 15px; font-weight: 600; color: var(--c-text); text-decoration: none; border-radius: var(--radius-sm); }
.header-mobile-nav a:hover { background: var(--c-primary-light); color: var(--c-primary); }
@media (max-width: 768px) { .header-nav { display: none; } .header-hamburger { display: flex; } }

/* ── Footer ── */
.footer { border-top: 1px solid var(--c-border); background: var(--c-surface); padding: 32px 0; margin-top: 64px; }
.footer-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.footer p { margin: 0; font-size: 13px; color: var(--c-text-muted); }
.footer strong { color: var(--c-text); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 18px; border-radius: var(--radius-md); font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer; border: 1px solid transparent; transition: all .15s; text-decoration: none; line-height: 1.4; white-space: nowrap; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn-secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--c-border-hover); background: var(--c-bg); }
.btn-ghost { background: transparent; color: var(--c-text-secondary); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--c-bg); color: var(--c-text); }
.btn-danger { background: var(--c-danger); color: #fff; border-color: var(--c-danger); }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-icon { padding: 6px; border-radius: var(--radius-sm); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 1.6; }
.badge-green { background: var(--c-primary-light); color: var(--c-primary-dark); border: 1px solid var(--c-primary-border); }
.badge-blue { background: var(--c-accent-light); color: #035a57; border: 1px solid #99f6e4; }
.badge-warm { background: var(--c-warm-light); color: #92400e; border: 1px solid #fde68a; }
.badge-gray { background: #f1f5f9; color: var(--c-text-secondary); border: 1px solid #e2e8f0; }

/* ── Cards ── */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-lg); overflow: hidden; transition: all .2s; }
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); border-color: var(--c-primary-border); }
.card-img { width: 100%; height: 150px; object-fit: cover; }
.card-img-placeholder { height: 150px; background: var(--c-gradient); display: flex; align-items: center; justify-content: center; font-size: 32px; opacity: .25; }
.card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.card-title { font-size: 14px; font-weight: 700; line-height: 1.4; color: var(--c-text); text-decoration: none; transition: color .15s; }
.card-title:hover { color: var(--c-primary); }
.card-desc { font-size: 12px; color: var(--c-text-muted); line-height: 1.5; }
.card-footer { display: flex; align-items: center; gap: 12px; font-size: 11px; color: var(--c-text-muted); padding-top: 10px; border-top: 1px solid var(--c-bg); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); animation: toast-in .3s ease; max-width: 360px; }
.toast-success { background: var(--c-primary); color: #fff; }
.toast-error { background: var(--c-danger); color: #fff; }
.toast-info { background: var(--c-accent); color: #fff; }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Form inputs ── */
.input { width: 100%; padding: 8px 14px; border: 1px solid var(--c-border); border-radius: var(--radius-md); font-size: 14px; font-family: inherit; background: var(--c-surface); color: var(--c-text); transition: border-color .15s, box-shadow .15s; outline: none; }
.input:focus { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(0,151,103,.15); }
.input::placeholder { color: var(--c-text-muted); }

/* ── Filter chips ── */
.chip-group { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 4px 14px; border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer; border: 1px solid var(--c-border); background: var(--c-surface); color: var(--c-text-secondary); transition: all .15s; font-family: inherit; }
.chip:hover { border-color: var(--c-primary); color: var(--c-primary); background: var(--c-primary-light); }
.chip.active { border-color: var(--c-primary); background: var(--c-primary); color: #fff; }

/* ── Skeleton ── */
.skeleton { background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%); background-size: 200% 100%; animation: shimmer 1.2s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skel-card { height: 280px; border-radius: var(--radius-lg); border: 1px solid var(--c-border); overflow: hidden; }
.skel-card-img { height: 150px; }
.skel-card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.skel-line { height: 12px; border-radius: 4px; }
.skel-line-sm { width: 60%; }
.skel-line-md { width: 80%; }

/* ── Star ── */
.star { color: var(--c-text-muted); transition: color .15s; cursor: pointer; background: none; border: none; padding: 2px; }
.star.filled { color: var(--c-star); }
.star:hover { color: var(--c-star); }

/* ── Utilities ── */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.text-xs { font-size: 12px; }
.text-sm { font-size: 13px; }
.text-center { text-align: center; }
.text-muted { color: var(--c-text-muted); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-8 { margin-top: 32px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mx-auto { margin-left: auto; margin-right: auto; }
.hidden { display: none; }
@media (max-width: 768px) { .hide-mobile { display: none; } }

/* ── Grid ── */
.grid { display: grid; gap: 16px; }
.grid-cols-1 { grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-cols-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid-cols-3 { grid-template-columns: repeat(3, 1fr); } }

/* ── Page header ── */
.page-hdr { padding: 32px 0 8px; }
.page-hdr h1 { font-size: 28px; font-weight: 900; letter-spacing: -.03em; margin: 0; background: var(--c-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.page-hdr p { margin: 4px 0 0; font-size: 14px; color: var(--c-text-muted); }

/* ── Viewer toolbar ── */
.viewer-tb { background: var(--c-surface); border-bottom: 1px solid var(--c-border); padding: 0 16px; height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 60px; z-index: 50; }
.viewer-tb-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.viewer-tb-right { display: flex; gap: 4px; align-items: center; }
.viewer-sep { width: 1px; height: 20px; background: var(--c-border); flex-shrink: 0; }

/* ── Sheet (paper) ── */
.sheet-wrap { background: #e2e8f0; padding: 32px 16px; display: flex; flex-direction: column; align-items: center; gap: 24px; }
.sheet { background: #fff; width: 100%; max-width: 650px; box-shadow: 0 2px 20px rgba(0,0,0,.1); }
.sheet-head { border-bottom: 2px solid var(--c-text); padding-bottom: 14px; margin-bottom: 18px; }
.sheet-title { font-size: 18px; font-weight: 700; color: var(--c-text); margin-bottom: 3px; outline: none; }
.sheet-sub { font-size: 12.5px; color: var(--c-text-secondary); outline: none; }
.sheet-inst { font-size: 12px; color: var(--c-text-secondary); margin-top: 8px; padding: 8px 12px; background: var(--c-primary-light); border-left: 3px solid var(--c-primary); border-radius: 0 4px 4px 0; outline: none; }
.sheet-id-row { display: grid; grid-template-columns: 1fr auto auto; gap: 0; margin-bottom: 22px; }
.sheet-id-field label { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--c-text-muted); margin-bottom: 6px; }
.sheet-id-field .sheet-line { border-bottom: 1px solid var(--c-text); height: 20px; }
.sheet-id-field+.sheet-id-field { margin-left: 24px; min-width: 80px; }
.sheet-footer { border-top: 1px solid var(--c-border); margin-top: 32px; padding-top: 10px; display: flex; justify-content: space-between; font-size: 10.5px; color: var(--c-text-muted); }
.sheet-q { margin-bottom: 22px; }
.sheet-q-header { display: flex; gap: 10px; margin-bottom: 9px; }
.sheet-q-num { font-size: 13px; font-weight: 700; color: var(--c-text); min-width: 24px; padding-top: 1px; }
.sheet-q-text { font-size: 13.5px; line-height: 1.65; color: var(--c-text); flex: 1; }
.sheet-alts { display: flex; flex-direction: column; gap: 0; margin-left: 34px; margin-top: 6px; }
.sheet-alt { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; line-height: 1.55; }
.sheet-alt-letra { font-weight: 600; min-width: 18px; color: var(--c-text-secondary); }
.sheet-alt-texto { font-weight: 400; color: var(--c-text); }
.sheet-alt.correct .sheet-alt-letra { color: var(--c-text-secondary); }
.sheet-alt.correct .sheet-alt-texto { color: var(--c-text); font-weight: 400; }
/* When gabarito is revealed (toggled by JS) */
.gab-visible .sheet-alt.correct .sheet-alt-letra { color: var(--c-primary); }
.gab-visible .sheet-alt.correct .sheet-alt-texto { color: var(--c-primary); font-weight: 500; }
.sheet-blank-lines { margin-left: 34px; margin-top: 8px; }
.sheet-blank-line { border-bottom: 1px solid var(--c-border-hover); height: 26px; }
.sheet-sep { border: none; border-top: 1px dashed var(--c-border); margin: 12px 0 0; }

/* ── Gabarito ── */
.gabarito { background: #fff; width: 100%; max-width: 650px; padding: 32px 48px; box-shadow: 0 2px 20px rgba(0,0,0,.1); margin-top: 24px; }
.gabarito-head { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--c-text-muted); border-bottom: 1.5px solid var(--c-text); padding-bottom: 8px; margin-bottom: 16px; }
.gabarito-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.gabarito-item { display: flex; align-items: center; gap: 6px; font-size: 13px; border: 1px solid var(--c-border); border-radius: 4px; padding: 5px 10px; min-width: 64px; }
.gabarito-item-q { color: var(--c-text-secondary); font-size: 11px; }
.gabarito-item-ans { font-weight: 700; color: var(--c-primary); }
.gabarito-item-ans.disc { font-size: 11px; color: var(--c-text-muted); font-style: italic; }

/* ── Layout panel ── */
.panel-anchor { position: relative; }
.layout-panel { display: none; position: absolute; top: calc(100% + 8px); right: 0; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); z-index: 200; width: 420px; max-width: calc(100vw - 32px); }
.layout-panel.open { display: block; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--c-bg); }
.panel-tab { flex: 1; padding: 13px 0; font-size: 13px; font-weight: 600; color: var(--c-text-muted); text-align: center; cursor: pointer; border: none; background: none; font-family: inherit; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.panel-tab.active { color: var(--c-text); border-bottom-color: var(--c-primary); background: var(--c-surface); }
.panel-body { padding: 22px 24px 24px; }
.panel-section { display: none; }
.panel-section.active { display: block; }
.slider-rows { display: flex; flex-direction: column; gap: 14px; }
.slider-row { display: grid; grid-template-columns: 100px 1fr 56px; align-items: center; gap: 12px; }
.slider-row label { font-size: 13px; color: var(--c-text-secondary); font-weight: 500; }
.slider-row input[type=range] { -webkit-appearance: none; width: 100%; height: 6px; border-radius: 4px; background: var(--c-border); outline: none; cursor: pointer; accent-color: var(--c-primary); }
.slider-row input[type=number] { width: 56px; padding: 6px 6px; border: 1px solid var(--c-border); border-radius: 6px; font-size: 13px; font-family: inherit; text-align: center; background: var(--c-bg); -moz-appearance: textfield; }
.slider-row input[type=number]:focus { outline: none; border-color: var(--c-primary); background: var(--c-surface); }

/* ── Comments ── */
.comment-avatar { width: 32px; height: 32px; border-radius: 999px; background: var(--c-primary-light); color: var(--c-primary-dark); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.comment-item { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--c-bg); }
.comment-item:last-child { border-bottom: none; }
.comment-name { font-size: 13px; font-weight: 600; color: var(--c-text); }
.comment-time { font-size: 12px; color: var(--c-text-muted); }
.comment-text { font-size: 13px; color: var(--c-text-secondary); line-height: 1.55; margin-top: 2px; }

/* ── PDF overlay ── */
.pdf-overlay { position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px; backdrop-filter: blur(4px); }
.pdf-overlay-spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: pdf-spin .8s linear infinite; }
@keyframes pdf-spin { to { transform: rotate(360deg); } }
.pdf-overlay-text { color: #fff; font-size: 14px; font-weight: 600; font-family: var(--font); }

/* ── Sala dos Professores (card no viewer) ── */
.sala-cta { transition: transform .18s ease, box-shadow .18s ease; }
.sala-cta:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(14,90,75,.35); }

/* ── Responsive tweaks ── */
@media (max-width: 640px) {
  .viewer-tb { padding: 0 8px; }
  .sheet-wrap { padding: 16px 8px; }
  .sheet { max-width: 100%; }
  /* Force all sheet inline paddings to shrink on mobile */
  .sheet-head,
  .sheet-id-row,
  .sheet > div[style] { padding-left: 14px !important; padding-right: 14px !important; }
  /* Keep Nome / Turma / Data on the same line */
  .sheet-id-row { display: flex !important; gap: 8px !important; padding-left: 14px !important; padding-right: 14px !important; }
  .sheet-id-field { flex: 1; }
  .sheet-id-field:first-child { flex: 1.5; }
  .sheet-id-field+.sheet-id-field { margin-left: 0 !important; min-width: 0 !important; }
  .gabarito { padding: 24px 16px; }
  .page-hdr h1 { font-size: 22px; }
}
@media print {
  @page {
    size: A4 portrait;
    margin: 1cm 0;
  }
  /* Force A4 width (794px @ 96dpi) so mobile viewport doesn't distort the PDF */
  html, body {
    width: 794px !important;
    min-width: 794px !important;
    background: #fff !important;
  }
  body::before, body::after { display: none !important; }
  .viewer-tb { display: none !important; }
  .no-print { display: none !important; }
  .sheet-wrap {
    background: #fff !important;
    padding: 0 !important;
  }
  .sheet {
    box-shadow: none !important;
    width: 794px !important;
    max-width: 794px !important;
  }
  .gabarito {
    box-shadow: none !important;
    width: 794px !important;
    max-width: 794px !important;
  }
}