@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url(fonts/bricolage.woff2) format('woff2');
}

:root {
  --bg: #0a0e13;
  --surface: #121921;
  --surface-2: #18222d;
  --text: #e9eef4;
  --muted: #8493a3;
  --border: #223040;
  --primary: #6cb8ff;
  --primary-text: #04121f;
  --glow: rgba(108, 184, 255, 0.32);
  /* Notas: cada uma com sua cor */
  --red: #ff6b6b;
  --orange: #ffa94d;
  --green: #4cd694;
  --blue: #6cb8ff;
  --on-color: #0a0e13;
  --radius: 18px;
  /* Variáveis que mudam com o tema */
  --bg-glow: #14202e;
  --bg-rgb: 10, 14, 19;
  --answer: #c5d3e0;
  --shadow: rgba(0, 0, 0, 0.45);
  --red-text: #ff6b6b;
  --green-text: #4cd694;
  --blue-text: #6cb8ff;
  --ts: 1; /* escala do texto do cartão */
  color-scheme: dark;
}

/* Tema claro (escolhido) e automático (segue o aparelho) */
:root[data-theme="light"] {
  --bg: #f2f5f9; --bg-glow: #e1ebf7; --bg-rgb: 242, 245, 249;
  --surface: #ffffff; --surface-2: #f7f9fc;
  --text: #13202c; --muted: #5b6b7b; --border: #d3dce6;
  --primary: #1c6fd6; --primary-text: #ffffff; --glow: rgba(28, 111, 214, 0.22);
  --answer: #33475a; --shadow: rgba(30, 50, 80, 0.16);
  --red-text: #c62f35; --green-text: #17855a; --blue-text: #1c6fd6;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f2f5f9; --bg-glow: #e1ebf7; --bg-rgb: 242, 245, 249;
    --surface: #ffffff; --surface-2: #f7f9fc;
    --text: #13202c; --muted: #5b6b7b; --border: #d3dce6;
    --primary: #1c6fd6; --primary-text: #ffffff; --glow: rgba(28, 111, 214, 0.22);
    --answer: #33475a; --shadow: rgba(30, 50, 80, 0.16);
    --red-text: #c62f35; --green-text: #17855a; --blue-text: #1c6fd6;
    color-scheme: light;
  }
}

/* Tamanho do texto dos cartões */
:root[data-textsize="s"] { --ts: 0.85; }
:root[data-textsize="l"] { --ts: 1.25; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 'Bricolage Grotesque', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  background: radial-gradient(120% 50% at 50% 0%, var(--bg-glow) 0%, var(--bg) 60%) no-repeat, var(--bg);
  background-attachment: fixed;
}
h1, h2 { margin: 0; }
h2 { font-size: 1.05rem; margin-bottom: 8px; }
a { color: inherit; text-decoration: none; }
hr { border: 0; border-top: 1px dashed var(--border); margin: 22px 0; width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 18px)
           calc(env(safe-area-inset-bottom) + 32px) calc(env(safe-area-inset-left) + 18px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100dvh;
}

