:root {
  color-scheme: dark;

  --bg: #151922;
  --bg-soft: #1b2230;
  --bg-softer: #242d3a;
  --bg-hard: #10141b;

  --card: #1b2230;
  --card-border: #313b4f;

  --text: #e8ecf3;
  --text-strong: #f4f7fb;
  --muted: #8a93a6;
  --soft-text: #c9d1d9;

  --blue: #3a72c4;
  --blue-hover: #4a83d8;
  --blue-soft: rgba(58, 114, 196, 0.16);

  --green: #6ee787;
  --green-soft: rgba(110, 231, 135, 0.1);

  --red: #ff7b72;
  --red-soft: rgba(255, 123, 114, 0.1);

  --yellow: #f2cc60;
  --yellow-soft: rgba(242, 204, 96, 0.14);

  --orange: #ffa657;

  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.22);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(58, 114, 196, 0.22), transparent 36rem),
    radial-gradient(circle at bottom right, rgba(255, 123, 114, 0.1), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button,
select,
input {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
}

/* -------------------------------------------------------------------------
   Login-Maske
------------------------------------------------------------------------- */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(18px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(circle at top left, rgba(58, 114, 196, 0.22), transparent 36rem),
    radial-gradient(circle at bottom right, rgba(255, 123, 114, 0.1), transparent 32rem),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: rgba(27, 34, 48, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.auth-title {
  margin: 0;
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  line-height: 1;
}

.auth-subtitle {
  margin: 0 0 4px;
  color: var(--muted);
  line-height: 1.45;
}

.auth-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.auth-field input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #45536a;
  border-radius: 12px;
  outline: none;
  background: var(--bg-hard);
  color: var(--text);
}

.auth-field input:focus {
  border-color: var(--blue-hover);
  box-shadow: 0 0 0 3px rgba(58, 114, 196, 0.22);
}

.auth-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--red);
  font-weight: 800;
  line-height: 1.4;
}

.auth-info {
  min-height: 1.2em;
  margin: 0;
  color: var(--green);
  font-weight: 800;
  line-height: 1.4;
}

/* Registrierungskarte kann lang werden -> im Rahmen scrollbar */
.auth-card {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 2px;
}

.auth-tab {
  flex: 1;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: var(--bg-hard);
  color: var(--muted);
  font-weight: 800;
}

.auth-tab.active {
  border-color: transparent;
  background: var(--blue);
  color: #fff;
}

.auth-panel {
  display: grid;
  gap: 12px;
}

.auth-row {
  display: grid;
  gap: 12px;
}

.auth-field select,
.auth-field textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #45536a;
  border-radius: 12px;
  outline: none;
  background: var(--bg-hard);
  color: var(--text);
  font: inherit;
}

.auth-field textarea {
  min-height: 64px;
  resize: vertical;
}

.auth-field select:focus,
.auth-field textarea:focus {
  border-color: var(--blue-hover);
  box-shadow: 0 0 0 3px rgba(58, 114, 196, 0.22);
}

@media (min-width: 560px) {
  .auth-row {
    grid-template-columns: 1fr 1fr;
  }
}

/* -------------------------------------------------------------------------
   Header
------------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name {
  color: var(--soft-text);
  font-weight: 800;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: rgba(27, 34, 48, 0.88);
  color: var(--soft-text);
  font-weight: 800;
}

.ghost-button:hover {
  background: #2d3849;
  border-color: #5b6d89;
}

/* -------------------------------------------------------------------------
   Statistik-Zeilen
------------------------------------------------------------------------- */

.stats-line-account {
  margin-bottom: 6px;
}

.stats-line-session {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.2rem);
  line-height: 1;
}

h2 {
  margin: 10px 0 16px;
  color: var(--text-strong);
  font-size: clamp(1.25rem, 4.4vw, 1.85rem);
  line-height: 1.25;
}

.pill {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: rgba(27, 34, 48, 0.88);
  color: var(--soft-text);
  font-weight: 800;
  white-space: nowrap;
}

/* -------------------------------------------------------------------------
   Cards / Layout
------------------------------------------------------------------------- */

.stats-card,
.filters,
.question-card {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: rgba(27, 34, 48, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.stats-card {
  padding: 14px;
  margin-bottom: 12px;
}

.stats-line {
  color: var(--soft-text);
  line-height: 1.45;
  margin-bottom: 12px;
}

/* -------------------------------------------------------------------------
   Progress
------------------------------------------------------------------------- */

.progress-wrap {
  position: relative;
  overflow: hidden;
  height: 26px;
  border: 1px solid #354157;
  border-radius: 999px;
  background: var(--bg-hard);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), #79b8ff);
  transition: width 180ms ease;
}

.progress-wrap span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-size: 0.9rem;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

/* -------------------------------------------------------------------------
   Filters
------------------------------------------------------------------------- */

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.filters label {
  color: var(--muted);
  font-weight: 800;
}

select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid #45536a;
  border-radius: 12px;
  outline: none;
  background: var(--bg-hard);
  color: var(--text);
}

