/* ==========================================================
   Bausteine: Karten, Buttons, Formulare, Chips, Dialoge …
   Alle Bedienelemente sind mind. ~44 px groß (iPad + Apple Pencil).
   ========================================================== */

/* ---------- Karten ---------- */
.card {
  position: relative; min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card.pad-lg { padding: 30px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.card-label { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--text-3); }
.card-label .i { width: 15px; height: 15px; }
.card-head .link { margin-left: auto; min-height: 36px; font-size: 13.5px; color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 0 2px; text-decoration: none; }
.card.glow { border-color: var(--border-strong); }
.title-xl { font: 600 clamp(24px, 2.6vw, 30px)/1.15 var(--font-display); letter-spacing: -.01em; }
.title-lg { font: 600 21px/1.2 var(--font-display); }
.meta { color: var(--text-2); font-size: 14px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-2); font-size: 14px; }
.meta-row span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--card); color: var(--text);
  font-weight: 600; font-size: 14.5px; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.danger { color: var(--red); }
.btn.sm { height: 38px; padding: 0 14px; font-size: 13.5px; border-radius: 11px; }
.btn.lg { height: 52px; padding: 0 24px; font-size: 16px; border-radius: 14px; }
.btn.icon { width: 44px; padding: 0; }
.btn.icon.sm { width: 38px; }

/* ---------- Formulare ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); font-weight: 400; }
.input, .select, .textarea {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 12px;
  font-size: 16px; /* verhindert das automatische Zoomen auf dem iPad */
  border: 1px solid var(--border-strong); background: var(--inset); color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.textarea { height: auto; min-height: 96px; padding: 11px 14px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--text-2); box-shadow: var(--focus); background: var(--card); }
.input::placeholder { color: var(--text-3); }
.select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%236b655c' stroke-width='2'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .form-grid.cols-2 { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; font-size: 14.5px; color: var(--text-2); cursor: pointer; }
.check input { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; margin: 0; border-radius: 7px; border: 1.5px solid var(--border-strong); background: var(--inset); display: grid; place-items: center; cursor: pointer; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; width: 10px; height: 5px; border: 2px solid var(--on-accent); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.check input[type="radio"] { border-radius: 50%; }
.check input[type="radio"]:checked::after { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--on-accent); transform: none; }

/* ---------- Chips & Badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border-radius: 99px;
  font-size: 12.5px; font-weight: 600; background: var(--inset); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.violet, .chip.cyan, .chip.pink { color: var(--text-2); }
.chip.green { color: var(--green); background: color-mix(in srgb, var(--green) 10%, var(--card)); border-color: color-mix(in srgb, var(--green) 28%, var(--card)); }
.chip.amber { color: var(--amber-text); background: color-mix(in srgb, var(--amber) 11%, var(--card)); border-color: color-mix(in srgb, var(--amber) 30%, var(--card)); }
.chip.red { color: var(--red); background: color-mix(in srgb, var(--red) 9%, var(--card)); border-color: color-mix(in srgb, var(--red) 26%, var(--card)); }
.chip.live .dot { animation: pulse 1.6s infinite; }
.chip-btn { cursor: pointer; height: 38px; padding: 0 16px; font-size: 13.5px; transition: background .15s, color .15s, border-color .15s; }
.chip-btn.active { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; }

.type-hw { --tc: var(--t-hw); } .type-test { --tc: var(--t-test); } .type-exam { --tc: var(--t-exam); } .type-other { --tc: var(--t-other); }
.type-chip { color: var(--tc); background: color-mix(in srgb, var(--tc) 10%, var(--card)); border-color: color-mix(in srgb, var(--tc) 28%, var(--card)); }

/* ---------- Segment-Schalter ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 13px; background: var(--inset); border: 1px solid var(--border); }
.seg button { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 16px; border: 0; border-radius: 10px; background: none; color: var(--text-2); font-weight: 600; font-size: 13.5px; }
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Countdown ---------- */
.countdown { display: flex; gap: 8px; }
.countdown .unit { flex: 1; min-width: 0; padding: 14px 6px 10px; border-radius: 14px; background: var(--inset); border: 1px solid var(--border); text-align: center; }
.countdown b { display: block; font: 600 clamp(24px, 2.6vw, 32px)/1 var(--font-display); font-variant-numeric: tabular-nums lining-nums; }
.countdown small { display: block; margin-top: 7px; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); font-weight: 600; }
.countdown.big b { font-size: clamp(32px, 4vw, 46px); }

