/* ============================================
   Quem é Mais Provável? — Tema
   ============================================ */

/*
 * Tokens únicos para os dois temas. `light-dark()` escolhe o valor conforme
 * `color-scheme`, que o theme.js ajusta para o tema escolhido (ou o do
 * sistema, na primeira visita). Isso evita duplicar a lista de cores e
 * dispensa qualquer script inline no <head> — importante porque a CSP do
 * projeto só libera scripts de 'self'.
 */
:root {
  color-scheme: light dark;

  /* Paleta alinhada ao My-Website (temis.com.br / tokens --dev-*) */
  --bg: light-dark(#faf9f7, #0c0c0c);
  --surface: light-dark(#f2f0ec, #141414);
  --surface-hover: light-dark(#e8e5de, #1e1e1e);
  --text: light-dark(#1a1a18, #e9e7e3);
  --muted: light-dark(#6b6862, #8d8a85);
  --line: light-dark(#dedbd5, #262626);
  --line-hover: light-dark(#b8b4ac, #3a3a3a);
  --accent: #ab74e8;
  --accent-hover: #ab74e8;
  --on-accent: #0c0c0c;
  --focus-ring: #ab74e8;
  --shadow-sm: light-dark(0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.35));
  --shadow-md: light-dark(0 4px 12px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.35));

  --radius: 12px;
  --radius-sm: 8px;
}

/* Tema explícito do usuário (data-theme) tem prioridade sobre o sistema.
   O theme.js define data-theme no <html>; o color-scheme no CSS garante
   que light-dark() reavalie sem depender de inline style. */
:root[data-theme="light"] {
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
}

/* Híbrido (sem data-theme): segue o sistema. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
  }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  transition: background-color 0.15s, color 0.15s;
}

body {
  min-width: 0;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  background: none;
  border: none;
  padding: 0;
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: var(--line-hover);
}

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

/* — layout — */

.app {
  width: min(100%, 420px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* — topbar — */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.brand:hover {
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 3px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark circle {
  fill: currentColor;
  stroke: none;
}

/* — theme toggle — */

.theme-toggle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--line-hover);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: block; }

/* Antes do JS carregar, segue o sistema. Depois, data-theme prevalece. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
}

:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }

/* — card — */

.card {
  flex: 1 1 auto;
  padding: clamp(28px, 7vw, 42px);
  display: flex;
  flex-direction: column;
  min-height: min(320px, 44svh);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.card.is-changing {
  opacity: 0.3;
  transform: translateY(6px);
}

.question {
  margin: auto 0;
  max-width: 18ch;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

/* — actions — */

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.next-button {
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.14s, background-color 0.14s;
}

.next-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent);
}

.next-button svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

/* — noscript — */

.noscript-message {
  margin: 0;
  padding: 16px;
  color: var(--text);
  text-align: center;
}

/* — responsive — */

@media (orientation: landscape) and (max-height: 520px) {
  .app {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .card {
    min-height: 0;
  }

  .action-row {
    flex-direction: row;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
