:root {
  --bg: #f6f3ee; --card: #fffdf9; --text: #26211c; --muted: #7a7065; --line: #e4ddd3;
  --accent: #c0392b; --accent-soft: #f6dcd8; --ok: #2e8b57; --ok-soft: #d7efe1; --warn: #c98a12; --warn-soft: #f8ebcf;
  --blue: #2f6fb0; --blue-soft: #dbe8f6; --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  --hanzi: "PingFang TC", "Heiti TC", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", sans-serif;
  --kai: "BiauKai", "DFKai-SB", "Kaiti TC", "STKaiti", "TW-Kai", var(--hanzi);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #181614; --card: #22201d; --text: #eee8e0; --muted: #a3998d; --line: #37332e;
    --accent: #e0604f; --accent-soft: #4a2622; --ok: #5cc28a; --ok-soft: #1f3a2b; --warn: #e3ab3f; --warn-soft: #43361a;
    --blue: #6aa5e3; --blue-soft: #1d2f44; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
[lang="zh-Hant"], .hz { font-family: var(--hanzi); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Kopfzeile */
header.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
header.top .logo { font-family: var(--hanzi); font-size: 1.4rem; font-weight: 700; color: var(--accent); }
header.top .spacer { flex: 1; }
.timer-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 5px 12px 5px 6px; cursor: pointer; font-variant-numeric: tabular-nums; font-weight: 600; }
.timer-chip .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) var(--p, 0%), var(--line) 0); }
.timer-chip .dot::after { content: ""; width: 18px; height: 18px; border-radius: 50%; background: var(--card); }
.timer-chip.running { border-color: var(--accent); }
.timer-chip.done .dot { background: var(--ok); }

/* Navigation unten */
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
nav.tabs a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: .75rem; padding: 4px 0; }
nav.tabs a .i { display: block; font-size: 1.35rem; line-height: 1.3; font-family: var(--hanzi); }
nav.tabs a.active { color: var(--accent); font-weight: 600; }
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 96px; }
  nav.tabs { top: 0; bottom: 0; right: auto; width: 96px; flex-direction: column; justify-content: flex-start;
    gap: 6px; padding-top: 80px; border-top: 0; border-right: 1px solid var(--line); }
  nav.tabs a { flex: 0; padding: 10px 0; }
}

main { max-width: 760px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: 6px 0 14px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 620px) { .grid2 { grid-template-columns: 1fr; } }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 16px;
  cursor: pointer; font-weight: 600; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.big { padding: 14px 20px; font-size: 1.05rem; width: 100%; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.danger { color: var(--accent); }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
label.check input { width: 20px; height: 20px; }

/* Startseite */
.today { display: flex; gap: 20px; align-items: center; }
.ring { --p: 0; width: 132px; height: 132px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); }
.ring.done { background: conic-gradient(var(--ok) calc(var(--p) * 1%), var(--line) 0); }
.ring > div { width: 108px; height: 108px; border-radius: 50%; background: var(--card); display: grid; place-items: center;
  text-align: center; }
