/* ==========================================================================
   STUDIY — PAINEL (dashboard). Somente tokens (css/tokens.css).
   Barra lateral = lista tipográfica com marcador de cor; cartões com borda fina;
   números grandes com data-count (js/motion.js). A cor da matéria vira --accent dentro de .app.
   ========================================================================== */
.app { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 288px minmax(0, 1fr); color: var(--text); }

/* ---------- Barra lateral ---------- */
.side {
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 20px; padding: 24px 16px 16px;
  border-right: 1px solid var(--line);
}
.side .logo { padding: 0 8px; color: var(--text); text-decoration: none; }
.home-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; color: var(--text-muted); font-weight: 600; font-size: var(--fs-sm); text-decoration: none; }
.home-link:hover { color: var(--text); }
.side h2 { margin: 0 0 4px; padding: 0 8px; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.subj-list { display: grid; }
.subj {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px;
  padding: 0 8px; border: 0; border-radius: var(--r-btn-sm); background: none; color: var(--text-muted);
  font: inherit; font-size: 17px; font-weight: 600; letter-spacing: -.015em; text-align: left;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color var(--dur-1) var(--ease), background-color var(--dur-1) var(--ease);
}
/* Marcador de cor da matéria: vira uma barra na matéria atual */
.subj[data-mark]::before {
  content: ""; flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--sw);
  transition: width var(--dur-2) var(--ease-spring);
}
.subj:hover { color: var(--text); background: var(--hover-tint); }
.subj[aria-current="true"] { color: var(--text); font-weight: 800; }
.subj[aria-current="true"]::before { width: 22px; }
.subj:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.subj.add { color: var(--text-muted); font-size: var(--fs-md); }
.subj.add:hover { color: var(--text); }

/* Ranking: fora da lista de matérias, com marcador próprio (barra preta) */
.side-extra { display: grid; padding-top: 12px; border-top: 1px solid var(--line); }
#rankingBtn::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--text); transition: width var(--dur-2) var(--ease-spring); }
#rankingBtn[aria-current="true"] { color: var(--text); font-weight: 800; }
#rankingBtn[aria-current="true"]::before { width: 22px; }

/* Itens reservados: não interativos, com etiqueta */
.side-soon { display: grid; padding-top: 12px; border-top: 1px solid var(--line); }
.subj.is-soon { cursor: default; color: var(--text-muted); opacity: .75; }
.subj.is-soon:hover { background: none; color: var(--text-muted); }
.subj.is-soon small { margin-left: auto; padding: 2px 8px; border-radius: var(--r-pill); background: var(--surface-2); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }

.side-foot { margin-top: auto; display: grid; gap: 12px; }
.side-row { display: flex; align-items: center; gap: 6px; }
.usage { padding: 14px; border-radius: var(--r-card); box-shadow: inset 0 0 0 1px var(--line); font-size: var(--fs-sm); }
.usage .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; font-weight: 700; }
.usage .top a { color: var(--accent); font-weight: 700; }
.usage p { margin: 8px 0 0; font-size: var(--fs-xs); color: var(--text-muted); }
.bar { height: 6px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .8s var(--ease); }
.profile-chip { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; min-height: 44px; padding: 6px; border: 0; border-radius: var(--r-btn); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: background-color var(--dur-1) var(--ease); }
.profile-chip:hover { background: var(--hover-tint); }
.profile-who { display: grid; min-width: 0; line-height: 1.3; }
.profile-who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.profile-who small { color: var(--text-muted); font-size: var(--fs-xs); }

/* ---------- Conteúdo ---------- */
.main { min-width: 0; width: 100%; max-width: 1240px; padding: clamp(24px, 4vw, 48px); display: flex; flex-direction: column; gap: 32px; }
.app-head { display: flex; flex-wrap: wrap; gap: 20px; justify-content: space-between; align-items: flex-end; padding-bottom: 20px; border-bottom: 1px solid var(--text); }
.app-head h1 {
  margin: 0; min-width: 0; font-size: clamp(40px, 6vw, 96px); font-weight: 900; letter-spacing: -.05em; line-height: .9;
  text-transform: uppercase; overflow-wrap: anywhere;
}
.head-actions { display: flex; gap: 10px; align-items: center; }
#content { display: flex; flex-direction: column; gap: 24px; }

