:root {
  --bg: #1b1715;
  --panel: #262019;
  --panel2: #30281f;
  --line: #4a3d2e;
  --text: #efe6d6;
  --muted: #a89a85;
  --gold: #d6a84a;
  --red: #c4483c;
  --green: #5aa063;
  --blue: #5b8fc9;
  --radius: 12px;
  --nav-h: 62px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 820px; margin: 0 auto; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px);
}
input, select, textarea, button {
  font: inherit; color: inherit; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
button { cursor: pointer; background: #3a3024; white-space: nowrap; }
button:active { transform: translateY(1px); }
button.good { background: #2f4a31; border-color: var(--green); }
button.bad { background: #4e2622; border-color: var(--red); }
button.ghost { background: transparent; border: none; font-size: 20px; padding: 4px 10px; }
button.mini { padding: 0 9px; font-size: 16px; line-height: 24px; margin-left: auto; }
.btn { display: inline-block; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #3a3024; cursor: pointer; text-align: center; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 15px; color: var(--text); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin-top: 8px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 12px 0; border-bottom: 1px solid var(--line); }
.top-row { display: flex; gap: 6px; align-items: center; }
.top-row select { flex: 1; background: transparent; border: none; color: var(--muted); padding-left: 0; }
.hero .name { width: 100%; font-size: 22px; font-weight: 700; background: transparent; border: none; padding: 2px 0; font-family: Georgia, "Times New Roman", serif; color: var(--gold); }
.hero .sub { display: flex; gap: 6px; flex-wrap: wrap; }
.hero .sub input { flex: 1 1 90px; background: transparent; border: none; border-bottom: 1px dashed var(--line); border-radius: 0; padding: 2px 0; font-size: 14px; }
.hero .lvl { flex-direction: row; align-items: center; gap: 4px; font-size: 13px; }
.hero .lvl input { width: 52px; padding: 2px 6px; }
.quick { display: flex; gap: 6px; margin: 8px 0 6px; overflow-x: auto; }
.pill { flex: 1 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; text-align: center; }
.pill .lbl { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pill b { font-size: 18px; }
.pill.hp b { color: var(--green); }
.pill.hp.low b { color: var(--red); }
.pill small { color: var(--blue); margin-left: 3px; }
.hpbar { height: 4px; background: #3b2f25; margin: 0 -12px; position: relative; display: flex; }
.hpbar > div { height: 100%; transition: width .25s; }
#hpBarFill { background: var(--green); }
#hpBarTemp { background: var(--blue); }

main { padding: 4px 12px; }
.tab { display: none; }
.tab.on { display: block; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 15px; font-family: Georgia, serif; color: var(--gold); letter-spacing: .02em; }
.card h2 small { font-family: system-ui, sans-serif; font-size: 11px; color: var(--muted); font-weight: 400; }
.card label + label { margin-top: 8px; }
.grid2, .grid3 { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid2 + label, .grid3 + label { margin-top: 8px; }
.card .grid2 > label + label, .card .grid3 > label + label { margin-top: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; }
.row > button { flex: 1; }
.row.end { justify-content: flex-end; }
.row.end > button { flex: 0 0 auto; }
.row + .row { margin-top: 8px; }
.stat { display: flex; flex-direction: column; justify-content: center; align-items: center; background: var(--panel2); border-radius: 8px; }
.stat span { font-size: 11px; color: var(--muted); }
.stat b { font-size: 20px; }

.hp-ctrl { display: grid; grid-template-columns: 1.2fr 1fr 1fr .8fr; gap: 6px; margin-bottom: 10px; }
.hp-ctrl input { font-size: 18px; text-align: center; }
.hd { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; font-size: 14px; }
.hd #hdLeft { color: var(--muted); }
.hd button { margin-left: auto; }

.dots { display: inline-flex; gap: 6px; vertical-align: middle; }
.dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--gold); background: transparent; padding: 0; }
.dot.on { background: var(--gold); }
.dots.bad .dot { border-color: var(--red); }
.dots.bad .dot.on { background: var(--red); }
.death { display: flex; flex-direction: column; gap: 8px; }
.death > div { display: flex; justify-content: space-between; align-items: center; }
.exh { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.exh .dot { width: 18px; height: 18px; border-color: var(--red); }
.exh .dot.on { background: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: transparent; color: var(--muted); }
.chip.on { background: #5a2a24; color: #fff; border-color: var(--red); }

.abil { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.ab { background: var(--panel2); border-radius: 10px; padding: 8px; text-align: center; }
.ab .k { font-size: 11px; color: var(--muted); letter-spacing: .08em; }
.ab .m { font-size: 26px; font-weight: 700; display: block; background: none; border: none; width: 100%; padding: 0; }
.ab input { width: 64px; text-align: center; padding: 2px; }

.list { display: flex; flex-direction: column; gap: 6px; }
.li { display: flex; gap: 8px; align-items: center; background: var(--panel2); border-radius: 8px; padding: 6px 8px; }
.li .grow { flex: 1; min-width: 0; }
.li .val { font-weight: 700; min-width: 34px; text-align: right; }
.li .prof { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted); padding: 0; font-size: 11px; line-height: 18px; background: transparent; flex: none; }
.li .prof.p1 { background: var(--gold); border-color: var(--gold); color: #000; }
.li .prof.p2 { background: var(--gold); border-color: #fff; color: #000; font-weight: 700; }
.li .ab-tag { font-size: 11px; color: var(--muted); }
.li input { background: transparent; border-color: transparent; padding: 4px; }
.li input:hover { border-color: var(--line); }
.li .x { background: transparent; border: none; color: var(--muted); padding: 2px 6px; }
.li.col { flex-direction: column; align-items: stretch; }
.li.col .head { display: flex; gap: 6px; align-items: center; }
.li textarea { background: transparent; border-color: transparent; font-size: 13px; color: var(--muted); padding: 4px; }
.li textarea:focus { color: var(--text); }
.li .tog { background: transparent; border: none; color: var(--muted); padding: 2px 6px; }
.li.closed .body { display: none; }
.res-pips { display: flex; flex-wrap: wrap; gap: 5px; padding: 2px 4px 4px; }
.res-pips .dot { width: 20px; height: 20px; }
.res-num { display: flex; align-items: center; gap: 6px; padding: 2px 4px; }
.res-num b { min-width: 60px; text-align: center; }
.small { font-size: 12px; color: var(--muted); }
.n { width: 56px; text-align: center; }
select.small { padding: 3px; font-size: 12px; }

.slots { display: flex; flex-direction: column; gap: 6px; }
.slot { display: flex; align-items: center; gap: 10px; }
.slot .lv { width: 52px; font-size: 13px; color: var(--muted); }
.slot input { width: 50px; text-align: center; padding: 3px; }
.slot .dot { border-color: var(--blue); }
.slot .dot.on { background: transparent; border-color: #555; }
.slot .dot:not(.on) { background: var(--blue); }

.coins { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.coins input { text-align: center; padding: 6px 2px; }
.weight { text-align: right; font-size: 13px; color: var(--muted); margin-top: 8px; }

.dice { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-bottom: 8px; }
.dice button { padding: 8px 0; font-size: 13px; }
.rolllog { list-style: none; padding: 0; margin: 8px 0 0; font-size: 14px; max-height: 180px; overflow: auto; }
.rolllog li { padding: 4px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.rolllog li b { color: var(--gold); font-size: 17px; }
.rolllog li.crit b { color: var(--green); }
.rolllog li.fail b { color: var(--red); }
.rolllog .d { color: var(--muted); font-size: 12px; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); width: min(440px, calc(100% - 32px)); padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.menu h2 { margin: 0 0 6px; color: var(--gold); font-family: Georgia, serif; }
.menu h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
#syncCode { font-family: ui-monospace, monospace; font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 30px); opacity: 0; background: #000c; border: 1px solid var(--gold); padding: 10px 16px; border-radius: 10px; transition: .25s; pointer-events: none; z-index: 20; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 480px) {
  .hp-ctrl { grid-template-columns: 1fr 1fr 1fr; }
  .hp-ctrl input { grid-column: 1 / -1; }
  .dice { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .coins label { font-size: 11px; }
}

/* ---------- Charakterbild ---------- */
.hero { display: flex; gap: 10px; align-items: center; }
.hero-txt { flex: 1; min-width: 0; }
.avatar { flex: none; width: 64px; height: 64px; border-radius: 50%; padding: 0; overflow: hidden; border: 2px solid var(--gold); background: var(--panel2); position: relative; font-size: 22px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: none; }
.avatar.has img { display: block; }
.avatar.has span { display: none; }
.portrait-dlg img { display: block; width: 100%; max-height: 70vh; object-fit: contain; border-radius: 8px; margin-bottom: 12px; }

/* ---------- Vorteil / Nachteil ---------- */
.advmode { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.advmode button { border: none; border-radius: 0; background: transparent; color: var(--muted); }
.advmode button.on { background: var(--gold); color: #1b1715; font-weight: 700; }
.advmode button[data-adv=dis].on { background: var(--red); color: #fff; }
.advmode button[data-adv=adv].on { background: var(--green); color: #fff; }

/* ---------- Würfel-Overlay ---------- */
.dice-ov { position: fixed; inset: 0; z-index: 30; background: radial-gradient(circle at 50% 45%, rgba(60, 40, 15, .92), rgba(5, 4, 3, .96)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; animation: ovIn .25s ease-out; }
.dice-ov[hidden] { display: none; }
@keyframes ovIn { from { opacity: 0; } }
.dice-stage { display: flex; flex-wrap: wrap; justify-content: center; gap: 28px; padding: 0 16px; }
.dr { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 220px; text-align: center; animation: toss .9s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes toss { 0% { transform: translate(-120px, 260px) scale(.3); opacity: 0; } 60% { opacity: 1; } 100% { transform: none; } }
.die { width: 150px; height: 150px; position: relative; perspective: 500px; }
.die svg { width: 100%; height: 100%; filter: drop-shadow(0 8px 18px rgba(0, 0, 0, .6)); will-change: transform; }
.die .face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font: 700 44px/1 Georgia, serif; color: #fff; text-shadow: 0 2px 6px #000; pointer-events: none; }
.dr .lbl { font-size: 15px; color: var(--gold); font-family: Georgia, serif; }
.dr .det { font-size: 12px; color: var(--muted); min-height: 1em; }
.dr .tot { font: 700 30px/1 Georgia, serif; color: #fff; opacity: 0; transition: opacity .3s; }
.dr.landed .tot { opacity: 1; }
.dr.landed .die { animation: land .5s ease-out; }
@keyframes land { 0% { transform: scale(1.25); } 60% { transform: scale(.94); } 100% { transform: scale(1); } }
.dr.crit .die svg { filter: drop-shadow(0 0 22px #6fdc7c); }
.dr.crit .tot, .dr.crit .face { color: #8ff09a; }
.dr.fail .die svg { filter: drop-shadow(0 0 22px #ff5040); }
.dr.fail .tot, .dr.fail .face { color: #ff8a7d; }
.dr .tag { font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.dice-hint { font-size: 12px; color: var(--muted); }

/* ---------- Tagebuch / Quests / NSCs ---------- */
.search { width: 100%; margin-bottom: 8px; }
.li .date { width: 132px; flex: none; font-size: 13px; }
.li .sess { width: 52px; }
.journal-entry textarea { min-height: 120px; color: var(--text); font-size: 14px; line-height: 1.5; }
.li .preview { font-size: 12px; color: var(--muted); padding: 0 4px 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li:not(.closed) .preview { display: none; }
.li.done .head input[data-li=title] { text-decoration: line-through; color: var(--muted); }
.qstat { font-size: 12px; }
.card h2 .mini { font-family: system-ui, sans-serif; font-size: 14px; }

/* ---------- Navigationsleiste unten (iPad/iPhone) ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 4px max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
  background: rgba(27, 23, 21, .94); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.tabs button {
  min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: transparent; border: none; border-radius: 12px; color: var(--muted); padding: 4px 0;
  font-size: 10px; letter-spacing: .01em; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tabs button i { font-style: normal; font-size: 22px; line-height: 1; filter: grayscale(1) opacity(.65); transition: transform .15s, filter .15s; }
.tabs button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabs button.on { color: var(--gold); }
.tabs button.on i { filter: none; transform: translateY(-1px) scale(1.12); }
@media (hover: hover) { .tabs button:hover { color: var(--text); } }

/* iPad & größer: mehr Platz, größere Leiste, Karten in zwei Spalten */
@media (min-width: 700px) {
  :root { --nav-h: 68px; }
  body { max-width: 1180px; }
  .tabs { grid-template-columns: repeat(7, minmax(0, 120px)); justify-content: center; gap: 6px; }
  .tabs button { font-size: 12.5px; }
  .tabs button i { font-size: 25px; }
  .tabs button.on { background: rgba(214, 168, 74, .12); }
  main { padding: 8px 16px; }
  .tab.on { columns: 2; column-gap: 14px; }
  .tab .card { break-inside: avoid; display: inline-block; width: 100%; }
  .top { padding: 10px 16px 0; }
  .hpbar { margin: 0 -16px; }
  #tab-tagebuch.on { columns: 1; max-width: 820px; margin: 0 auto; }
}
@media (min-width: 1100px) {
  .tab.on { columns: 3; }
}
.li .jtitle { font: 700 16px Georgia, serif; color: var(--gold); width: 100%; }

/* ---------- Stufenaufstieg ---------- */
.lvlup { padding: 2px 10px; font-size: 13px; background: #4a3a1a; border-color: var(--gold); color: var(--gold); }
.lvlinfo { font-size: 15px; margin: 4px 0 8px; }
.lvllist { margin: 0; padding-left: 4px; list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.lvllist li { background: var(--panel2); border-radius: 8px; padding: 6px 10px; }
.lvlhp { font-size: 15px; min-height: 1.4em; }
.lvlhp b.good { color: #8ff09a; } .lvlhp b.bad { color: #ff8a7d; }
button:disabled { opacity: .45; cursor: default; }

/* ---------- Dein Zug ---------- */
.econ { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.econ button { font-size: 12px; padding: 10px 2px; border-color: var(--gold); background: #3d3120; white-space: normal; line-height: 1.15; }
.econ button.used { background: transparent; border-color: var(--line); color: var(--muted); text-decoration: line-through; }
.turnopts { display: flex; flex-direction: column; gap: 10px; }
.tsec h4 { margin: 0 0 5px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); }
.tsec.used { opacity: .45; }
.tchips { display: flex; flex-wrap: wrap; gap: 5px; }
.tchip { font-size: 13px; padding: 5px 10px; border-radius: 99px; }
.tchip.atk { background: #4e2622; border-color: var(--red); }
.tchip.spell { background: #23344d; border-color: var(--blue); }
.tchip.own { background: #3d3120; border-color: var(--gold); }
.tchip.std { background: transparent; color: var(--muted); font-size: 12px; }

/* ---------- Begleiter ---------- */
.comp-stats { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 4px; }
.comp-stats .cs { display: flex; align-items: center; gap: 4px; }
.comp-stats .cs button { padding: 2px 9px; }
.minibar { height: 4px; background: #3b2f25; border-radius: 2px; margin: 0 4px 4px; overflow: hidden; }
.minibar > div { height: 100%; background: var(--green); }

/* ---------- Ausrüstung ---------- */
.li .head.sub, .row.sub { flex-wrap: wrap; gap: 6px; padding: 0 4px; }
.li.equipped { box-shadow: inset 3px 0 0 var(--gold); }
label.check.eq { margin: 0; font-size: 13px; }
