/* ============================================================
   Karteikasten – Bildschirm-Stylesheet
   Papier, Kugelschreiberblau, Registerreiter
   ============================================================ */

:root {
  --paper:      #e7e8e1;
  --paper-deep: #dcded5;
  --card:       #fcfbf7;
  --ink:        #15181a;
  --ink-soft:   #5b615f;
  --rule:       #cfd0c6;
  --blue:       #2b3aa0;
  --blue-deep:  #1e2a78;
  --red:        #bf4034;
  --green:      #2c7a4b;
  --amber:      #a8650d;

  --r-sm: 3px;
  --r-md: 6px;
  --r-lg: 10px;

  --shadow-1: 0 1px 0 rgba(21,24,26,.06), 0 1px 3px rgba(21,24,26,.07);
  --shadow-2: 0 2px 4px rgba(21,24,26,.06), 0 12px 28px rgba(21,24,26,.10);

  --display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --body:    "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,.55), transparent 42%),
    radial-gradient(circle at 92% 0%, rgba(255,255,255,.35), transparent 38%);
  color: var(--ink);
  font: 400 16px/1.55 var(--body);
}

a { color: var(--blue-deep); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--blue); }

h1, h2, h3 { font-family: var(--display); font-weight: 400; letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(2rem, 1.4rem + 2.2vw, 3rem); line-height: 1.06; }
h2 { font-size: 1.4rem; line-height: 1.2; }
h3 { font-size: 1.1rem; }

p { margin: 0; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--ink); color: var(--card); padding: .6rem 1rem;
}
.skip:focus { left: 0; }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.muted  { color: var(--ink-soft); }
.is-hidden { display: none !important; }
.narrow { max-width: 30rem; margin-inline: auto; }
.stack    > * + * { margin-top: .85rem; }
.stack-lg > * + * { margin-top: 1.6rem; }

/* ------------------------------ Kopfleiste ---------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--rule);
  background: rgba(252,251,247,.82);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; align-items: center; gap: .55rem; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 22px; height: 28px; border-radius: 2px 2px var(--r-sm) var(--r-sm);
  background: var(--card); border: 1px solid var(--ink);
  box-shadow: 3px 3px 0 var(--blue);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 5px 4px auto 4px; height: 1px;
  background: var(--rule); box-shadow: 0 5px 0 var(--rule), 0 10px 0 var(--rule);
}
.brand-name { font-family: var(--display); font-size: 1.3rem; }
.topnav { display: flex; align-items: center; gap: 1rem; font-size: .93rem; }
.topnav a { text-decoration: none; }
.topnav a.is-current { text-decoration: underline; }
.topnav-user { font-family: var(--mono); font-size: .8rem; color: var(--ink-soft); }

.wrap { max-width: 72rem; margin: 0 auto; padding: clamp(1.2rem, 3vw, 2.4rem) clamp(1rem, 4vw, 2.5rem) 4rem; }

.footer {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  max-width: 72rem; margin: 0 auto; padding: 1.2rem clamp(1rem, 4vw, 2.5rem) 2.5rem;
  border-top: 1px solid var(--rule); font-size: .8rem; color: var(--ink-soft);
  font-family: var(--mono);
}

/* -------------------------------- Kopf -------------------------------- */
.page-head { margin-bottom: 1.8rem; }
.eyebrow {
  font-family: var(--mono); font-size: .74rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: .5rem;
}
.eyebrow a { color: inherit; }
.lede { margin-top: .6rem; color: var(--ink-soft); }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

/* ------------------------------- Flächen ------------------------------ */
.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 1.2rem;
  box-shadow: var(--shadow-1);
}
.panel + .panel, section + section, .panel + section, section + .panel { margin-top: 1.4rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .9rem; }
.panel-head p { font-size: .84rem; }
.count { font-family: var(--mono); font-size: .9rem; color: var(--ink-soft); }