select:focus {
  border-color: var(--blue-hover);
  box-shadow: 0 0 0 3px rgba(58, 114, 196, 0.22);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--text) !important;
}

.checkbox-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--blue);
}

/* -------------------------------------------------------------------------
   Question
------------------------------------------------------------------------- */

.question-card {
  display: grid;
  grid-template-columns: 1fr minmax(300px, 42%);
  gap: 20px;
  aspect-ratio: 16 / 9;
  padding: 20px;
  overflow: hidden;
}

.q-main {
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.q-aside {
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding-left: 18px;
  border-left: 1px solid var(--card-border);
}

.q-image {
  display: grid;
  gap: 12px;
  align-content: start;
}

.q-image-cap {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.9rem;
}

.q-fig {
  width: 100%;
  height: auto;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: var(--bg-hard);
}

.q-image-empty {
  padding: 18px;
  border: 1px dashed var(--card-border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
  text-align: center;
}

@media (max-width: 860px) {
  .question-card {
    grid-template-columns: 1fr;
    aspect-ratio: auto;
  }

  .q-aside {
    padding-left: 0;
    padding-top: 14px;
    border-left: none;
    border-top: 1px solid var(--card-border);
  }
}

.tag-line {
  color: var(--muted);
  font-weight: 900;
  line-height: 1.35;
}

.tag-sc {
  color: #79b8ff;
}

.tag-mc {
  color: var(--red);
}

.options {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 1px solid #354157;
  border-radius: 14px;
  background: var(--bg-hard);
  color: var(--text);
  cursor: pointer;
  line-height: 1.4;
  user-select: none;
}

.option:hover {
  border-color: #53647f;
  background: #121925;
}

.option:has(input:checked) {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.option input {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  accent-color: var(--blue);
}

.option.correct {
  border-color: rgba(110, 231, 135, 0.55);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 900;
}

.option.wrong {
  border-color: rgba(255, 123, 114, 0.55);
  background: var(--red-soft);
  color: var(--red);
  font-weight: 900;
}

.option.disabled {
  cursor: default;
}

.option.disabled:hover {
  border-color: #354157;
}

/* -------------------------------------------------------------------------
   Feedback
------------------------------------------------------------------------- */

.feedback {
  min-height: 28px;
  margin-top: 16px;
  color: var(--soft-text);
  line-height: 1.45;
}

.feedback .ok {
  color: var(--green);
  font-weight: 900;
}

.feedback .bad {
  color: var(--red);
  font-weight: 900;
}

.feedback .warn {
  color: var(--yellow);
  font-weight: 900;
}

/* -------------------------------------------------------------------------
   Auswahl-Hinweis (Pflichtanzahl bei Multiple Choice)
------------------------------------------------------------------------- */

.select-hint {
  min-height: 20px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.4;
}

.select-hint.ready {
  color: var(--green);
}

/* -------------------------------------------------------------------------
   Buttons
------------------------------------------------------------------------- */

.buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

button {
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid #45536a;
  border-radius: 14px;
  outline: none;
  background: var(--bg-softer);
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

button:hover {
  background: #2d3849;
  border-color: #5b6d89;
}

button:focus-visible {
  border-color: var(--blue-hover);
  box-shadow: 0 0 0 3px rgba(58, 114, 196, 0.24);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

button.primary {
  border-color: transparent;
  background: var(--blue);
  color: white;
}

button.primary:hover {
  background: var(--blue-hover);
}

#manuscriptButton {
  background: #273247;
}

#manuscriptButton:hover {
  background: #31405b;
}

/* -------------------------------------------------------------------------
   Dialogs
------------------------------------------------------------------------- */

dialog {
  width: min(720px, calc(100% - 24px));
  border: none;
  border-radius: 20px;
  padding: 0;
  background: transparent;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
}

.dialog-card {
  padding: 18px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

/* -------------------------------------------------------------------------
   Evaluation
------------------------------------------------------------------------- */

.evaluation-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  overflow: hidden;
  border-radius: 14px;
}

.evaluation-table th,
.evaluation-table td {
  padding: 10px;
  border-bottom: 1px solid #313b4f;
  text-align: left;
}

.evaluation-table th {
  color: var(--muted);
  background: var(--bg-softer);
  font-weight: 900;
}

.evaluation-table td {
  color: var(--text);
}

.quote-good {
  color: var(--green);
  font-weight: 900;
}

.quote-mid {
  color: var(--yellow);
  font-weight: 900;
}

.quote-bad {
  color: var(--red);
  font-weight: 900;
}

/* -------------------------------------------------------------------------
   Script / Manuscript Dialog
------------------------------------------------------------------------- */

.script-dialog {
  width: min(940px, calc(100% - 24px));
}

.script-dialog-card {
  max-height: min(88vh, 920px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.script-dialog-card h2 {
  margin-bottom: 4px;
}

.script-meta {
  margin: 0;
  color: var(--soft-text);
  line-height: 1.45;
}

.script-meta b:first-child {
  color: var(--text-strong);
}

.script-meta b:last-child {
  color: #79b8ff;
}

.script-question {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
}

.script-search {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: rgba(16, 20, 27, 0.72);
}

.script-search label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.script-search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.script-search input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #45536a;
  border-radius: 12px;
  outline: none;
  background: var(--bg-hard);
  color: var(--text);
}

.script-search input:focus {
  border-color: var(--blue-hover);
  box-shadow: 0 0 0 3px rgba(58, 114, 196, 0.22);
}

.script-search button {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
}

.script-search-info {
  margin: 0;
  color: var(--soft-text);
  font-size: 0.88rem;
  line-height: 1.35;
}

.script-text {
  flex: 1;
  overflow: auto;
  min-height: 280px;
  max-height: 58vh;
  padding: 14px;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: var(--bg-hard);
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92rem;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.script-text mark {
  padding: 0 3px;
  border-radius: 4px;
  font-weight: 900;
}

.script-text mark.auto-hit {
  background: #5c4b16;
  color: #fff3a3;
}

.script-text mark.manual-hit {
  background: #174a7c;
  color: #bfe4ff;
}

.script-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

/* -------------------------------------------------------------------------
   PDF zur Folie
------------------------------------------------------------------------- */

.script-pdf-box {
  display: grid;
  gap: 8px;
}

.script-pdf-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.script-pdf-tab {
  color: #79b8ff;
  font-weight: 800;
  text-decoration: none;
}

.script-pdf-tab:hover {
  text-decoration: underline;
}

.script-pdf-wrap {
  width: 100%;
  height: min(70vh, 720px);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-hard);
}

.script-pdf-frame {
  width: 100%;
  height: 100%;
  border: 0;
}

/* -------------------------------------------------------------------------
   Admin / Verwaltung
------------------------------------------------------------------------- */

.admin-request {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: var(--bg-hard);
}

.admin-request-role {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: #79b8ff;
  font-size: 0.85rem;
  font-weight: 800;
}

.admin-request-sub {
  color: var(--muted);
  font-size: 0.9rem;
}

.admin-request-actions {
  display: flex;
  gap: 8px;
}

.admin-request-actions button {
  min-height: 40px;
}

.admin-empty {
  color: var(--soft-text);
}

.admin-section {
  margin: 16px 0 8px;
  color: var(--text-strong);
  font-size: 1rem;
}

.admin-section:first-child {
  margin-top: 0;
}

.user-status {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}

.user-active {
  background: var(--green-soft);
  color: var(--green);
}

.user-inactive {
  background: var(--red-soft);
  color: var(--red);
}

/* -------------------------------------------------------------------------
   Admin: Inbox / Outbox
------------------------------------------------------------------------- */

.admin-tabs {
  margin-bottom: 14px;
}

.mail-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--bg-hard);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
}

.chip.active {
  border-color: transparent;
  background: var(--blue);
  color: #fff;
}

.chip-action {
  margin-left: auto;
}

.mail-row {
  cursor: pointer;
}

.mail-row:hover {
  border-color: var(--blue);
}

.mail-row.unread {
  border-left: 4px solid var(--blue);
}

.mail-status {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.mail-unread,
.mail-queued,
.mail-sending {
  background: var(--blue-soft);
  color: #79b8ff;
}

.mail-sent {
  background: var(--green-soft);
  color: var(--green);
}

.mail-failed {
  background: var(--red-soft);
  color: var(--red);
}

.mail-detail {
  margin: 12px 0;
}

.mail-body {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-hard);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  font-size: 0.9rem;
  max-height: 320px;
  overflow: auto;
}

.mail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.mail-table th {
  text-align: left;
  padding: 6px 10px 6px 0;
  color: var(--muted);
  white-space: nowrap;
  vertical-align: top;
  width: 130px;
}

.mail-table td {
  padding: 6px 0;
  word-break: break-word;
}

.reply-area {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.reply-area input,
.reply-area textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  background: var(--bg-hard);
  color: var(--text-strong);
  font: inherit;
}

.reply-feedback {
  min-height: 1.2em;
  margin: 0;
}

#adminContent .bad {
  color: var(--red);
}

#adminContent .good {
  color: var(--green);
}

/* -------------------------------------------------------------------------
   Scrollbars
------------------------------------------------------------------------- */

* {
  scrollbar-color: #3a4558 #10141b;
  scrollbar-width: thin;
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: var(--bg-hard);
}

::-webkit-scrollbar-thumb {
  background: #3a4558;
  border: 3px solid var(--bg-hard);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: #4a586f;
}

/* -------------------------------------------------------------------------
   Responsive
------------------------------------------------------------------------- */

@media (min-width: 720px) {
  .filters {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .buttons {
    grid-template-columns: 2fr 1.15fr 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .pill {
    align-self: flex-start;
  }

  .question-card {
    padding: 14px;
  }

  .option {
    padding: 13px;
  }

  .dialog-card {
    padding: 14px;
  }

  .script-search-row {
    grid-template-columns: 1fr;
  }

  .script-search button {
    width: 100%;
  }

  .script-text {
    max-height: 54vh;
    font-size: 0.86rem;
  }
}