/* Barra superior */
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 48px; }
.topbar h1 { font-size: 1.1rem; font-weight: 600; text-align: center; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-side { display: flex; align-items: center; }
.tb-side.end { justify-content: flex-end; }
.back { color: var(--muted); font-size: 1rem; padding: 10px 0; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.5rem; padding: 6px 10px; cursor: pointer; line-height: 1; }
.remaining { font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600;
  padding: 12px 16px; min-height: 48px;
  border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 700; }
.btn.danger { background: var(--red); color: var(--on-color); border-color: var(--red); }
.btn.danger-outline { color: var(--red-text); border-color: var(--red); background: transparent; }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.btn.small { padding: 8px 16px; min-height: 40px; font-size: 0.9rem; }
.btn.disabled { color: var(--muted); background: transparent; border-color: transparent; cursor: default; }
.btn:active { opacity: 0.8; }
.btn.block.primary { box-shadow: 0 0 28px var(--glow); }

/* Início */
.hero { padding: 4px 0 0; }
.hero-label { color: var(--muted); font-size: 0.95rem; }
.hero-num { font-size: 4.75rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero-num small { font-size: 1rem; font-weight: 400; letter-spacing: 0; color: var(--muted); margin-left: 8px; }
.hero-sub { margin-top: 10px; color: var(--muted); font-size: 0.95rem; }
.hero-sub strong { color: var(--text); font-weight: 600; }
.legend { display: flex; justify-content: flex-end; gap: 14px; font-size: 0.8rem; margin-bottom: -8px; }
.c-new { color: var(--blue-text); font-weight: 700; }
.c-due { color: var(--green-text); font-weight: 700; }
.link { color: var(--muted); font-size: 0.9rem; text-decoration: underline; text-underline-offset: 3px; }

.sync-badge { color: var(--muted); font-size: 0.85rem; }
.sync-badge:not(:empty)::before { content: " · "; }
details.adv { margin-top: 10px; }
details.adv summary { color: var(--muted); font-size: 0.9rem; cursor: pointer; padding: 6px 0; }

/* Meta diária */
.goal { margin-top: 14px; }
.goal-text { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.goal-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.goal-bar > div { height: 100%; border-radius: 3px; background: var(--primary); transition: width 0.3s; }
.goal.done .goal-bar > div { background: var(--green); }
.goal.done .goal-text { color: var(--green-text); }

/* Aviso de backup */
.banner { display: flex; align-items: center; gap: 12px; justify-content: space-between; background: var(--surface-2); border: 1px solid var(--orange); border-radius: var(--radius); padding: 12px 14px; }
.banner .btn { flex: none; }
.decks, .cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.deck { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--deck-color, var(--primary)); border-radius: var(--radius); padding: 14px 16px; }
.deck-main { flex: 1; min-width: 0; }
.deck-name { font-weight: 600; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-meta { font-size: 0.85rem; }
.counts { display: flex; gap: 14px; min-width: 56px; justify-content: flex-end; font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 40px 12px; }
.empty.big { padding-top: 12vh; }
.empty .check { width: 68px; height: 68px; margin: 0 auto 14px; border-radius: 50%; background: var(--green); color: var(--on-color); font-size: 2rem; font-weight: 800; line-height: 68px; box-shadow: 0 0 36px rgba(76, 214, 148, 0.35); }

/* Baralho */
section { display: flex; flex-direction: column; gap: 8px; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; }
.add-form { display: flex; flex-direction: column; gap: 8px; }
textarea, input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; width: 100%;
}
textarea::placeholder, input::placeholder { color: var(--muted); }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.card-row { width: 100%; text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; cursor: pointer; display: flex; align-items: center; gap: 12px; }
.cr-text { flex: 1; min-width: 0; }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; flex: none; background: var(--surface-2); }

/* Campo de imagem */
.or-sep { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; margin: 4px 0; }
.or-sep::before, .or-sep::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.img-field { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 2px dashed var(--border); border-radius: 16px; background: var(--surface); }
.img-preview img { display: block; max-width: 100%; max-height: 200px; margin: 0 auto; border-radius: 12px; }
.img-empty { text-align: center; padding: 22px 8px; font-size: 0.95rem; }
.img-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.img-actions .btn { min-height: 40px; }
.cr-front { font-weight: 600; white-space: pre-wrap; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cr-back { white-space: pre-wrap; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 0.92rem; }
.cr-status { font-size: 0.75rem; margin-top: 4px; }

/* Estudo */
.study { padding-bottom: calc(env(safe-area-inset-bottom) + 130px); }
.progress { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 2px; box-shadow: 0 0 12px var(--glow); transition: width 0.25s; }
.face {
  flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); border-radius: 28px;
  box-shadow: 0 0 0 1px rgba(108, 184, 255, 0.06), 0 30px 60px var(--shadow);
  padding: 30px 24px; min-height: 40vh; cursor: pointer; position: relative;
}
.face.revealed { cursor: default; justify-content: flex-start; text-align: left; align-items: stretch; }
.side-img { display: block; max-width: 100%; max-height: 56vh; object-fit: contain; border-radius: 14px; margin: 0 auto 18px; }
.face.no-back { justify-content: center; align-items: center; text-align: center; cursor: default; }
.face.no-back .side-img { margin-bottom: 0; }
.face.no-back .side.front { margin-top: 18px; }
.side { white-space: pre-wrap; word-break: break-word; font-size: calc(1.5rem * var(--ts)); font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; width: 100%; }
.side.answer { font-size: calc(1.2rem * var(--ts)); font-weight: 400; line-height: 1.45; color: var(--answer); letter-spacing: 0; }
.tap-hint { position: absolute; bottom: 14px; font-size: 0.8rem; }
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 14px calc(env(safe-area-inset-right) + 18px) calc(env(safe-area-inset-bottom) + 14px) calc(env(safe-area-inset-left) + 18px);
  background: linear-gradient(180deg, rgba(var(--bg-rgb), 0), var(--bg) 28%);
}
.action-bar > * { max-width: 640px; margin: 0 auto; }
.big-btn { min-height: 56px; font-size: 1.05rem; margin-top: 0; }
.rating { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rating .btn { flex-direction: column; gap: 0; padding: 9px 4px; min-height: 62px; color: var(--on-color); border: 0; border-radius: 16px; }
.r-int { font-size: 0.75rem; opacity: 0.75; font-weight: 600; font-variant-numeric: tabular-nums; }
.r-label { font-size: 1rem; font-weight: 800; }
.r-again { background: var(--red); }
.r-hard { background: var(--orange); }
.r-good { background: var(--green); }
.r-easy { background: var(--blue); }

/* Cores de baralho */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 0; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-checked="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface-2) inset; }

/* Estatísticas */
.stat-hero { font-size: 3rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-hero small { font-size: 0.95rem; font-weight: 400; letter-spacing: 0; color: var(--muted); margin-left: 8px; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 100px; margin-top: 14px; }
.chart > i { flex: 1; min-height: 3px; border-radius: 3px 3px 0 0; background: var(--primary); opacity: 0.55; }
.chart > i.today { opacity: 1; }
.chart > i.zero { background: var(--border); opacity: 1; }
.chart-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.stat-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.stat-row:last-child { border-bottom: 1px solid var(--border); }
.stat-row strong { font-variant-numeric: tabular-nums; }
.hard-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.hard-row .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hard-row .n { flex: none; color: var(--red-text); font-weight: 700; font-variant-numeric: tabular-nums; }

/* Diálogos e avisos */
dialog.modal {
  border: 1px solid var(--border); border-radius: 22px; padding: 22px; width: min(92vw, 440px);
  background: var(--surface-2); color: var(--text);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.modal h2 { font-size: 1.15rem; }
dialog.modal p { margin: 8px 0 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.actions .btn { min-height: 44px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px;
  max-width: 88vw; z-index: 10; font-size: 0.92rem; font-weight: 500;
}

/* Tela larga (computador): o cartão ganha mais presença */
@media (min-width: 700px) {
  .screen { max-width: 720px; padding-top: 24px; }
  .hero-num { font-size: 6rem; }
  .side { font-size: calc(1.9rem * var(--ts)); }
  .side.answer { font-size: calc(1.35rem * var(--ts)); }
  .face { min-height: 46vh; padding: 44px 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .progress > div { transition: none; }
}
