:root {
	--bg: #0a0e17;
	--bg-2: #0e1320;
	--surface: #141b2b;
	--surface-2: #1c2439;
	--surface-3: #26304a;
	--border: rgba(255, 255, 255, .07);
	--text: #eaedf4;
	--muted: #8b94ab;
	--accent: #2dd4bf;
	--accent-ink: #04322b;
	--indigo: #8b8cf0;
	--good: #34d399;
	--bad: #fb7185;
	--warn: #fbbf24;
	--radius: 16px;
	--radius-sm: 10px;
	--maxw: 680px;
	--shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
	background:
		radial-gradient(1200px 600px at 50% -10%, rgba(45, 212, 191, .06), transparent 60%),
		var(--bg);
	color: var(--text);
	font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 16px;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
	-webkit-tap-highlight-color: transparent;
}

body { padding-bottom: env(safe-area-inset-bottom); }
#app { min-height: 100vh; }

h1, h2, h3 { letter-spacing: -.02em; }
h2 { font-size: 1.35rem; font-weight: 700; }
a { color: var(--accent); text-decoration: none; }
code { background: var(--surface-2); padding: .1em .4em; border-radius: 6px; font-size: .85em; }
hr { border: none; border-top: 1px solid var(--border); }

button {
	font: inherit;
	font-weight: 550;
	cursor: pointer;
	border: 1px solid transparent;
	border-radius: var(--radius-sm);
	padding: .72rem 1rem;
	background: var(--surface-2);
	color: var(--text);
	transition: transform .06s ease, background .15s, border-color .15s, opacity .15s;
	display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
}
button:hover { background: var(--surface-3); }
button:active { transform: translateY(1px) scale(.99); }
button.primary {
	background: linear-gradient(180deg, var(--accent), #21b6a3);
	color: var(--accent-ink); font-weight: 700; border-color: rgba(255,255,255,.12);
}
button.primary:hover { filter: brightness(1.05); background: linear-gradient(180deg, var(--accent), #21b6a3); }
button.ghost { background: transparent; border-color: var(--border); color: var(--text); }
button.ghost:hover { background: var(--surface); }
button.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
button.danger:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); }
button.icon-btn { padding: .55rem; aspect-ratio: 1; }
button:disabled { opacity: .5; cursor: default; }
button svg { font-size: 1.2rem; }

input, textarea, select {
	font: inherit;
	width: 100%;
	padding: .72rem .85rem;
	border-radius: var(--radius-sm);
	border: 1px solid var(--border);
	background: var(--bg-2);
	color: var(--text);
	transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
	outline: none; border-color: var(--accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 1.1rem; }

.topbar {
	position: sticky; top: 0; z-index: 10;
	display: flex; align-items: center; gap: .7rem;
	padding: .85rem 1.1rem;
	background: color-mix(in srgb, var(--bg) 82%, transparent);
	backdrop-filter: saturate(1.4) blur(10px);
	border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; flex: 1; font-weight: 800; letter-spacing: -.02em; }
.brand .logo { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
	background: linear-gradient(140deg, var(--accent), var(--indigo)); color: #04322b; font-weight: 900; font-size: .95rem; }
.topbar .who { color: var(--muted); font-size: .85rem; }
.spacer { flex: 1; }

.tabbar {
	position: sticky; bottom: 0; z-index: 10;
	display: flex; justify-content: space-around;
	background: color-mix(in srgb, var(--bg) 88%, transparent);
	backdrop-filter: saturate(1.4) blur(10px);
	border-top: 1px solid var(--border);
	padding: .45rem 0 calc(.45rem + env(safe-area-inset-bottom));
}
.tabbar a {
	flex: 1; text-align: center; color: var(--muted); font-size: .7rem; font-weight: 600;
	padding: .35rem; display: flex; flex-direction: column; align-items: center; gap: .28rem;
	border-radius: 10px; transition: color .15s;
}
.tabbar a .ico { font-size: 1.4rem; }
.tabbar a.active { color: var(--accent); }

.card-tile {
	background: linear-gradient(180deg, var(--surface), var(--bg-2));
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 1rem 1.1rem;
	margin-bottom: .75rem;
	display: flex; align-items: center; gap: .85rem;
	transition: border-color .15s, transform .06s;
}
.card-tile:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
.card-tile .grow { flex: 1; min-width: 0; }
.card-tile h3 { margin: 0 0 .25rem; font-size: 1.05rem; }
.card-tile .meta { color: var(--muted); font-size: .82rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.badge {
	display: inline-flex; align-items: center; gap: .25rem;
	padding: .14rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 700;
	border: 1px solid transparent;
}
.badge.due { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge.new { background: color-mix(in srgb, var(--indigo) 18%, transparent); color: var(--indigo); }
.badge.default { background: var(--surface-2); color: var(--muted); }

.stack { display: flex; flex-direction: column; gap: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 1.1rem; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: .4rem 0; }

/* --- Dashboard --- */
.hello { font-size: 1.5rem; font-weight: 800; margin: .2rem 0 .1rem; }
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.stat {
	background: linear-gradient(180deg, var(--surface), var(--bg-2));
	border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem;
	display: flex; flex-direction: column; gap: .15rem;
}
.stat .n { font-size: 1.7rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.stat .l { font-size: .72rem; color: var(--muted); font-weight: 600; }
.stat.accent .n { color: var(--accent); }
.stat .row-ico { display: flex; align-items: center; gap: .3rem; color: var(--warn); font-size: 1.7rem; font-weight: 800; }

.panel {
	background: linear-gradient(180deg, var(--surface), var(--bg-2));
	border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem;
}

/* --- Heatmap (façon GitLab) --- */
/* Aligné à droite : la colonne du jour reste toujours visible ;
   si une colonne doit être rognée, c'est la plus ancienne (à gauche). */
.heatmap { overflow: hidden; display: flex; justify-content: flex-end; }
.heatmap-grid {
	display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px);
	gap: 3px; width: max-content;
}
.hm-cell { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); }
.hm-cell[data-l="1"] { background: #0e4429; }
.hm-cell[data-l="2"] { background: #16794a; }
.hm-cell[data-l="3"] { background: #26a641; }
.hm-cell[data-l="4"] { background: #39d353; }
.heatmap-foot { display: flex; align-items: center; justify-content: space-between; margin-top: .5rem; color: var(--muted); font-size: .72rem; }
.heatmap-legend { display: flex; align-items: center; gap: 3px; }
.heatmap-legend .hm-cell { width: 10px; height: 10px; }

/* --- Grille de cartes (code couleur SRS) --- */
.legend { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .74rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.legend i.s-new { background: var(--surface-3); }
.legend i.s-hard { background: var(--bad); }
.legend i.s-good { background: var(--good); }
.legend i.s-easy { background: var(--accent); }

.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: .55rem; }
.ccell {
	position: relative; min-height: 88px; padding: .5rem; cursor: pointer; overflow: hidden;
	display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; text-align: center;
	background: linear-gradient(180deg, var(--surface), var(--bg-2));
	border: 1px solid var(--border); border-left: 4px solid var(--st, var(--surface-3));
	border-radius: 12px; transition: transform .06s, border-color .15s;
}
.ccell:hover { transform: translateY(-1px); }
.ccell.s-new { --st: var(--surface-3); }
.ccell.s-hard { --st: var(--bad); }
.ccell.s-good { --st: var(--good); }
.ccell.s-easy { --st: var(--accent); }
.ccell .cf { font-size: 1.5rem; font-weight: 700; line-height: 1.1; word-break: break-word; }
.ccell .cr { font-size: .68rem; color: var(--muted); }
.ccell .cb { font-size: 1rem; color: var(--accent); word-break: break-word; }
.ccell .due-dot { position: absolute; top: 6px; left: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--bg-2); }
.ccell .del {
	position: absolute; top: 3px; right: 3px; padding: 2px; width: 20px; height: 20px;
	background: color-mix(in srgb, var(--bg) 55%, transparent); color: var(--bad);
	border: none; border-radius: 6px; font-size: .8rem; opacity: 0; transition: opacity .15s;
}
.ccell:hover .del { opacity: 1; }

/* --- Étude --- */
.study-card {
	background: linear-gradient(180deg, var(--surface), var(--bg-2));
	border: 1px solid var(--border);
	border-radius: 22px; min-height: 44vh;
	display: flex; flex-direction: column; align-items: center; justify-content: center;
	padding: 2rem 1.2rem; text-align: center; gap: 1rem; box-shadow: var(--shadow);
}
.study-card .front { font-size: clamp(2.4rem, 13vw, 5.2rem); font-weight: 800; letter-spacing: -.02em; }
.study-card .reading { color: var(--accent); font-size: 1.3rem; font-weight: 600; }
.study-card .back { font-size: 1.6rem; }
.study-card .extra { color: var(--muted); }
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.grade-row button { padding: .95rem .3rem; font-size: .82rem; font-weight: 700; border: 1px solid var(--border); }
.g-again { color: var(--bad); } .g-again:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.g-hard { color: var(--warn); } .g-hard:hover { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.g-good { color: var(--good); } .g-good:hover { background: color-mix(in srgb, var(--good) 14%, transparent); }
.g-easy { color: var(--accent); } .g-easy:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.progress { height: 6px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--good)); transition: width .25s; }

/* --- Party --- */
.pin { font-size: 2.8rem; letter-spacing: .45rem; font-weight: 800; text-align: center;
	background: linear-gradient(120deg, var(--accent), var(--indigo)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.option { text-align: left; padding: 1rem 1.1rem; border: 1px solid var(--border); font-weight: 600; }
.option:hover { border-color: var(--accent); }
.option.correct { background: color-mix(in srgb, var(--good) 22%, transparent); border-color: var(--good); }
.option.wrong { background: color-mix(in srgb, var(--bad) 22%, transparent); border-color: var(--bad); }
.scoreboard { list-style: none; padding: 0; margin: 0; }
.scoreboard li { display: flex; justify-content: space-between; align-items: center; padding: .7rem .9rem;
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: .45rem; }
.scoreboard li strong { color: var(--accent); }

/* --- Tracé --- */
.trace-wrap { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.trace-stage { position: relative; width: min(80vw, 360px); aspect-ratio: 1;
	background: linear-gradient(180deg, var(--surface), var(--bg-2)); border: 1px solid var(--border);
	border-radius: 22px; touch-action: none; box-shadow: var(--shadow); }
.trace-stage svg, .trace-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.kana-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.kana-cell { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 1.7rem;
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); position: relative; cursor: pointer;
	transition: border-color .15s, transform .06s; }
.kana-cell:hover { border-color: var(--accent); }
.kana-cell.done { border-color: var(--good); box-shadow: inset 0 0 0 1px var(--good); }
.kana-cell .dot { position: absolute; bottom: 3px; right: 6px; font-size: .58rem; color: var(--muted); }

.toast {
	position: fixed; left: 50%; bottom: 5.2rem; transform: translateX(-50%);
	background: var(--surface-3); border: 1px solid var(--border); padding: .7rem 1.15rem;
	border-radius: 999px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; font-size: .9rem;
}

.login-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; }
.login-box { width: 100%; max-width: 380px; background: linear-gradient(180deg, var(--surface), var(--bg-2));
	border: 1px solid var(--border); padding: 2.2rem; border-radius: 22px; box-shadow: var(--shadow); }
.login-box .logo-lg { width: 52px; height: 52px; margin: 0 auto 1rem; border-radius: 14px; display: grid; place-items: center;
	background: linear-gradient(140deg, var(--accent), var(--indigo)); color: #04322b; font-weight: 900; font-size: 1.6rem; }

.spinner { width: 30px; height: 30px; border: 3px solid var(--surface-2); border-top-color: var(--accent);
	border-radius: 50%; animation: spin .8s linear infinite; margin: 2.5rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-text { color: var(--bad); font-size: .88rem; }
.offline-banner { background: var(--warn); color: #422006; text-align: center; padding: .35rem; font-size: .8rem; font-weight: 600; }
