/* Self-hosted (not a live Google Fonts link) so the terminal look still
   renders correctly offline — this app is local-first by design, see
   store.js. Share Tech Mono is the body/UI face; VT323 is the big
   CRT-style display face used only for page titles. */
@font-face {
  font-family: 'Share Tech Mono';
  src: url('../fonts/ShareTechMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'VT323';
  src: url('../fonts/VT323-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #0b3d1f;
  --ink-soft: #3f7a58;
  --brown: #0a7a3d;
  --tan: #e3f3e8;
  --parchment: #f5fbf6;
  --edge: #a9d8b8;
  --accent: #c97c00;
  --gold: #127a44;
  --hp: #c81e3a;
  --tracker-blue: #0090b0;
  --magie-purple: #b0179e;
  --status-ok: #127a2e;
  --status-warn: #a66a00;
  --highlight: #ffe066;
  --formula-bg: #e3f3e8;
  --sep: #3f7a58;
  --shadow-rgb: 10, 61, 31;
  --title-font: 'VT323', monospace;
  --display-font: 'Share Tech Mono', monospace;
  color-scheme: light;
}

/* Dark mode — opt-in via the toggle button (js/theme.js), not tied to
   system preference. Default is always light, matching the sheet as
   designed; dark persists once explicitly chosen (localStorage only,
   never synced as character data — it's a display preference, not
   game data). This is the Matrix-inspired black/phosphor-green look. */
:root[data-theme="dark"] {
  --ink: #4dff88;
  --ink-soft: #3fae74;
  --brown: #39ff88;
  --tan: #0d2818;
  --parchment: #030a05;
  --edge: #1c5c38;
  --accent: #ffb300;
  --gold: #6dffa8;
  --hp: #ff3355;
  --tracker-blue: #00e5ff;
  --magie-purple: #ff33cc;
  --status-ok: #39ff88;
  --status-warn: #ffcc00;
  --highlight: #ffcc00;
  --formula-bg: #0d2818;
  --sep: #3fae74;
  --shadow-rgb: 0, 255, 102;
  color-scheme: dark;
}

* { -webkit-tap-highlight-color: transparent; }

body {
  background: #eef7ee;
  font-family: var(--display-font);
  color: var(--ink);
  padding: 14px;
  margin: 0;
  max-width: 900px;
  margin-inline: auto;
  border: 2px solid var(--brown);
  outline: 1px solid var(--edge);
  outline-offset: -7px;
  box-shadow: 0 10px 28px rgba(var(--shadow-rgb), 0.25);
  min-height: 100vh;
  box-sizing: border-box;
  transition: background-color 0.2s ease, color 0.2s ease;
  position: relative;
}
/* Dark mode swaps the flat light background for a black CRT vignette plus
   a faint scanline overlay (body::after below) — the closest a stylesheet
   gets to a phosphor monitor without shipping an image asset. */
[data-theme="dark"] body,
[data-theme="dark"] .search-container {
  background: radial-gradient(ellipse at top, #061006 0%, #000000 75%);
}
[data-theme="dark"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(57, 255, 136, 0.05) 0px,
    rgba(57, 255, 136, 0.05) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: screen;
  z-index: 1000;
}

h1, h2, h3 { text-align: center; color: var(--brown); margin: 10px 0; }

h1 {
  font-family: var(--title-font);
  font-weight: 400;
  font-size: 2.6em;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 0 4px rgba(var(--shadow-rgb), 0.5);
}
/* The neon glow only reads as "glow" against a dark background — on the
   light terminal theme it would just look like blur, so it's dark-only. */
[data-theme="dark"] h1 {
  text-shadow: 0 0 6px var(--brown), 0 0 18px rgba(var(--shadow-rgb), 0.7);
}
h1::after {
  content: "";
  display: block;
  width: 150px;
  height: 2px;
  margin: 6px auto 0;
  background: linear-gradient(to right, transparent, var(--gold), transparent);
}

h2 {
  font-family: var(--display-font);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 1.15em;
}
h2::before { content: "> "; }
h3 { font-family: var(--display-font); font-weight: 400; letter-spacing: 0.03em; }

.box {
  border: 1px solid var(--brown);
  outline: 1px solid var(--edge);
  outline-offset: -6px;
  background: rgba(240, 250, 242, 0.9);
  border-radius: 4px;
  padding: 14px;
  margin: 14px 0;
  box-shadow: 0 3px 10px rgba(var(--shadow-rgb), 0.12);
  transition: background-color 0.2s ease;
}
[data-theme="dark"] .box { background: rgba(3, 12, 6, 0.88); box-shadow: 0 0 14px rgba(var(--shadow-rgb), 0.15); }

label { display: block; margin: 5px 0; font-weight: normal; color: var(--ink-soft); }

textarea, input[type="text"], input[type="email"], input[type="password"] {
  width: 100%;
  padding: 6px;
  margin-bottom: 10px;
  border: 1px solid var(--brown);
  background: var(--parchment);
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  box-sizing: border-box;
  border-radius: 3px;
}

input[type="number"], select {
  width: 100%;
  margin: 0;
  box-sizing: border-box;
  font-size: 12px;
  border: 1px solid var(--edge);
  background: var(--parchment);
  color: var(--ink);
  border-radius: 3px;
  padding: 3px;
  font-family: inherit;
}

nav { text-align: center; margin: 10px 0; }
nav a, .theme-toggle {
  margin: 0 6px 6px;
  text-decoration: none;
  color: var(--brown);
  font-family: var(--display-font);
  font-weight: 400;
  font-size: 0.82em;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--brown);
  padding: 7px 14px;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
  display: inline-block;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
/* Inverse video on hover — the classic terminal "selected" look. */
nav a:hover, .theme-toggle:hover {
  background: var(--brown);
  color: var(--parchment);
  box-shadow: 0 0 12px rgba(var(--shadow-rgb), 0.55);
}
.theme-toggle {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}

/* ---- Sync status badge ---- */
.sync-badge {
  display: block;
  text-align: center;
  font-size: 11px;
  padding: 3px 0 0;
  color: var(--ink-soft);
  min-height: 15px;
}
.sync-ok::before { content: "● "; color: var(--status-ok); }
.sync-warn::before { content: "● "; color: var(--status-warn); }
.sync-neutral::before { content: "○ "; color: var(--ink-soft); }

/* ---- Collapsible sections ---- */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.collapsible-header h2 { margin: 0; }
.collapse-arrow {
  font-size: 12px;
  color: var(--brown);
  transition: transform 0.2s ease;
  display: inline-block;
}
.collapse-arrow.collapsed { transform: rotate(-90deg); }
.collapsible-body {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 1200px;
  opacity: 1;
}
.collapsible-body.collapsed { max-height: 0; opacity: 0; }

/* ---- Basiswerte grid ---- */
.attr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.attr-grid label { margin: 0; font-size: 13px; }
.attr-grid input { font-size: 15px; text-align: center; padding: 5px; }

.sub-h { margin: 16px 0 8px; font-size: 1em; border-top: 1px solid var(--edge); padding-top: 10px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row button {
  flex: 1;
  min-width: 120px;
  padding: 9px 8px;
  border: 1px solid var(--brown);
  background: transparent;
  color: var(--brown);
  border-radius: 3px;
  font-family: var(--display-font);
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 12.5px;
  box-shadow: none;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.btn-row button:hover { background: var(--brown); color: var(--parchment); }
.btn-row button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row button:disabled:hover { background: transparent; color: var(--brown); }

/* ---- Search ---- */
.search-container {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #eef7ee;
  padding: 8px 0 4px;
}
.search-box {
  border: 1px solid var(--brown);
  background: rgba(240, 250, 242, 0.97);
  border-radius: 4px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
[data-theme="dark"] .search-box { background: rgba(3, 12, 6, 0.92); }
.search-icon { flex-shrink: 0; opacity: 0.65; color: var(--ink-soft); }
#skillSearch {
  flex: 1;
  border: 1px solid var(--edge);
  background: var(--parchment);
  padding: 6px 10px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
#skillSearch:focus { border-color: var(--brown); }
#searchClear {
  border: 1px solid var(--edge);
  background: var(--parchment);
  color: var(--brown);
  border-radius: 3px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  display: none;
  flex-shrink: 0;
}
#searchClear:hover { background: var(--tan); }
#searchCount {
  font-size: 11px;
  color: var(--ink-soft);
  text-align: right;
  padding: 3px 2px 0;
  min-height: 16px;
}
tr.skill-hidden { display: none; }
.cat-box-hidden { display: none; }
mark.search-highlight {
  background: var(--highlight);
  /* Always dark text on this highlight regardless of theme — a search
     match should stay legible without needing its own theme variant. */
  color: #1a1400;
  border-radius: 2px;
  padding: 0 1px;
}

/* ---- Skill tables ---- */
.cat {
  margin-top: 15px;
  font-family: var(--display-font);
  font-size: 1.05em;
  font-weight: 400;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink);
}
.cat-note { font-weight: normal; font-size: 0.75em; }
.table-wrapper { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  min-width: 320px;
  border-collapse: collapse;
  margin-bottom: 10px;
  table-layout: fixed;
}
col.col-name  { width: 28%; }
col.col-attr  { width: 24%; }
col.col-fw    { width: 16%; }
col.col-malus { width: 18%; }
col.col-wert  { width: 14%; }

/* Gaben table — Beschreibung is the one that needs the room */
col.col-gabe-name   { width: 25%; }
col.col-gabe-beschr { width: 67%; }

/* Zauber tables — the spell name was getting truncated to a few letters
   while the remove button got a full, mostly-empty column */
col.col-zauber-name    { width: 34%; }
col.col-zf              { width: 9%; }
col.col-zauber-malus    { width: 23%; }
col.col-zauber-mp       { width: 11%; }
col.col-zauber-endwert  { width: 15%; }

/* Shared: the remove-row column only ever holds a small ✕ button */
col.col-remove { width: 8%; }
th, td {
  border: 1px solid var(--edge);
  padding: 4px 3px;
  font-size: 12px;
  overflow: hidden;
  word-break: break-word;
}
th {
  background: var(--tan);
  font-family: var(--display-font);
  font-weight: 400;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--brown);
}
.orange {
  /* A fixed dark chip (not the page background) so the amber readout stays
     legible in both themes — amber-on-light-page contrast is too low. */
  background: #0a0a0a;
  border: 1px solid var(--accent);
  box-shadow: 0 0 6px rgba(var(--shadow-rgb), 0.2), inset 0 0 4px rgba(0, 0, 0, 0.6);
  color: var(--accent);
  font-weight: bold;
  padding: 2px 4px;
  display: block;
  width: 100%;
  text-align: center;
  box-sizing: border-box;
  border-radius: 3px;
}
.empty-row { text-align: center; color: var(--ink-soft); font-style: italic; }
tr.total-row td { font-weight: bold; background: var(--tan); }
.row-remove {
  border: 1px solid var(--edge);
  background: var(--parchment);
  color: var(--hp);
  border-radius: 3px;
  width: 100%;
  cursor: pointer;
  font-size: 11px;
  padding: 2px;
}
.row-remove:hover { background: rgba(255, 51, 85, 0.18); border-color: var(--hp); }

/* ---- Status trackers ---- */
.tracker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tracker-card {
  background: var(--parchment);
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.tracker-label { font-family: var(--display-font); font-weight: 400; letter-spacing: 0.03em; text-transform: uppercase; font-size: 12px; color: var(--brown); }
.tracker-bar-wrap {
  width: 100%;
  height: 10px;
  background: var(--tan);
  border-radius: 3px;
  overflow: hidden;
}
.tracker-bar { height: 100%; border-radius: 3px; transition: width 0.25s ease; }
.bar-hp { background: var(--hp); }
.bar-mp { background: var(--tracker-blue); }
.tracker-inputs { display: flex; align-items: center; gap: 4px; }
.tracker-num {
  width: 58px;
  text-align: center;
  border: 1px solid var(--edge);
  background: var(--parchment);
  font-family: inherit;
  font-size: 18px;
  font-weight: bold;
  padding: 4px;
  border-radius: 3px;
  color: var(--ink);
}
.tracker-sep { color: var(--sep); font-size: 18px; font-weight: bold; }
.tracker-btns { display: flex; gap: 8px; }
.tracker-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--brown);
  background: transparent;
  border-radius: 3px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--brown);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tracker-btn:hover { background: var(--brown); color: var(--parchment); }
.tracker-btn:active { transform: scale(0.93); }

/* ---- Hints ---- */
.hint { font-size: 11px; color: var(--ink-soft); text-align: center; margin: 4px 0 10px; }
.hint-inline { font-weight: normal; font-size: 0.7em; color: var(--ink-soft); }

/* ---- Portrait (Charakterbeschreibung) ----
 * Flex row so the portrait sits beside the fields on wider screens; the
 * fields' min-width naturally forces a wrap onto their own line below the
 * portrait on narrow phones, with no separate breakpoint needed. */
.info-layout { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.info-fields { flex: 1 1 220px; min-width: 200px; }
.portrait-wrap { display: flex; flex-direction: column; align-items: center; flex: 0 0 auto; margin: 0 auto; }
.portrait-frame {
  width: 220px;
  height: 330px;
  border: 1px solid var(--brown);
  outline: 1px solid var(--edge);
  outline-offset: -5px;
  border-radius: 4px;
  background: var(--tan);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 8px;
}
/* contain, not cover — never crop a friend's uploaded portrait to fit the frame */
.portrait-frame img { width: 100%; height: 100%; object-fit: contain; }
.portrait-frame svg { width: 62%; height: 62%; color: var(--ink-soft); }
/* UA stylesheets only guarantee [hidden] → display:none for HTML elements, not SVG */
.portrait-frame [hidden] { display: none; }
.portrait-wrap .btn-row { max-width: 280px; }

/* ---- Auth (login page + nav identity/logout) ---- */
.auth-box { max-width: 360px; margin: 40px auto 0; }
.form-error { font-size: 13px; color: var(--status-warn); text-align: center; min-height: 18px; margin: 6px 0 0; }
.auth-badge { text-align: center; font-size: 11px; color: var(--ink-soft); margin: 2px 0 0; }
.hint a, .hint-inline a { color: var(--brown); }

/* ---- Derived stats (Basiswerte / Kampf / Magie) ---- */
.derived-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
.derived-cell {
  background: var(--parchment);
  border: 1px solid var(--edge);
  border-radius: 3px;
  padding: 6px 4px;
  text-align: center;
}
.derived-label { font-family: var(--display-font); font-weight: 400; font-size: 9.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.derived-value { font-size: 20px; font-weight: bold; color: var(--brown); }
.derived-editable input { text-align: center; font-size: 18px; font-weight: bold; padding: 3px; margin-top: 2px; }
.attr-grid-aengste input { font-size: 14px; }

/* ---- Kampfmalus readout ---- */
.malus-readout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 8px;
}
.malus-label { font-family: var(--display-font); font-weight: 400; text-transform: uppercase; letter-spacing: 0.02em; font-size: 11px; color: var(--ink-soft); }
.malus-value {
  font-size: 26px;
  font-weight: bold;
  color: var(--accent);
  /* Same fixed dark chip as .orange — keeps amber legible in light mode. */
  background: #0a0a0a;
  border: 1px solid var(--accent);
  box-shadow: 0 0 8px rgba(var(--shadow-rgb), 0.2), inset 0 0 4px rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  padding: 2px 16px;
}
.malus-strip {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  max-width: 420px;
  margin: 0 auto;
}
.malus-cell {
  font-size: 9px;
  text-align: center;
  border: 1px solid var(--edge);
  border-radius: 2px;
  padding: 2px 0;
  color: var(--ink-soft);
  background: var(--parchment);
}
.malus-cell.active { background: var(--accent); color: #1a1400; font-weight: bold; }

/* ---- Körperzonen / Wunden ---- */
.zone-card {
  border: 1px solid var(--edge);
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--parchment);
}
.zone-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.zone-name { font-family: var(--display-font); font-weight: 400; letter-spacing: 0.03em; text-transform: uppercase; font-size: 0.95em; color: var(--brown); }
.zone-meta { font-size: 10px; color: var(--ink-soft); }
.zone-boxes { display: flex; gap: 6px; flex-wrap: wrap; }
.wunde-box {
  width: 48px;
  height: 44px;
  border: 1px solid var(--brown);
  border-radius: 4px;
  background: var(--parchment);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  padding: 0;
}
.wunde-vp { font-size: 13px; font-weight: bold; color: var(--brown); }
.wunde-heilung { font-size: 9px; color: var(--ink-soft); }
.wunde-box.marked { background: var(--hp); border-color: var(--hp); }
.wunde-box.marked .wunde-vp, .wunde-box.marked .wunde-heilung { color: #fff; }

/* ---- Regeln reference text ---- */
.regeln-text h3 { text-align: left; font-size: 1em; margin: 14px 0 4px; }
.regeln-text p { font-size: 12.5px; line-height: 1.5; margin: 4px 0; }
.regeln-table { font-size: 12px; }
.regeln-table td { border: 1px solid var(--edge); padding: 3px 6px; }
.regeln-table td:first-child { font-weight: bold; white-space: nowrap; width: 70px; }

/* ---- Magie ---- */
.formula-banner {
  background: var(--formula-bg);
  text-align: center;
  font-size: 12.5px;
  font-weight: bold;
  padding: 8px;
}
/* Always one full-width column (same width as the Gaben box) — spell
   names/descriptions need the room more than a 2-up layout is worth. */
.magie-categories { display: grid; grid-template-columns: 1fr; gap: 0; }
.magie-kat-header { justify-content: space-between; padding: 2px 2px 0; }
.magie-kat-header h2 { margin: 0; font-size: 1.3em; }
.magie-kat-count { font-size: 13px; font-weight: normal; color: var(--ink-soft); }
.mp-bar-wrap { width: 100%; height: 12px; background: var(--tan); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.mp-bar { height: 100%; background: var(--magie-purple); border-radius: 3px; transition: width 0.25s ease; }

@media print {
  nav, .search-container, .btn-row, .tracker-btns, .sync-badge, .row-remove, .theme-toggle { display: none; }
  .collapsible-body.collapsed { max-height: none; opacity: 1; }
  /* Printing should always be light/legible on paper, regardless of
     which theme was active on screen — dark mode's neon-on-black text
     would otherwise print as nearly invisible on white. */
  body, .box { background: #fff !important; color: #000 !important; box-shadow: none !important; }
  body::after { display: none !important; }
}