/* ---------- Fortschritt ---------- */
.bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > div { height: 100%; border-radius: inherit; background: var(--accent); transition: width .6s var(--ease); }
.ring { position: relative; width: var(--size, 120px); height: var(--size, 120px); flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--surface-3); }
.ring .val { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .8s var(--ease); }
.ring .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .center b { font: 600 26px/1 var(--font-display); font-variant-numeric: lining-nums; }
.ring .center small { font-size: 11px; color: var(--text-3); margin-top: 3px; }

/* ---------- Listen ---------- */
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.item {
  display: flex; align-items: center; gap: 14px; padding: 13px 15px; min-height: 60px; border-radius: var(--r-md);
  background: var(--inset); border: 1px solid var(--border);
  transition: background .15s, border-color .15s;
}
.item.clickable { cursor: pointer; }
.item .accent { width: 4px; align-self: stretch; border-radius: 4px; background: var(--tc, var(--text-3)); flex: none; }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.item .side { text-align: right; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.item .side b { display: block; color: var(--text); font-weight: 600; font-size: 13.5px; }
.item.done .title { text-decoration: line-through; color: var(--text-3); }
.item.past { opacity: .5; }
.date-tile { width: 48px; flex: none; text-align: center; padding: 6px 0; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.date-tile small { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 600; }
.date-tile b { display: block; font: 600 19px/1.1 var(--font-display); font-variant-numeric: lining-nums; }

.empty { display: grid; justify-items: center; gap: 10px; padding: 36px 16px; text-align: center; color: var(--text-2); }
.empty .icon-wrap { width: 54px; height: 54px; border-radius: 17px; display: grid; place-items: center; background: var(--inset); border: 1px solid var(--border); color: var(--text-2); }
.empty b { color: var(--text); font-size: 15.5px; }

/* ---------- Avatar ---------- */
.avatar { width: 36px; height: 36px; border-radius: 12px; flex: none; display: grid; place-items: center; font-weight: 600; font-size: 13.5px; color: #fbf9f4; background: hsl(var(--h, 30) 14% 52%); }
.avatar.sm { width: 30px; height: 30px; border-radius: 10px; font-size: 12px; }
.avatar-wrap { position: relative; }
.avatar-wrap .presence { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-3); border: 2px solid var(--card); }
.avatar-wrap .presence.on { background: var(--green); }

/* ---------- Dialog ---------- */
dialog.modal {
  width: min(540px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--border);
  border-radius: var(--r-xl); background: var(--card); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.modal[open] { animation: fade-up .25s var(--ease); }
dialog.modal::backdrop { background: rgba(45, 40, 34, .35); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
dialog.modal.image { width: auto; max-width: 94vw; background: none; border: 0; box-shadow: none; }
dialog.modal.image img { max-width: 94vw; max-height: 88vh; border-radius: 14px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 22px 24px 0; }
.modal-head h3 { font-size: 21px; }
.modal-head .btn { margin-left: auto; }
.modal-body { padding: 18px 24px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 0 24px 22px; }
.modal-foot .left { margin-right: auto; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 9500; left: 50%; bottom: 28px; transform: translateX(-50%); display: grid; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 14px;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-lg);
  font-size: 14.5px; font-weight: 500; animation: fade-up .25s var(--ease);
}
.toast.ok .i { color: var(--green); } .toast.err .i { color: var(--red); }
.toast.out { opacity: 0; transform: translateY(6px); transition: .25s; }
@media (max-width: 900px) { .toasts { bottom: calc(110px + env(safe-area-inset-bottom)); } }

/* ---------- Tabellen ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
.table th { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); font-weight: 600; text-align: left; padding: 0 6px; }
.table td { padding: 0 4px; }
.table .input { height: 44px; }
.scroll-x { overflow-x: auto; }

/* ---------- Hinweis ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid color-mix(in srgb, var(--amber) 30%, var(--card)); background: color-mix(in srgb, var(--amber) 8%, var(--card)); color: var(--amber-text); font-size: 14px; }
.notice .i { color: var(--amber); margin-top: 1px; }
.notice a { color: inherit; font-weight: 600; }
.notice.info { border-color: var(--border-strong); background: var(--inset); color: var(--text-2); }
.notice.info .i { color: var(--text-2); }
.notice code { font-family: var(--font-mono); background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }

/* ---------- Hover nur mit Maus (auf dem iPad bleiben sonst Zustände „hängen“) ---------- */
@media (hover: hover) {
  .nav-item:hover:not(.active) { background: var(--surface-2); color: var(--text); }
  .btn:hover { background: var(--inset); }
  .btn.primary:hover { opacity: .9; }
  .btn.ghost:hover { background: var(--surface-2); color: var(--text); }
  .btn.danger:hover { background: color-mix(in srgb, var(--red) 8%, var(--card)); }
  .card-head .link:hover { color: var(--text); }
  .chip-btn:hover:not(.active) { color: var(--text); border-color: var(--border-strong); }
  .seg button:hover:not(.active) { color: var(--text); }
  .item.clickable:hover { background: var(--card); border-color: var(--border-strong); }
  .input:hover, .select:hover { border-color: var(--text-3); }
  .who button:hover:not(.sel) { background: var(--card); }
}

/* ---------- Bausteine der neuen Version ---------- */
/* Segmentierte Auswahl */
.seg { max-width: 100%; flex-wrap: wrap; }
.seg button {
  min-height: 40px; min-width: 44px; padding: 0 14px; border: 0; border-radius: 10px; background: none;
  color: var(--text-2); font-weight: 600; cursor: pointer; font-size: 15px;
}
.seg button.on, .seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg.full { display: flex; } .seg.full button { flex: 1; }

/* Schalter */
.switch { position: relative; display: inline-flex; flex: none; width: 56px; height: 44px; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch .track { width: 52px; height: 32px; border-radius: 99px; background: var(--surface-3); transition: background .2s; position: relative; }
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }
[data-theme="dark"] .switch input:checked + .track::after { background: var(--on-accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--text-2); outline-offset: 2px; }

/* Einstellungs-Zeilen */
.set-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-top: 1px solid var(--border); min-height: 64px; }
.set-row:first-child { border-top: 0; }
.set-row .txt { flex: 1; min-width: 0; }
.set-row .txt > b { display: block; font-weight: 600; }
.set-row .txt > span { display: block; color: var(--text-2); font-size: 14px; }

.notice.warn { border-color: color-mix(in srgb, var(--amber) 30%, var(--card)); }
.notice.ok { border-color: color-mix(in srgb, var(--green) 30%, var(--card)); background: color-mix(in srgb, var(--green) 8%, var(--card)); color: var(--text); }
.notice.ok .i { color: var(--green); }
.empty.small { padding: 18px 10px; font-size: 14px; }
/* ---------- Dialoge ---------- */
.modal-layer { position: relative; z-index: 1000; }
.modal-back {
  position: fixed; inset: 0; background: rgba(25, 20, 14, .42); display: grid; place-items: center;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  animation: fadeIn .16s ease both; overscroll-behavior: contain;
}
.modal {
  width: min(560px, 100%); max-height: calc(100dvh - 32px - var(--sat) - var(--sab)); overflow-y: auto;
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 22px;
  animation: popIn .2s cubic-bezier(.2, .9, .3, 1.1) both; overscroll-behavior: contain;
}
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { flex: 1; font-size: 22px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal-actions .left { margin-right: auto; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.image-view { position: fixed; inset: 0; background: rgba(0, 0, 0, .9); display: grid; place-items: center; z-index: 1100; padding: calc(20px + var(--sat)) 20px calc(20px + var(--sab)); }
.image-view img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.image-view .btn { position: absolute; top: calc(14px + var(--sat)); left: calc(14px + var(--sal)); }

.toast.err { background: var(--red); color: #fff; }
.btn.subtle { background: var(--inset); border-color: var(--border); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.form-err { color: var(--red); }
.avatar.lg { width: 56px; height: 56px; border-radius: 18px; font-size: 20px; }

/* ---------- Konto: Passwort ändern ---------- */
.set-block { display: grid; gap: 12px; padding: 14px 0; border-top: 1px solid var(--border); }
.set-block .txt > b { display: block; font-weight: 600; }
.set-block .txt > span { display: block; color: var(--text-2); font-size: 14px; }
.pw-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
fieldset.readonly { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.readonly :is(input, select, textarea, button) { opacity: .75; }
.who-admin { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); grid-template-columns: repeat(4, 1fr); }

/* ---------- Admin-Bereich ---------- */
.adm-list { display: grid; gap: 8px; margin-top: 4px; }
.adm-acc { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--inset); }
.adm-acc.off { opacity: .6; }
.adm-acc .txt { flex: 1; min-width: 0; display: grid; gap: 2px; }
.adm-acc .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.adm-acc .tags:empty { display: none; }
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 99px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--text-2); }
.tag.red { background: color-mix(in srgb, var(--red) 18%, var(--card)); color: var(--red); }
.tag.amber { background: color-mix(in srgb, var(--amber) 18%, var(--card)); color: var(--amber-text); }
.tag.green { background: color-mix(in srgb, var(--green) 20%, var(--card)); color: var(--green); }
.adm-form { display: grid; gap: 12px; }
.adm-games { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); margin-top: 6px; }
.adm-game { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r-md); cursor: pointer; }
.adm-game.off { opacity: .55; }
.adm-game .emoji { font-size: 22px; width: 28px; text-align: center; }
.adm-game .grow { display: grid; min-width: 0; }
.num-in { width: 90px; text-align: right; }
@media (max-width: 600px) {
  .adm-acc { flex-wrap: wrap; }
  .adm-acc .btn { width: 100%; justify-content: center; }
}

/* Mitteilungen (Banner oben, auch über Spielen; unter dem Notfall-Bildschirm) */
.notes { position: fixed; z-index: 9600; top: calc(12px + var(--sat, 0px)); left: 50%; transform: translateX(-50%); width: min(440px, calc(100% - 32px)); display: grid; gap: 8px; pointer-events: none; }
.note-banner { pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 12px 10px 12px 14px; border-radius: 18px;
  background: color-mix(in srgb, var(--card) 94%, transparent); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); animation: note-in .28s var(--ease); }
.note-banner.out { opacity: 0; transform: translateY(-12px); transition: .25s var(--ease); }
.nb-ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--accent); color: var(--on-accent); }
.kind-ann .nb-ico { background: var(--amber); color: #fff; }
.kind-warn .nb-ico, .kind-lesson .nb-ico { background: var(--green); color: #fff; }
.nb-txt { flex: 1; min-width: 0; display: grid; gap: 2px; }
.nb-txt b { font-weight: 650; }
.nb-txt span { color: var(--text-2); font-size: .92rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.nb-x { width: 32px; height: 32px; border-radius: 10px; border: 0; background: none; color: var(--text-2); display: grid; place-items: center; flex: none; cursor: pointer; }
.composer[hidden] { display: none; }
@keyframes note-in { from { opacity: 0; transform: translateY(-16px); } }
.adm-pprev { width: 100%; max-height: 240px; object-fit: contain; border-radius: 12px; background: #000; }
