:root {
  color-scheme: dark;
  --bg: #0f1419;
  --panel: #151a24;
  --cell: #1a1f2e;
  --cell-soft: #202638;
  --text: #e8e8e8;
  --muted: #aab2c0;
  --gold: #d4a574;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.15);
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 260px),
    var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.45;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 78px;
  padding: 12px 18px;
  background: rgba(15, 20, 25, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  flex: 0 0 auto;
  min-width: 230px;
}

.brand h1 {
  margin: 0;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 750;
  letter-spacing: 0;
}

.brand p {
  margin: 1px 0 0;
  color: var(--gold);
  font-size: 0.9rem;
  font-style: italic;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.toolbar button,
.toggle {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #202638;
  color: var(--text);
  padding: 8px 11px;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: filter 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.toolbar button:hover,
.toggle:hover {
  border-color: rgba(212, 165, 116, 0.5);
  filter: brightness(1.12);
}

.toolbar button:active,
.toggle:active {
  transform: translateY(1px);
}

.toolbar .danger,
.modal .danger {
  border-color: rgba(192, 57, 43, 0.5);
  color: #ffd8d3;
}

.toolbar .primary {
  border-color: rgba(212, 165, 116, 0.55);
  background: rgba(212, 165, 116, 0.16);
  color: #fff;
  font-weight: 800;
}

.toolbar .primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}

.row-counter {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.toolbar-sep {
  display: inline-block;
  width: 1px;
  height: 26px;
  margin: 0 4px;
  background: var(--line-strong);
}

.row-hidden {
  display: none !important;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle input {
  accent-color: var(--gold);
}

.page-shell {
  width: min(1900px, calc(100vw - 28px));
  margin: 18px auto 36px;
}

.grid-wrap {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  box-shadow: var(--shadow);
}

.xabcde-grid {
  display: grid;
  grid-template-columns: minmax(108px, 0.58fr) minmax(160px, 0.95fr) minmax(210px, 1.25fr) minmax(250px, 1.55fr) minmax(250px, 1.55fr) minmax(250px, 1.55fr);
  gap: 1px;
  background: var(--line);
}

.grid-head,
.grid-cell {
  min-width: 0;
  background: var(--cell);
}

.grid-head {
  position: sticky;
  top: 78px;
  z-index: 15;
  padding: 11px 12px;
  color: var(--gold);
  font-size: 0.84rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #151b28;
  border-bottom: 1px solid rgba(212, 165, 116, 0.28);
}

.grid-cell {
  min-height: 132px;
  padding: 12px;
}

.letter-cell {
  display: grid;
  align-content: start;
  gap: 9px;
  border-left: 4px solid var(--row-color);
}

.letter-badge {
  display: inline-grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  color: #fff;
  font-size: 1.38rem;
  font-weight: 850;
  line-height: 1;
  text-align: center;
  box-shadow: 0 12px 28px color-mix(in srgb, var(--row-color), transparent 68%);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.vital-pill {
  display: none;
  width: fit-content;
  max-width: 100%;
  border: 1px solid color-mix(in srgb, var(--row-color), white 18%);
  border-radius: 999px;
  padding: 5px 8px;
  color: #fff;
  background: color-mix(in srgb, var(--row-color), transparent 72%);
  font-size: 0.78rem;
  font-weight: 700;
}

.show-vitals .vital-pill:not(:empty) {
  display: inline-block;
}

.reveal-cell {
  position: relative;
  display: block;
  width: 100%;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  border-radius: 0;
  color: var(--text);
  text-align: left;
  overflow: hidden;
  transition: box-shadow 180ms ease, background 180ms ease;
}

.reveal-cell:not(.revealed) {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent),
    #171c29;
}

.reveal-cell:not(.revealed)::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  pointer-events: none;
}

.reveal-cell:hover {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--row-color), white 16%), 0 0 24px color-mix(in srgb, var(--row-color), transparent 78%);
}

.placeholder {
  display: grid;
  min-height: 104px;
  place-items: center;
  color: #d7dce6;
  font-size: 0.96rem;
  text-align: center;
}

.revealed-content {
  display: block;
  color: #fff;
  font-size: 1.08rem;
  font-weight: 730;
  animation: revealIn 300ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes revealIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.input-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.snippet-controls {
  position: relative;
  display: flex;
  justify-content: flex-end;
  min-height: 28px;
}

.snippet-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid color-mix(in srgb, var(--row-color), white 20%);
  border-radius: 8px;
  background: color-mix(in srgb, var(--row-color), #1a1f2e 78%);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1;
}

.snippet-button:hover {
  filter: brightness(1.18);
}

.snippet-menu {
  position: absolute;
  top: 34px;
  right: 0;
  z-index: 25;
  width: min(340px, 72vw);
  max-height: 360px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #111722;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  animation: menuIn 140ms ease-out both;
}

@keyframes menuIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.snippet-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 8px 9px;
  text-align: left;
  font-size: 0.92rem;
}

