/* Granki — feuille de style principale */

:root {
  --bg: #0b1120;
  --bg-soft: #111a2e;
  --surface: #16203a;
  --surface-2: #1d2947;
  --border: #26324f;
  --text: #e8edf7;
  --muted: #93a2c0;
  --primary: #6366f1;
  --primary-600: #4f46e5;
  --new: #38bdf8;
  --learn: #f59e0b;
  --review: #34d399;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --deck: #6366f1;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fc;
    --bg-soft: #eef2fa;
    --surface: #ffffff;
    --surface-2: #f2f5fb;
    --border: #dfe6f3;
    --text: #16203a;
    --muted: #5c6b8a;
    --shadow: 0 8px 24px rgba(24, 39, 75, .10);
  }
}

* { box-sizing: border-box; }

/* Sans cela, les blocs en display:flex/grid ignorent l'attribut hidden. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: inherit; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); margin: .2em 0 .4em; }
h2 { font-size: 1.15rem; margin: 0; }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 6px; }

/* ── Barre supérieure ─────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: .7rem clamp(1rem, 4vw, 2rem);
  padding-top: calc(.7rem + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex; align-items: center; gap: .55rem;
  font-weight: 700; letter-spacing: -.02em; text-decoration: none; font-size: 1.1rem;
}

.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #0ea5e9);
  color: #fff; font-weight: 800;
}

.topnav { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }

.topnav a {
  padding: .4rem .7rem; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-size: .92rem;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav .nav-user { color: var(--text); font-weight: 600; }

.container {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.footer {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: .82rem;
}

.net-status { color: var(--danger); font-weight: 600; }

/* ── Composants ───────────────────────────────────────────────────────── */

.muted { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.05rem; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { padding: .85rem 1.5rem; font-size: 1.05rem; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }

.pill {
  background: rgba(255, 255, 255, .22); border-radius: 999px;
  padding: 0 .5rem; font-size: .85rem; min-width: 1.6em; text-align: center;
}

.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px;
  background: color-mix(in srgb, var(--deck) 22%, transparent);
  color: var(--deck); font-size: .74rem; font-weight: 700; letter-spacing: .04em;
}

.chip {
  padding: .1rem .5rem; border-radius: 999px; font-size: .72rem;
  background: var(--surface-2); color: var(--muted);
}
.chip-new { color: var(--new); }
.chip-learning, .chip-relearning { color: var(--learn); }
.chip-review { color: var(--review); }

.alert {
  padding: .75rem 1rem; border-radius: 12px; margin: 0 0 1rem;
  border: 1px solid var(--border); background: var(--surface);
}
.alert-success { border-color: var(--review); }
.alert-error { border-color: var(--danger); }
.alert-info { border-color: var(--new); }

.empty {
  text-align: center; padding: 3rem 1rem; border: 1px dashed var(--border);
  border-radius: var(--radius); color: var(--muted);
}

/* ── Formulaires ──────────────────────────────────────────────────────── */

label { display: block; margin-bottom: .9rem; font-size: .88rem; color: var(--muted); font-weight: 600; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=color], select, textarea {
  display: block; width: 100%; margin-top: .3rem;
  padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 60%, transparent);
  outline-offset: 1px; border-color: var(--primary);
}
input[type=color] { padding: .2rem; height: 42px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }

.auth-card {
  max-width: 420px; margin: 2rem auto;
  padding: 1.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
}

/* ── Accueil ──────────────────────────────────────────────────────────── */

.hero {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.hero h1 { margin: 0; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1.75rem; }
.stat {
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  padding: .9rem .5rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.stat-n { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat-new { color: var(--new); }
.stat-due { color: var(--review); }
.stat-l { font-size: .78rem; color: var(--muted); }

.deck-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
}

.deck-card {
  display: flex; flex-direction: column; gap: .6rem;
  padding: 1.1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  border-top: 3px solid var(--deck);
}
.deck-card header { display: flex; flex-direction: column; gap: .35rem; }
.deck-desc { margin: 0; color: var(--muted); font-size: .9rem; flex: 1; }
.deck-counts { display: flex; gap: .75rem; font-size: .82rem; flex-wrap: wrap; }
.c-new { color: var(--new); }
.c-due { color: var(--review); }
.c-tot { color: var(--muted); }
.deck-card footer { display: flex; gap: .5rem; margin-top: .35rem; }
.deck-card footer form { margin: 0; }

/* ── Étude ────────────────────────────────────────────────────────────── */

.study { max-width: 640px; margin: 0 auto; }

.study-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.back { text-decoration: none; color: var(--muted); font-size: .9rem; }
.queue-counts { display: flex; gap: .4rem; font-weight: 700; font-size: .85rem; }
.q { padding: .1rem .6rem; border-radius: 999px; background: var(--surface-2); }
.q-new { color: var(--new); }
.q-learn { color: var(--learn); }
.q-rev { color: var(--review); }

.study-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }

.card {
  position: relative;
  display: flex; flex-direction: column;
  min-height: 340px;
  padding: 1.5rem;
  border: 1px solid var(--border); border-top: 4px solid var(--deck);
  border-radius: 20px; background: var(--surface); box-shadow: var(--shadow);
  animation: cardIn .18s ease-out;
  touch-action: pan-y;
  user-select: none;
  transition: transform .2s ease, opacity .18s ease;
  will-change: transform;
}
.card.dragging { transition: none; }

.swipe-hint {
  position: absolute; top: 42%; z-index: 2;
  padding: .3rem .8rem; border-radius: 10px;
  border: 2px solid currentColor; font-weight: 800; font-size: .95rem;
  text-transform: uppercase; letter-spacing: .04em;
  opacity: 0; pointer-events: none;
}
.swipe-hint-left { left: 1.2rem; color: var(--danger); transform: rotate(-12deg); }
.swipe-hint-right { right: 1.2rem; color: var(--review); transform: rotate(12deg); }

.swipe-tip { display: none; text-align: center; font-size: .78rem; color: var(--muted); margin: .8rem 0 0; }
@media (hover: none) { .swipe-tip { display: block; } }

@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } }

