:root {
  --paper: #f5efe4;
  --card: #fffaf2;
  --ink: #1d2726;
  --muted: #66706d;
  --line: #e4dccd;
  --teal: #14524f;
  --teal-2: #1f6f6a;
  --teal-soft: #d8e8e4;
  --amber: #e07a2f;
  --amber-soft: #fbe3cf;
  --red: #b3412e;
  --red-soft: #f8dcd5;
  --green: #2f7a4b;
  --green-soft: #dcefe1;
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-size: 17px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1 { font-family: Georgia, "Noto Serif", "Times New Roman", serif; font-weight: 600; font-size: 1.85rem; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; }

.screen { display: none; min-height: 100%; padding: 20px 18px calc(28px + var(--safe-b)); max-width: 560px; margin: 0 auto; }
.screen.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; color: var(--teal-2); font-weight: 700; margin-bottom: 4px; }
.label { font-weight: 700; font-size: .9rem; margin: 22px 0 10px; color: var(--ink); }
.error { color: var(--red); margin-top: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); color: var(--teal); }

.btn { border-radius: 14px; padding: 13px 18px; font-weight: 650; text-align: center; }
.btn.primary { background: var(--teal); color: #fff; }
.btn.secondary { background: var(--teal-soft); color: var(--teal); }
.btn.ghost { background: transparent; color: var(--teal); border: 1px solid var(--line); }
.btn.big { padding: 17px 20px; font-size: 1.05rem; }
.btn.small { padding: 9px 14px; font-size: .9rem; }
.btn:disabled { opacity: .5; }

.banner { background: var(--amber-soft); color: #7a3c10; padding: 12px 14px; border-radius: 14px; margin-bottom: 14px; font-weight: 600; }
.banner.warn { background: var(--red-soft); color: var(--red); }

/* Code */
.center-wrap { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; align-items: stretch; text-align: center; gap: 8px; }
.logo { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto 10px; }
#code-input { padding: 15px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); text-align: center; font-size: 1.1rem; }

/* Home */
.streak-card { display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.streak-num { font-family: Georgia, serif; font-size: 2.2rem; font-weight: 700; line-height: 1; color: var(--teal); }
.week { display: flex; gap: 7px; }
.week .d { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .7rem; color: var(--muted); }
.week .d i { width: 22px; height: 22px; border-radius: 50%; background: var(--line); display: block; }
.week .d.on i { background: var(--amber); }
.week .d.today span { color: var(--ink); font-weight: 700; }

.start-btn {
  margin: 22px 0 4px; width: 100%; border-radius: 28px; padding: 26px 20px;
  background: linear-gradient(145deg, var(--teal) 0%, var(--teal-2) 100%); color: #fff;
  display: flex; align-items: center; gap: 18px; box-shadow: 0 14px 30px -14px rgba(20,82,79,.7);
  transition: transform .15s ease;
}
.start-btn:active { transform: scale(.98); }
.start-btn.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(224,122,47,.55); } 50% { box-shadow: 0 0 0 14px rgba(224,122,47,0); } }
.start-mic { width: 64px; height: 64px; border-radius: 50%; background: var(--amber); display: grid; place-items: center; flex: none; }
.start-mic svg { width: 34px; height: 34px; }
.start-text { font-family: Georgia, serif; font-size: 1.45rem; font-weight: 600; text-align: left; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 15px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: .92rem; }
.chip.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.chips.days .chip { padding: 8px 0; width: 42px; }

.history-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.history-list li button { width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.history-list .h-main { font-weight: 650; }
.history-list .h-sub { color: var(--muted); font-size: .85rem; }
.history-list .h-count { background: var(--amber-soft); color: #7a3c10; border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 700; white-space: nowrap; }

/* Session */
.session { display: none; flex-direction: column; height: 100dvh; padding-bottom: calc(12px + var(--safe-b)); }
.session.active { display: flex; }
.session-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pill { background: var(--teal-soft); color: var(--teal); padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: .85rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); }
#timeup-banner { margin: 12px 0 0; }

.stage { display: flex; flex-direction: column; align-items: center; padding: 18px 0 6px; flex: none; }
.orb { position: relative; width: 150px; height: 150px; display: grid; place-items: center; }
.orb-core { width: 104px; height: 104px; border-radius: 50%; background: var(--teal); display: grid; place-items: center; z-index: 2; transition: background .3s ease, transform .3s ease; box-shadow: 0 10px 30px -10px rgba(20,82,79,.6); }
.ring { position: absolute; inset: 23px; border-radius: 50%; border: 2px solid var(--teal); opacity: 0; }
.bars { display: flex; gap: 5px; align-items: center; height: 36px; }
.bars i { width: 6px; height: 8px; border-radius: 3px; background: #fff; opacity: .9; transition: height .2s; }

.orb[data-state="speaking"] .bars i { animation: bar .9s ease-in-out infinite; }
.orb[data-state="speaking"] .bars i:nth-child(2) { animation-delay: .15s; }
.orb[data-state="speaking"] .bars i:nth-child(3) { animation-delay: .3s; }
.orb[data-state="speaking"] .bars i:nth-child(4) { animation-delay: .45s; }
.orb[data-state="speaking"] .bars i:nth-child(5) { animation-delay: .6s; }
@keyframes bar { 0%,100% { height: 8px; } 50% { height: 34px; } }

.orb[data-state="listening"] .orb-core { background: var(--amber); }
.orb[data-state="listening"] .ring { border-color: var(--amber); animation: ripple 2.1s ease-out infinite; }
.orb[data-state="listening"] .r2 { animation-delay: .7s; }
.orb[data-state="listening"] .r3 { animation-delay: 1.4s; }
@keyframes ripple { from { transform: scale(1); opacity: .7; } to { transform: scale(1.7); opacity: 0; } }

.orb[data-state="thinking"] .orb-core { animation: breathe 1.4s ease-in-out infinite; }
.orb[data-state="thinking"] .bars i { height: 6px; width: 6px; animation: dot 1.2s ease-in-out infinite; }
.orb[data-state="thinking"] .bars i:nth-child(2) { animation-delay: .2s; }
.orb[data-state="thinking"] .bars i:nth-child(3) { animation-delay: .4s; }
.orb[data-state="thinking"] .bars i:nth-child(4), .orb[data-state="thinking"] .bars i:nth-child(5) { display: none; }
@keyframes dot { 0%,100% { opacity: .3; } 50% { opacity: 1; } }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(.94); } }
.orb[data-state="idle"] .orb-core, .orb[data-state="paused"] .orb-core { background: #8a9592; }

.state-label { margin-top: 10px; font-weight: 700; color: var(--teal); }
.live-text { min-height: 1.5em; margin-top: 6px; color: var(--muted); text-align: center; font-style: italic; padding: 0 10px; }

.log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px 2px 12px; scroll-behavior: smooth; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: 18px; font-size: .97rem; }
.msg.teacher { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.student { align-self: flex-end; background: var(--teal); color: #fff; border-bottom-right-radius: 6px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: .85rem; padding: 2px; }
.msg.hidden-text { cursor: pointer; }
.msg.hidden-text .txt { filter: blur(6px); user-select: none; }
.msg.hidden-text::after { content: "Antippen zum Mitlesen"; display: block; font-size: .78rem; color: var(--teal-2); font-weight: 700; margin-top: 6px; }
.hoertext { display: block; margin: 8px 0; padding: 10px 12px; border-radius: 12px; background: var(--teal-soft); }
.hoertext.covered { cursor: pointer; }
.hoertext.covered .ht { filter: blur(7px); user-select: none; }
.hoertext .ht-label { display: block; font-size: .78rem; font-weight: 700; color: var(--teal); margin-bottom: 4px; }

.controls { display: flex; justify-content: space-around; align-items: center; padding-top: 6px; flex: none; }
.round-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--teal); font-size: .78rem; font-weight: 650; width: 70px; }
.round-btn svg { width: 46px; height: 46px; padding: 11px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); }
.round-btn.on svg { background: var(--amber); color: #fff; border-color: var(--amber); }
.mic-btn { width: 84px; height: 84px; border-radius: 50%; background: var(--teal); color: #fff; display: grid; place-items: center; box-shadow: 0 10px 24px -10px rgba(20,82,79,.8); transition: transform .15s, background .2s; }
.mic-btn svg { width: 38px; height: 38px; }
.mic-btn:active { transform: scale(.95); }
.mic-btn .ic-send { display: none; }
.mic-btn.listening { background: var(--amber); }
.mic-btn.listening .ic-mic { display: none; }
.mic-btn.listening .ic-send { display: block; }
.mic-btn:disabled { opacity: .45; }
.mic-hint { text-align: center; color: var(--muted); font-size: .82rem; margin-top: 8px; min-height: 1.2em; flex: none; }

/* Feedback */
.loading { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 60px 0; color: var(--muted); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--teal-soft); border-top-color: var(--teal); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card-title { font-weight: 750; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--teal-2); margin-bottom: 8px; }
.card.praise { background: var(--green-soft); border-color: #c4e2cd; }
.card.praise .card-title { color: var(--green); }
.card.tip { background: var(--amber-soft); border-color: #f2cfae; }
.card.tip .card-title { color: #9a4b12; }
.err-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.err-topic { display: inline-block; font-size: .72rem; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; color: var(--teal-2); background: var(--teal-soft); border-radius: 999px; padding: 2px 9px; margin-bottom: 8px; }
.err-said { color: var(--red); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.err-said::before { content: "Du: "; text-decoration: none; display: inline-block; font-weight: 700; margin-right: 2px; }
.err-right { color: var(--green); font-weight: 650; margin-top: 4px; }
.err-right::before { content: "Besser: "; font-weight: 750; }
.err-why { color: var(--muted); font-size: .9rem; margin-top: 6px; }
#fb-einschaetzung { margin: 8px 0 4px; }

/* Settings */
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; margin: 10px 0; }
.field input[type="text"], .field input[type="time"], .field select { padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-weight: 500; }
.field input[type="range"] { accent-color: var(--teal); }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; font-weight: 600; margin: 6px 0; }
.switch-row input { width: 24px; height: 24px; accent-color: var(--teal); flex: none; }
#reminder-details { margin-top: 6px; }
#reminder-details .btn { margin-top: 12px; }
.card .btn.ghost.small { margin: 4px 6px 4px 0; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: .92rem; max-width: 90vw; z-index: 50; box-shadow: 0 8px 24px -8px rgba(0,0,0,.4); }

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