.snippet-menu button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.hide-snippets .snippet-controls {
  display: none;
}

textarea {
  display: block;
  width: 100%;
  min-height: 76px;
  resize: none;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(3, 7, 12, 0.28);
  color: var(--text);
  padding: 10px 11px;
  font-size: 1rem;
  line-height: 1.42;
  outline: none;
}

textarea:focus {
  border-color: color-mix(in srgb, var(--row-color), white 18%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--row-color), transparent 78%);
}

textarea::placeholder {
  color: rgba(232, 232, 232, 0.42);
}

.bonus-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.info-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.25);
}

.info-card summary {
  padding: 15px 16px;
  color: var(--gold);
  font-weight: 800;
  cursor: pointer;
}

.info-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 16px 16px;
}

.info-card dl div {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: baseline;
}

.info-card dt {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(212, 165, 116, 0.16);
  color: #fff;
  font-weight: 850;
}

.info-card dd {
  margin: 0;
  color: #d7dce6;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid rgba(212, 165, 116, 0.5);
  border-radius: 8px;
  background: rgba(20, 24, 32, 0.95);
  color: #fff;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(440px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #171c29;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 8px;
  color: #fff;
  font-size: 1.3rem;
}

.modal p {
  margin: 0 0 18px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-actions button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #202638;
  color: var(--text);
  padding: 8px 12px;
}

@media (max-width: 1100px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .grid-head {
    top: 137px;
  }
}

@media (max-width: 767px) {
  .page-shell {
    width: min(100% - 18px, 720px);
  }

  .xabcde-grid {
    display: block;
    background: transparent;
  }

  .grid-head {
    display: none;
  }

  .grid-cell {
    min-height: auto;
    margin-bottom: 1px;
  }

  .letter-cell {
    border-radius: 8px 8px 0 0;
  }

  .input-cell:nth-of-type(6n) {
    border-radius: 0 0 8px 8px;
    margin-bottom: 14px;
  }

  .bonus-grid {
    grid-template-columns: 1fr;
  }
}

@page {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  :root {
    color-scheme: light;
  }

  html,
  body {
    background: #fff !important;
    color: #000 !important;
  }

  body {
    font-size: 10pt;
  }

  body::before {
    content: "xABCDE · Notfallmedizin · " attr(data-print-date);
    display: block;
    margin: 0 0 7mm;
    color: #000;
    font-weight: 800;
    text-align: center;
  }

  .topbar,
  .snippet-controls,
  .toast,
  .modal-backdrop {
    display: none !important;
  }

  .row-hidden {
    display: block !important;
  }

  .xabcde-grid .row-hidden {
    display: revert !important;
  }

  .page-shell {
    width: 100%;
    margin: 0;
  }

  .grid-wrap {
    border: 1px solid #999;
    box-shadow: none;
  }

  .xabcde-grid {
    display: grid;
    grid-template-columns: 24mm 38mm 55mm 1fr 1fr 1fr;
    gap: 0;
    background: transparent;
  }

  .grid-head,
  .grid-cell {
    background: #fff !important;
    color: #000 !important;
    border-right: 1px solid #999;
    border-bottom: 1px solid #999;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .grid-head {
    position: static;
    display: block;
    padding: 4px 5px;
    color: #000 !important;
    font-size: 7.8pt;
  }

  .grid-cell {
    min-height: 22mm;
    padding: 5px;
  }

  .letter-badge {
    width: 15mm;
    height: 15mm;
    font-size: 11pt;
    color: #fff !important;
    box-shadow: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .vital-pill {
    display: inline-block !important;
    border-color: #999;
    background: transparent !important;
    color: #000 !important;
    font-size: 7.5pt;
  }

  .reveal-cell {
    border-top: 0;
    border-right: 1px solid #999;
    border-bottom: 1px solid #999;
    border-radius: 0;
    box-shadow: none !important;
  }

  .reveal-cell::after {
    display: none;
  }

  .reveal-cell .placeholder {
    display: none;
  }

  .reveal-cell::before {
    content: attr(data-content);
    display: block;
    color: #000;
    font-weight: 700;
  }

  .reveal-cell.revealed::before {
    content: "";
    display: none;
  }

  .revealed-content {
    color: #000 !important;
    font-size: 9.5pt;
    font-weight: 700;
    animation: none;
  }

  textarea {
    display: none;
  }

  .input-cell::after {
    content: attr(data-print-value);
    display: block;
    color: #000;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 8.5pt;
    line-height: 1.25;
  }

  .bonus-grid {
    display: none;
  }
}