.card-deck { font-size: .78rem; color: var(--muted); display: flex; gap: .4rem; align-items: center; }
.card-front { text-align: center; padding: 1.5rem 0 .5rem; }
.c-article { margin: 0; color: var(--deck); font-weight: 700; letter-spacing: .05em; }
.c-front { margin: .2rem 0; font-size: clamp(1.8rem, 7vw, 2.6rem); letter-spacing: -.02em; }
.c-type { margin: 0; font-size: .8rem; color: var(--muted); font-style: italic; }

.card-answer { flex: 1; }
.card-answer hr { border: none; border-top: 1px solid var(--border); margin: .5rem 0 1rem; }
.c-back { margin: 0 0 .4rem; text-align: center; font-size: 1.5rem; color: var(--review); }
.c-plural { margin: 0 0 .6rem; text-align: center; font-size: .85rem; color: var(--muted); }
.c-example {
  margin: 0 0 .6rem; padding: .7rem .9rem; border-left: 3px solid var(--deck);
  background: var(--surface-2); border-radius: 0 10px 10px 0;
}
.c-example span { display: block; }
.c-example em { display: block; color: var(--muted); font-size: .88rem; }
.c-notes { font-size: .85rem; color: var(--muted); }

.card-actions { margin-top: auto; padding-top: 1.75rem; }
.rating-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; }
.rate {
  flex-direction: column; gap: .1rem; padding: .6rem .3rem;
  font-size: .82rem; line-height: 1.2;
}
.rate small { font-size: .7rem; color: var(--muted); font-weight: 500; }
.rate kbd { display: none; }
.rate-1 { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); color: var(--danger); }
.rate-2 { border-color: color-mix(in srgb, var(--learn) 55%, var(--border)); color: var(--learn); }
.rate-3 { border-color: color-mix(in srgb, var(--review) 55%, var(--border)); color: var(--review); }
.rate-4 { border-color: color-mix(in srgb, var(--new) 55%, var(--border)); color: var(--new); }

kbd {
  font: inherit; font-size: .7rem; padding: 0 .35rem; border-radius: 5px;
  background: rgba(255, 255, 255, .18);
}
@media (hover: none) { #btn-show kbd { display: none; } }

.icon-btn {
  position: absolute; top: 1rem; right: 1rem;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-size: 1rem;
}

/* ── Tableaux (admin) ─────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td form { display: inline; }

.panel {
  padding: 1.25rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); margin-bottom: 1.5rem;
}
.panel h2 { margin-bottom: .75rem; }

.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .grow { flex: 1; }

.tabs { display: flex; gap: .35rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.tabs a {
  padding: .45rem .9rem; border-radius: 999px; text-decoration: none;
  border: 1px solid var(--border); color: var(--muted); font-size: .9rem;
}
.tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.pager { display: flex; gap: .4rem; justify-content: center; margin: 1.25rem 0; flex-wrap: wrap; }
.pager a, .pager span { padding: .35rem .7rem; border-radius: 8px; border: 1px solid var(--border); text-decoration: none; font-size: .85rem; }
.pager .current { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Stats ────────────────────────────────────────────────────────────── */

.bars { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding: .5rem 0; }
.bars .bar { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .bar span { position: absolute; bottom: -1.4rem; left: 50%; transform: translateX(-50%); font-size: .62rem; color: var(--muted); }
.bars-wrap { padding-bottom: 1.5rem; }

@media (max-width: 560px) {
  .topnav a { padding: .35rem .5rem; font-size: .85rem; }
  .hero-actions { width: 100%; }
  .hero-actions .btn { width: 100%; }
  .rate { font-size: .74rem; }
}