.ring b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ring small { color: var(--muted); }
.streak-head { display: flex; align-items: baseline; gap: 10px; }
.streak-num { font-size: 2rem; font-weight: 800; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.cal div { aspect-ratio: 1; border-radius: 6px; background: var(--line); opacity: .55; position: relative; }
.cal .partial { background: var(--warn); opacity: .75; }
.cal .full { background: var(--ok); opacity: 1; }
.cal .frozen { background: var(--blue); opacity: .8; }
.cal .missed { background: var(--line); opacity: .9; }
.cal .is-today { outline: 2px solid var(--text); outline-offset: 1px; }
.cal .wd { background: none; aspect-ratio: auto; text-align: center; font-size: .7rem; color: var(--muted); opacity: 1; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .75rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.stat { font-size: .9rem; color: var(--muted); }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.modes .btn { padding: 12px 6px; }

/* Lernkarte */
.study-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; color: var(--muted); font-size: .9rem; }
.flash { text-align: center; padding: 26px 16px; min-height: 340px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; }
.flash .kind { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.flash .hanzi { font-family: var(--hanzi); font-size: clamp(3.5rem, 15vw, 6.5rem); line-height: 1.15; font-weight: 500; }
.flash .pinyin { font-size: 1.6rem; color: var(--blue); }
.flash .german { font-size: 1.35rem; font-weight: 600; }
.flash .note { color: var(--muted); font-size: .95rem; }
.speak { border: 0; background: var(--blue-soft); color: var(--blue); width: 44px; height: 44px; border-radius: 50%;
  cursor: pointer; font-size: 1.2rem; }
.reveal-zone { display: flex; flex-direction: column; gap: 8px; align-items: center; min-height: 40px; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.ratings .btn { padding: 14px 4px; font-size: .95rem; }
.ratings .r1 { background: var(--accent-soft); border-color: transparent; }
.ratings .r2 { background: var(--warn-soft); border-color: transparent; }
.ratings .r3 { background: var(--ok-soft); border-color: transparent; }
.ratings .r4 { background: var(--blue-soft); border-color: transparent; }
.ratings .suggested { outline: 3px solid var(--text); outline-offset: 1px; }
.ratings kbd { display: block; font-size: .7rem; color: var(--muted); font-family: inherit; }
.feedback { font-weight: 700; font-size: 1.1rem; }
.feedback.ok { color: var(--ok); } .feedback.meh { color: var(--warn); } .feedback.no { color: var(--accent); }
.answer-input { font-size: 1.4rem !important; text-align: center; max-width: 420px; }

/* Schreiben mit dem Stift */
.pad-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.pad-chars { display: flex; gap: 8px; justify-content: center; min-height: 48px; }
.pad-chars span { width: 44px; height: 44px; border: 1px dashed var(--line); border-radius: 8px; display: grid;
  place-items: center; font-family: var(--hanzi); font-size: 1.6rem; }
.pad-chars span.cur { border: 2px solid var(--accent); }
.pad-chars span.done { border-style: solid; color: var(--ok); }
.pad { position: relative; width: min(78vw, 360px, 52vh); aspect-ratio: 1; border: 2px solid var(--accent);
  border-radius: 6px; background-color: var(--card); touch-action: none;
  background-image: linear-gradient(var(--line), var(--line)), linear-gradient(var(--line), var(--line)),
    linear-gradient(45deg, transparent calc(50% - .5px), var(--line) calc(50% - .5px), var(--line) calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(-45deg, transparent calc(50% - .5px), var(--line) calc(50% - .5px), var(--line) calc(50% + .5px), transparent calc(50% + .5px));
  background-size: 100% 1px, 1px 100%, 100% 100%, 100% 100%; background-position: center; background-repeat: no-repeat; }
.pad canvas, .pad svg { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.pad .ref { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--kai);
  font-size: calc(min(78vw, 360px, 52vh) * .82); color: var(--accent); opacity: .22; pointer-events: none; line-height: 1; }
.compare { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; }
.compare img { width: 120px; height: 120px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.compare .hanzi { font-size: 5rem; }

/* Wörter */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; font-size: .9rem; white-space: nowrap; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.wlist { list-style: none; margin: 0; padding: 0; }
.wlist li { display: grid; grid-template-columns: minmax(70px, auto) 1fr auto; gap: 4px 12px; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.wlist li:last-child { border-bottom: 0; }
.wlist .h { font-family: var(--hanzi); font-size: 1.5rem; grid-row: span 2; }
.wlist .p { color: var(--blue); font-size: .9rem; }
.wlist .g { font-size: .95rem; }
.wlist .lvl { grid-row: span 2; font-size: .7rem; color: var(--muted); text-align: right; }
.level { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-left: 2px; }
.level.on { background: var(--ok); }

a.btn { text-decoration: none; text-align: center; }

/* Belohnungen */
.session-bar { display: flex; align-items: center; gap: 10px; margin: -4px 0 12px; }
.session-bar .progress { margin: 0; height: 10px; border-radius: 5px; }
.session-bar .progress > i { transition: width .4s ease; border-radius: 5px; }
.combo { font-weight: 800; color: var(--warn); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }
.combo.pop { animation: comboPop .35s ease-out; }
@keyframes comboPop { 0% { transform: scale(1); } 40% { transform: scale(1.45); } 100% { transform: scale(1); } }
.flash { position: relative; transition: box-shadow .3s, border-color .3s; }
.flash.enter { animation: cardIn .25s ease-out; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.flash.fx-ok { border-color: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.flash.fx-ok .feedback, .flash.fx-close .feedback { animation: pop2 .35s ease-out; }
@keyframes pop2 { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.flash.fx-close { border-color: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.flash.fx-wrong { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.new-pill { position: absolute; top: 12px; right: 12px; font-size: .72rem; font-weight: 700; color: var(--blue);
  background: var(--blue-soft); padding: 2px 8px; border-radius: 999px; }
.xp-float { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-weight: 800; color: var(--warn);
  pointer-events: none; animation: xpUp 1.1s ease-out forwards; }
@keyframes xpUp { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -34px) scale(1); } }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 100; }
.summary { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.summary > div { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 84px; }
.summary b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.summary span { font-size: .8rem; color: var(--muted); }
.xp-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.xp-row .progress { margin: 0; }
.lvl-badge { background: var(--warn-soft); color: var(--warn); font-weight: 800; font-size: .8rem; padding: 3px 10px; border-radius: 999px; }
.streak-num.lit { animation: flicker 2.4s ease-in-out infinite; display: inline-block; transform-origin: 30% 90%; }
@keyframes flicker { 0%, 100% { transform: scale(1) rotate(0); } 50% { transform: scale(1.06) rotate(-2deg); } }
@media (prefers-reduced-motion: reduce) { .streak-num.lit, .combo.pop, .flash.enter { animation: none; } }

/* Schreibtraining */
.pad.large { width: min(86vw, 520px, 56vh); }
.drill-word { font-family: var(--hanzi); font-size: 2.2rem; display: flex; align-items: center; gap: 12px; justify-content: center; }
.drill-word b.cur-char { color: var(--accent); font-weight: inherit; border-bottom: 3px solid var(--accent); }
.steps { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 4px 0 2px; }
.steps span { font-size: .78rem; padding: 3px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.steps span.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
#drill-msg { min-height: 1.5em; font-size: 1rem; }
#drill-msg.muted { color: var(--muted); font-weight: 500; }

/* Kurz-Session */
.quick-btn { background: var(--warn-soft); border-color: transparent; }
.quick-clock { color: var(--warn); font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.quick-clock.ending { color: var(--accent); animation: comboPop .5s ease-in-out infinite; }

/* Hanzi-Methode */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.char-tile { aspect-ratio: 1; display: grid; place-items: center; font-family: var(--hanzi); font-size: 1.6rem; text-decoration: none;
  color: var(--text); border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.char-tile.has { background: var(--ok-soft); border-color: var(--ok); }
.char-tile.unseen { opacity: .45; }
.hm-head { display: flex; gap: 16px; align-items: flex-start; }
.hm-char { width: 110px; height: 110px; flex: none; display: grid; place-items: center; font-family: var(--hanzi); font-size: 5rem;
  line-height: 1; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.parts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.part { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: .9rem; }
.part b { font-family: var(--hanzi); font-size: 1.15rem; margin-right: 4px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 620px) { .grid3 { grid-template-columns: 1fr; } }
textarea { resize: vertical; line-height: 1.5; }
.sys-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; margin-bottom: 6px; }
.sys-row span { font-weight: 600; font-size: .9rem; }
.hm-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.hm-tags span { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: .9rem; }
.hm-scene { max-width: 560px; text-align: left; background: var(--bg); border-radius: 12px; padding: 12px 14px; line-height: 1.55; }
.btn.r1 { background: var(--accent-soft); border-color: transparent; }

/* Kurs / Checkliste */
.stage summary { list-style: none; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.stage summary::-webkit-details-marker { display: none; }
.stage summary h2 { margin: 0; flex: 1; }
.stage summary::after { content: "▾"; color: var(--muted); transition: transform .2s; }
.stage:not([open]) summary::after { transform: rotate(-90deg); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 10px 0 4px; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.tasks { list-style: none; margin: 8px 0 0; padding: 0; }
.tasks li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.tasks li:last-child { border-bottom: 0; }
.tasks label { flex: 1; display: flex; gap: 12px; align-items: center; cursor: pointer; }
.tasks input[type=checkbox] { width: 24px; height: 24px; flex: none; accent-color: var(--ok); }
.tasks li.done .t { color: var(--muted); text-decoration: line-through; }
.tasks .k { font-size: 1.1rem; flex: none; }

/* Foto-Import */
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.thumbs figure { margin: 0; width: 84px; text-align: center; font-size: .75rem; color: var(--muted); }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
table.import { width: 100%; border-collapse: collapse; }
table.import td { padding: 4px 3px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.import input[type=text] { padding: 6px 8px; font-size: .95rem; }
table.import td.hz input { font-family: var(--hanzi); font-size: 1.15rem; min-width: 80px; }
table.import tr.dup { opacity: .55; }
@media (max-width: 620px) {
  table.import tr { display: grid; grid-template-columns: 32px 1fr 1fr; padding: 6px 0; border-bottom: 1px solid var(--line); }
  table.import td { border: 0; }
  table.import td.cb { grid-row: span 3; }
  table.import td.ge, table.import td.no { grid-column: 2 / 4; }
}

/* Dialog & Hinweise */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(520px, 94vw); background: var(--card);
  color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form, dialog .body { padding: 18px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 50; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } }
.celebrate { text-align: center; padding: 30px 16px; }
.celebrate .big { font-size: 3.5rem; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Anmeldung */
.login { max-width: 380px; margin: 12vh auto 0; padding: 16px; }
.login .logo { font-family: var(--hanzi); font-size: 3rem; color: var(--accent); text-align: center; margin-bottom: 4px; }
.error { color: var(--accent); min-height: 1.4em; font-size: .9rem; }

/* Startseite: das Wichtigste ohne Scrollen */
.hero .small-ring { width: 104px; height: 104px; }
.hero .small-ring > div { width: 84px; height: 84px; }
.hero .small-ring b { font-size: 1.4rem; }
.hero h2 { margin-bottom: 2px; }
.hero .stat { margin: 0 0 6px; }
.small-streak { font-size: 1.25rem; }
.start-btns { gap: 10px; margin-top: 14px; }
.start-btns .btn { padding: 18px 10px; font-size: 1.15rem; }
.start-btns { grid-template-columns: 1fr 1fr !important; }
a.btn { color: inherit; }
a.btn.primary { color: #fff; }