.notice { padding: .7rem .9rem; border-radius: var(--r-md); font-size: .93rem; }
.notice-bad { background: #f7e4e1; border: 1px solid #e3b6af; color: #7d2a20; }

.empty { color: var(--ink-soft); padding: 1.4rem; text-align: center; border: 1px dashed var(--rule); border-radius: var(--r-md); }

.checklist { margin: 0; padding-left: 1.1rem; font-family: var(--mono); font-size: .84rem; color: var(--ink-soft); }

/* ------------------------------ Formulare ----------------------------- */
label { display: block; font-size: .87rem; color: var(--ink-soft); }
input[type=text], input[type=email], input[type=password], input[type=search], textarea, select {
  width: 100%; margin-top: .3rem;
  font: inherit; color: var(--ink);
  background: #fff;
  border: 1px solid var(--rule); border-radius: var(--r-md);
  padding: .55rem .7rem;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(43,58,160,.15); }
label.check { display: inline-flex; align-items: center; gap: .4rem; }
label.check input { width: auto; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: 500 .92rem/1 var(--body);
  padding: .6rem .9rem; border-radius: var(--r-md);
  border: 1px solid var(--rule); background: #fff; color: var(--ink);
  text-decoration: none; cursor: pointer;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { box-shadow: var(--shadow-1); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-deep); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-danger { color: var(--red); border-color: #e0bab4; background: #fff; }
.btn-danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.btn-sm { padding: .38rem .6rem; font-size: .82rem; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1rem; }
.btn-good { background: var(--green); border-color: var(--green); color: #fff; }
.btn-bad  { background: var(--red);   border-color: var(--red);   color: #fff; }
.btn kbd {
  font: 400 .7rem/1 var(--mono); padding: .18rem .32rem; border-radius: 3px;
  background: rgba(255,255,255,.22); border: 1px solid rgba(255,255,255,.35);
}
.btn:not(.btn-primary):not(.btn-good):not(.btn-bad) kbd { background: var(--paper-deep); border-color: var(--rule); color: var(--ink-soft); }

.status { font-family: var(--mono); font-size: .78rem; color: var(--ink-soft); }
.status.is-ok  { color: var(--green); }
.status.is-bad { color: var(--red); }

/* -------------------------------- Decks ------------------------------- */
.deck-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
.deck {
  position: relative; background: var(--card);
  border: 1px solid var(--rule); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); display: flex; flex-direction: column;
}
.deck-body { display: block; padding: 1.5rem 1.1rem 1rem; text-decoration: none; color: inherit; }
.deck-tab {
  position: absolute; top: -9px; left: 1.1rem; width: 4.2rem; height: 10px;
  background: var(--blue); border-radius: 3px 3px 0 0;
}
.deck:nth-child(3n+2) .deck-tab { background: var(--amber); }
.deck:nth-child(3n+3) .deck-tab { background: var(--green); }
.deck-desc { margin-top: .35rem; font-size: .87rem; color: var(--ink-soft); }
.deck-figures, .figures { display: flex; flex-wrap: wrap; gap: 1.2rem; margin: 1rem 0 0; }
.deck-figures div, .figures div { margin: 0; }
.deck-figures dt, .figures dt {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft);
}
.deck-figures dd, .figures dd { margin: .1rem 0 0; font-family: var(--mono); font-size: 1.25rem; }
.figures.panel { padding: 1.2rem; gap: 1.8rem; }
.figures .unit { font-size: .8rem; color: var(--ink-soft); }
.is-due { color: var(--red); }
.deck-actions {
  display: flex; flex-wrap: wrap; gap: .35rem; align-items: center;
  padding: .8rem 1.1rem 1rem; border-top: 1px dashed var(--rule);
}
.deck-new { padding: 1.5rem 1.1rem; border-style: dashed; box-shadow: none; background: transparent; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 5; width: 17rem;
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-md);
  padding: .9rem; box-shadow: var(--shadow-2);
}

/* --------------------------- Schnellerfassung ------------------------- */
.quickadd { border-left: 3px solid var(--blue); }
.quickadd-fields { display: grid; gap: .9rem; grid-template-columns: 1fr 1fr; }
.field-label {
  display: block; font-family: var(--mono); font-size: .68rem;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft);
}
.quickadd textarea { font-size: 1.05rem; }
.quickadd-foot { display: flex; align-items: center; gap: .8rem; margin-top: .9rem; }

.import summary { cursor: pointer; }
.import summary h2 { display: inline; }

/* ------------------------------ Kartenliste --------------------------- */
.sticky-head { position: sticky; top: 3.4rem; background: var(--paper); padding: .6rem 0; z-index: 4; }
.sticky-head input { max-width: 16rem; }
.cardlist { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.card-row {
  display: grid; gap: .7rem; align-items: start;
  grid-template-columns: 3.2rem 1fr 1fr 9.5rem;
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-md);
  padding: .7rem;
}
.card-row.is-dirty { border-color: var(--amber); }
.card-index { display: flex; flex-direction: column; gap: .2rem; font-family: var(--mono); font-size: .78rem; color: var(--ink-soft); }
.card-index .box { color: var(--blue); }
.card-index .uid { font-size: .68rem; letter-spacing: .04em; color: var(--ink-soft); }
.card-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; font-family: var(--mono); font-size: .78rem; }
.tally b { color: var(--green); }
.card-row.is-removing { opacity: .35; }

/* ------------------------------- Abfrage ------------------------------ */
.learn { max-width: 46rem; margin-inline: auto; }
.learn-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; align-items: flex-end; }
.learn-title { font-size: 2rem; }
.learn-modes { display: flex; align-items: flex-end; gap: .8rem; flex-wrap: wrap; }
.learn-modes select { min-width: 12rem; }

