:root {
  --bg: #f6f3ec;
  --card: #fffdf8;
  --ink: #2a2a33;
  --muted: #7a7568;
  --line: #e4ddcd;
  --accent: #b5122e;      /* vermelho "carta de baralho" */
  --accent-2: #1f6f6f;    /* verde-azulado */
  --gold: #c99a2e;
  --shadow: 0 8px 24px rgba(60, 45, 20, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 22px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 1.25rem; font-weight: 700; color: var(--accent); text-decoration: none; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.topbar nav a { color: var(--ink); text-decoration: none; font-weight: 500; }
.topbar nav a:hover { color: var(--accent); }
.inline { display: inline; margin: 0; }
button.link {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font: inherit; padding: 0;
}
button.link:hover { color: var(--accent); }

.container { max-width: 820px; margin: 32px auto; padding: 0 18px; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 30px 12px; }

.messages { list-style: none; padding: 0; margin: 0 0 18px; }
.msg { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; }
.msg.success { background: #e5f3ec; color: #1c6b45; }
.msg.error { background: #fbe6e8; color: #9c1524; }

h1 { font-size: 1.7rem; margin: 0 0 6px; }
.subtitle { color: var(--muted); margin-top: 0; }

/* Cards / grid */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .num { font-size: 2rem; font-weight: 700; color: var(--accent-2); }
.stat .label { color: var(--muted); font-size: .9rem; }

.progressbar { background: var(--line); border-radius: 999px; height: 12px; overflow: hidden; margin: 8px 0 4px; }
.progressbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); }

.btn {
  display: inline-block; padding: 12px 22px; border-radius: 12px; border: none;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 1rem;
  text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--accent-2); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.block { display: block; width: 100%; text-align: center; }

/* Estudo */
.flashcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 34px 30px; box-shadow: var(--shadow); text-align: center;
}
.pill { display: inline-block; font-size: .78rem; padding: 4px 12px; border-radius: 999px;
  background: #efe8d6; color: var(--muted); margin-bottom: 14px; }
.pill.new { background: #e5f0ea; color: var(--accent-2); }
.pill.review { background: #f6e4c8; color: var(--gold); }
.it-text { font-size: 1.7rem; font-weight: 600; margin: 12px 0; }
.pt-text { font-size: 1.25rem; color: var(--accent-2); margin: 8px 0 4px; }
.divider { border: none; border-top: 1px dashed var(--line); margin: 22px 0; }
.hint { color: var(--muted); font-size: .9rem; }
.chapter-tag { color: var(--muted); font-size: .82rem; letter-spacing: .04em; text-transform: uppercase; }

.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 6px; }
.ratings button {
  padding: 14px 8px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; font-size: .95rem;
}
.ratings button small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; margin-top: 3px; }
.r1 { color: #9c1524; } .r1:hover { background: #fbe6e8; }
.r2 { color: #b06a12; } .r2:hover { background: #fbf0dd; }
.r3 { color: #1c6b45; } .r3:hover { background: #e5f3ec; }
.r4 { color: #145a86; } .r4:hover { background: #e2eef7; }

.session-info { display: flex; gap: 18px; justify-content: center; color: var(--muted);
  font-size: .9rem; margin-bottom: 18px; }
.session-info b { color: var(--ink); }

/* Tradução palavra por palavra */
.it-text.words-active .word { cursor: help; border-radius: 4px; transition: background .12s; }
.it-text.words-active .word:hover { background: #f6e4c8; }
.word-hint { margin-top: -4px; }

.word-tip {
  position: absolute; z-index: 50;
  transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 6px 12px; border-radius: 8px;
  font-size: .95rem; font-weight: 500; line-height: 1.3;
  max-width: 260px; text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .12s;
}
.word-tip.visible { opacity: 1; visibility: visible; }
.word-tip::after {
  content: ""; position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent; border-bottom-color: var(--ink);
}

/* Áudio / pronúncia */
.audio-controls { display: flex; gap: 14px; align-items: center; justify-content: center;
  margin: 4px 0 2px; flex-wrap: wrap; }
.audio-btn { padding: 8px 16px; font-size: .92rem; }
.slow-toggle { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.audio-warn { color: var(--gold); }

/* Caixa de explicação didática (verbos, expressões, nuances) */
.explanation {
  text-align: left; margin: 16px 0 4px; border: 1px solid var(--line);
  border-radius: 12px; background: #fbf7ee; padding: 4px 14px;
}
.explanation > summary {
  cursor: pointer; font-weight: 600; color: var(--accent-2);
  padding: 8px 2px; list-style: none;
}
.explanation > summary::-webkit-details-marker { display: none; }
.explanation > summary::before { content: "▸ "; color: var(--gold); }
.explanation[open] > summary::before { content: "▾ "; }
.explanation-body { font-size: .95rem; line-height: 1.5; padding: 2px 2px 10px; }
.explanation-body p { margin: 8px 0; }
.explanation-body ul { margin: 6px 0; padding-left: 20px; }
.explanation-body li { margin: 4px 0; }
.explanation-body strong { color: var(--ink); }
.explanation-body em { color: var(--accent); font-style: italic; }
.explanation-body code {
  background: #efe8d6; padding: 1px 5px; border-radius: 5px; font-size: .9em;
}

/* Alavanca (interruptor) de repetição automática */
.switch-toggle { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.switch-input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative; display: inline-block; width: 38px; height: 22px;
  background: var(--line); border-radius: 999px; transition: background .18s ease; flex: none;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .18s ease;
}
.switch-input:checked + .switch-track { background: var(--accent-2); }
.switch-input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* Auth */
.authbox { max-width: 400px; margin: 20px auto; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.authbox p { margin: 12px 0; }
.authbox label { display: block; font-weight: 600; margin-bottom: 4px; }
.authbox input { width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 1rem; }
.helptext, .errorlist { font-size: .82rem; color: var(--muted); }
.errorlist { color: var(--accent); list-style: none; padding: 0; }

/* Livro */
.book p { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--gold);
  border-radius: 8px; padding: 12px 16px; margin: 10px 0; }
.book .num { color: var(--muted); font-size: .75rem; margin-right: 8px; }
.book .pt { display: block; color: var(--accent-2); font-size: .95rem; margin-top: 4px; }
.book h3 { margin: 26px 0 6px; color: var(--accent); }
