:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  background: #2d333b;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  color: var(--purple);
}

/* ============ Landing ============ */
.hero {
  text-align: center;
  padding: 4rem 1rem 2rem;
  background: linear-gradient(180deg, #1a2332 0%, var(--bg) 100%);
}
.hero h1 {
  font-size: 3rem;
  margin: 0 0 0.5rem;
  background: linear-gradient(135deg, #58a6ff, #bc8cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .subtitle { font-size: 1.2rem; color: var(--muted); margin: 0.5rem 0; }
.hero .hint { color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  color: var(--text);
  display: block;
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 10px 30px rgba(88, 166, 255, 0.15);
  text-decoration: none;
}
.card h2 { margin: 0.5rem 0; font-size: 1.4rem; }
.card p { color: var(--muted); }
.card .level {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: 20px;
  background: #2d333b;
}
.card-1 .level { background: #143d20; color: var(--green); }
.card-2 .level { background: #3d2e14; color: var(--yellow); }
.card-3 .level { background: #3d1414; color: var(--red); }
.card .tag {
  display: inline-block;
  margin-top: 1rem;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--accent);
}

.howto {
  max-width: 900px;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.howto h3 { margin-top: 0; }
.howto .warn {
  margin-top: 1rem;
  padding: 1rem;
  background: #3d2e14;
  border-left: 4px solid var(--yellow);
  border-radius: 4px;
  color: var(--text);
}

footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

/* ============ Chat page ============ */
.chat-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.chat-header h1 { margin: 0; flex: 1; font-size: 1.4rem; }
.back {
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.back:hover { text-decoration: none; background: var(--panel-2); }
.level-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: bold;
}
.level-badge.facil { background: #143d20; color: var(--green); }
.level-badge.medio { background: #3d2e14; color: var(--yellow); }
.level-badge.dificil { background: #3d1414; color: var(--red); }

.brief {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}
.brief details { margin-top: 0.5rem; }
.brief summary { cursor: pointer; color: var(--accent); }
.brief ul { margin: 0.5rem 0 0; padding-left: 1.5rem; color: var(--muted); }

.chat-box {
  min-height: 350px;
  max-height: 55vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.8rem;
}
.message {
  margin: 0.8rem 0;
  display: flex;
  gap: 0.6rem;
}
.message.user { justify-content: flex-end; }
.message .bubble {
  max-width: 75%;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.message.user .bubble {
  background: var(--accent);
  color: #0d1117;
  border-bottom-right-radius: 4px;
}
.message.assistant .bubble {
  background: var(--panel-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.message.assistant .bubble.thinking { color: var(--muted); font-style: italic; }
.message.error .bubble { background: #3d1414; color: var(--red); border: 1px solid var(--red); }

.chat-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.chat-form input {
  flex: 1;
  padding: 0.8rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}
.chat-form input:focus { outline: none; border-color: var(--accent); }
.chat-form button, .flag-box button {
  padding: 0.8rem 1.5rem;
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  font-size: 1rem;
}
.chat-form button:hover, .flag-box button:hover { opacity: 0.85; }
.chat-form button:disabled { opacity: 0.5; cursor: not-allowed; }

.flag-box {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
}
.flag-box h3 { margin-top: 0; }
.flag-box form { display: flex; gap: 0.5rem; }
.flag-box input {
  flex: 1;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.flag-box input:focus { outline: none; border-color: var(--accent); }
#flag-result {
  margin-top: 0.8rem;
  font-weight: bold;
}
#flag-result.ok { color: var(--green); }
#flag-result.ko { color: var(--red); }