.progress { height: 4px; background: var(--paper-deep); border-radius: 2px; margin: 1.4rem 0 .5rem; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--blue); transition: width .25s ease; }
.learn-counters { display: flex; gap: 1.2rem; font-family: var(--mono); font-size: .8rem; color: var(--ink-soft); }
.tally-good b { color: var(--green); }
.tally-bad b { color: var(--red); }

.flashcard {
  margin-top: 1.2rem; min-height: 20rem;
  background: var(--card);
  background-image:
    linear-gradient(to bottom, transparent 27px, var(--rule) 27px, var(--rule) 28px, transparent 28px);
  background-size: 100% 28px;
  background-position: 0 2.6rem;
  border: 1px solid var(--rule); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  padding: 1.6rem 1.8rem 2rem 3.4rem;
  position: relative; overflow: hidden;
}
.flashcard::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 2.6rem; width: 1px; background: var(--red); opacity: .5;
}
.flashcard-side {
  font-family: var(--mono); font-size: .7rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: .8rem;
}
.flashcard-text { font-size: clamp(1.25rem, 1rem + 1.4vw, 1.9rem); line-height: 28px; white-space: pre-wrap; word-break: break-word; }
.flashcard-answer { margin-top: 1.4rem; animation: reveal .18s ease-out; }
.flashcard-answer .flashcard-text { font-size: clamp(1.1rem, .95rem + .9vw, 1.5rem); color: var(--blue-deep); }
.flashcard-rule { border: 0; border-top: 1px dashed var(--rule); margin: 0 0 1.2rem; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.stage-actions { margin-top: 1.4rem; display: flex; justify-content: center; }
.verdicts { display: flex; gap: .8rem; flex-wrap: wrap; justify-content: center; }

.summary { margin-top: 2rem; background: var(--card); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 1.6rem; box-shadow: var(--shadow-1); }
.summary h2 { margin-top: .3rem; }
.summary .figures { margin-top: 1.2rem; }

/* ------------------------------ Statistik ----------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--rule); }
.table th { font-family: var(--mono); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); font-weight: 500; }
.table td.num, .table th.num { text-align: right; font-family: var(--mono); }
.table tr:last-child td { border-bottom: 0; }

.boxbars { display: grid; grid-template-columns: repeat(5, 1fr); gap: .8rem; align-items: end; }
.boxbar { display: grid; justify-items: center; gap: .35rem; }
.boxbar-track { width: 100%; height: 8rem; background: var(--paper-deep); border-radius: var(--r-sm); display: flex; align-items: flex-end; }
.boxbar-fill { width: 100%; background: var(--blue); border-radius: var(--r-sm); min-height: 2px; }
.boxbar-n { font-family: var(--mono); font-size: .95rem; }
.boxbar-label { font-size: .72rem; text-align: center; color: var(--ink-soft); }

.histogram { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .4rem; align-items: end; height: 10rem; }
.hbar { display: grid; align-content: end; justify-items: center; gap: .3rem; height: 100%; }
.hbar-stack { width: 100%; min-height: 2px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: var(--r-sm); overflow: hidden; background: var(--paper-deep); }
.hbar-bad  { background: var(--red); }
.hbar-good { background: var(--green); }
.hbar-label { font-family: var(--mono); font-size: .62rem; color: var(--ink-soft); }

/* ------------------- Druckseite: Bedienleiste am Schirm --------------- */
.toolbar {
  max-width: 72rem; margin: 0 auto; padding: 1rem clamp(1rem, 4vw, 2rem);
  display: grid; gap: .8rem; background: var(--card); border-bottom: 1px solid var(--rule);
}
.toolbar-info { display: flex; gap: .8rem; align-items: baseline; flex-wrap: wrap; }
.toolbar-form { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.toolbar-form label { font-size: .78rem; }
.toolbar-form select { min-width: 10rem; }
.toolbar-actions { display: flex; gap: .5rem; }
.toolbar-hint { font-size: .78rem; max-width: 60ch; }

/* ------------------------------ Responsiv ----------------------------- */
@media (max-width: 720px) {
  .quickadd-fields { grid-template-columns: 1fr; }
  .card-row { grid-template-columns: 2.6rem 1fr; }
  .card-meta { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
  .sticky-head { position: static; }
  .histogram { height: 7rem; }
  .topnav { gap: .6rem; font-size: .85rem; }
}

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

/* ------------------------------- Scanner ------------------------------ */
.scanner .scan-stage {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #14171a;
  border-radius: var(--r-md);
  overflow: hidden;
  display: none;
  margin-bottom: .9rem;
}
.scanner.is-live .scan-stage { display: block; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 50% auto auto 50%;
  width: 58%; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,.85);
  border-radius: var(--r-md);
  box-shadow: 0 0 0 100vmax rgba(20,23,26,.45);
}
.scanner input[type=file] {
  width: 100%; margin-top: .3rem; font: inherit;
  background: #fff; border: 1px solid var(--rule); border-radius: var(--r-md); padding: .5rem;
}