/* Cor da matéria */
.swatches { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatches legend { float: left; margin-right: 6px; padding: 0; font-weight: 600; font-size: var(--fs-sm); color: var(--text-muted); line-height: 44px; }
.swatch { width: 44px; height: 44px; padding: 0; border: 0; border-radius: var(--r-btn-sm); background: var(--sw); cursor: pointer; transition: transform var(--dur-1) var(--ease-spring), box-shadow var(--dur-1) var(--ease); }
.swatch:hover { transform: scale(1.06); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--sw); }
.swatch:focus-visible { outline: 2px solid var(--focus); outline-offset: 6px; }
.swatches .grow { margin-left: auto; }

/* Números grandes */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stat { padding: 20px 22px 22px; border-radius: var(--r-card); box-shadow: inset 0 0 0 1px var(--line); }
.stat .label { margin-bottom: 8px; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.stat .value { margin-bottom: 14px; font-size: clamp(44px, 5.5vw, 80px); font-weight: 900; letter-spacing: -.055em; line-height: .9; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: var(--fs-md); font-weight: 600; letter-spacing: 0; color: var(--text-muted); }
.stat:first-child .value span { color: var(--dot); }   /* sequência = o ponto vermelho do sistema */

/* Painéis */
.panels { display: flex; flex-wrap: wrap; gap: 16px; }
.panel { flex: 1 1 340px; min-width: 0; padding: 24px; border-radius: var(--r-card); box-shadow: inset 0 0 0 1px var(--line); }
.panel h2 { margin-bottom: 14px; font-size: var(--fs-2xl); font-weight: 900; letter-spacing: -.04em; text-transform: uppercase; }
/* "Revisar agora": o único bloco cheio de cor do painel */
.panel-grad { display: flex; flex-direction: column; gap: 14px; background: var(--accent); color: var(--on-accent); box-shadow: none; }
.panel-grad h2 { font-size: clamp(32px, 3.4vw, 48px); line-height: .92; }
.panel-grad p { margin: 0; color: inherit; opacity: .9; }
.panel-grad .btn { align-self: flex-start; margin-top: auto; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); font-size: 15px; }
.row .name { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.row .actions { display: flex; gap: 8px; flex: none; }
.empty { margin: 0; color: var(--text-muted); }
.hint-text { margin: 0 0 8px; color: var(--text-muted); font-size: var(--fs-sm); }
.welcome { max-width: 760px; }
.welcome h1 { font-size: clamp(36px, 5vw, 64px); font-weight: 900; letter-spacing: -.05em; line-height: .95; text-transform: uppercase; }
.welcome p { color: var(--text-muted); font-size: var(--fs-lg); }
.tips { display: grid; gap: 8px; margin: 18px 0 28px; padding-left: 22px; color: var(--text-muted); }
details.resumo { padding: 4px 0; border-top: 1px solid var(--line); }
details.resumo summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-weight: 600; }
.prewrap { max-width: 70ch; margin: 4px 0 12px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Flashcard (flip 3D em css/motion.css) ---------- */
.flashcard { margin: 12px 0 16px; }
.flashcard .flip-face { display: flex; flex-direction: column; justify-content: center; min-height: 220px; padding: 24px; border-radius: var(--r-card); }
.flashcard .flip-front { background: var(--surface-2); }
.flashcard .flip-back { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.card-label { margin: 0 0 8px; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.card-q { margin: 0; font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -.03em; line-height: 1.2; overflow-wrap: anywhere; }
.card-a { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-lg); }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }

/* ---------- Ranking ---------- */
.rank-tabs { display: inline-flex; gap: 4px; padding: 4px; border-radius: var(--r-btn); box-shadow: inset 0 0 0 1px var(--line); align-self: flex-start; }
.rank-tabs .btn[aria-pressed="true"] { --b-bg: var(--text); --b-fg: var(--bg); --b-h: var(--text); }
.rank-meta { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }
.rank-meta strong { color: var(--text); }
.rank-offline { color: var(--warn); }
.rank-me { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 20px; padding: 20px 22px; border-radius: var(--r-card); background: var(--accent); color: var(--on-accent); }
.rank-me .card-label { width: 100%; color: inherit; opacity: .85; }
.rank-me-pos { margin: 0; font-size: clamp(56px, 7vw, 96px); font-weight: 900; letter-spacing: -.055em; line-height: .9; font-variant-numeric: tabular-nums; }
.rank-me-pos small { font-size: .5em; }
.rank-me-val { margin: 0; font-size: var(--fs-lg); font-weight: 700; }
.rank-cta { display: grid; gap: 8px; justify-items: start; }
.rank-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--text); }
.rank-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 52px; padding: 0 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.rank-pos { font-weight: 800; color: var(--text-muted); }
.rank-nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank-val { color: var(--text-muted); font-weight: 600; }
.rank-row.is-top { min-height: 68px; }
.rank-row.is-top .rank-pos { font-size: var(--fs-2xl); font-weight: 900; letter-spacing: -.04em; color: var(--text); }
.rank-row.is-top .rank-nome { font-size: var(--fs-lg); font-weight: 800; }
.rank-row.is-voce { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
/* Esqueleto só no primeiro acesso (depois há sempre uma prévia salva) */
.rank-skel { background: linear-gradient(90deg, var(--surface-2) 0, var(--line) 50%, var(--surface-2) 100%) 0 0 / 200% 100%; animation: rank-brilho 1.2s linear infinite; }
@keyframes rank-brilho { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .rank-skel { animation: none; } }

/* ---------- Celular/tablet: a barra lateral vira um cabeçalho compacto ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: static; height: auto; overflow: visible; padding: 12px 16px; gap: 10px 8px;
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "logo foot" "subj subj" "rank rank" "usage usage";
    align-items: center; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .side .logo { grid-area: logo; }
  .home-link, .side h2, .side-soon { display: none; }
  .side nav { grid-area: subj; min-width: 0; }
  .side .side-extra { grid-area: rank; display: flex; padding: 0; border: 0; }
  .subj-list { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scroll-snap-type: x proximity; scrollbar-width: none; }
  .subj-list::-webkit-scrollbar { display: none; }
  .subj { width: auto; flex: none; padding: 0 14px; font-size: 15px; border-radius: var(--r-pill); box-shadow: inset 0 0 0 1px var(--line); scroll-snap-align: start; }
  .subj[aria-current="true"] { box-shadow: inset 0 0 0 1.5px var(--text); }
  .side-foot { display: contents; }
  .side-row { grid-area: foot; }
  .profile-who { display: none; }
  .profile-chip { flex: none; padding: 2px; }
  .usage { grid-area: usage; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; padding: 10px 12px; }
  .usage .top { margin: 0; gap: 12px; }
  .usage .bar, .usage p { grid-column: 1 / -1; }
  .usage p { margin: 0; }
  .main { padding: 20px 16px 40px; gap: 24px; }
  .stats { gap: 8px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 40px; }
  .rate { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .swatches legend { float: none; width: 100%; margin: 0 0 4px; line-height: 1.4; }
  .app-head { align-items: flex-start; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:last-child { grid-column: 1 / -1; }
}

/* ---------- Perfil (diálogo "Meu perfil"): nome gigante ---------- */
dialog.profile { width: min(920px, calc(100vw - 32px)); padding: clamp(24px, 4vw, 48px); border-radius: var(--r-card); }
dialog.profile #accTitle { margin: 0 0 20px; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.profile .acc-head { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px 24px; align-items: end; padding-bottom: 24px; border-bottom: 1px solid var(--text); }
.profile .avatar.lg { width: 96px; height: 96px; border-radius: var(--r-card); font-size: 34px; font-weight: 900; background: var(--accent); color: var(--on-accent); }
.profile .acc-name {
  margin: 0; font-size: clamp(44px, 8vw, 112px); font-weight: 900; letter-spacing: -.055em; line-height: .88;
  text-transform: uppercase; overflow-wrap: anywhere; hyphens: auto;
}
.profile #dlgEmail { margin: 10px 0 0; font-size: var(--fs-lg); }
.profile .acc-head > div:last-child { min-width: 0; }
.profile .acc-head .acc-actions, .profile .acc-head .hint-text { grid-column: 1 / -1; }
.profile .acc-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 8px; }
.profile .acc-section { margin-top: 0; padding: 20px 0; border-top: 0; border-bottom: 1px solid var(--line); }
.profile .acc-section h3, .profile details.acc-section summary { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -.03em; }
.profile details.acc-section summary { display: flex; align-items: center; justify-content: space-between; min-height: 44px; cursor: pointer; list-style: none; }
.profile details.acc-section summary::-webkit-details-marker { display: none; }
.profile details.acc-section summary::after { content: "+"; font-size: 24px; font-weight: 400; transition: transform var(--dur-1) var(--ease-spring); }
.profile details.acc-section[open] summary::after { transform: rotate(45deg); }
.profile .acc-section form { max-width: 480px; }
.profile #delStart { margin-top: 12px; }
.profile #delForm { max-width: 480px; margin-top: 16px; padding: 16px; border-radius: var(--r-card); background: var(--danger-soft); box-shadow: inset 3px 0 0 var(--danger); }

@media (max-width: 600px) {
  dialog.profile { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; padding: 20px 16px; }
  .profile .acc-head { grid-template-columns: 1fr; }
  .profile .avatar.lg { width: 72px; height: 72px; font-size: 26px; }
}
