:root {
  --bg: #f3efe6;
  --paper: #fffdf8;
  --ink: #2b2620;
  --muted: #7a6f62;
  --line: #e2d9c9;
  --accent: #b5562b;
  --accent-2: #4f7a4a;
  --warn: #c98a12;
  --bad: #a33a2b;
  --good: #3e7b46;
  --learn: #2f6690;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { font-size: 14px; line-height: 1.45; }
button, input, select { font: inherit; }
.hidden { display: none !important; }
.small { font-size: 12px; color: var(--muted); }

/* ---------- Buttons */
.btn { border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: #c9bca6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #9d4822; }
.btn.green { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }

/* ---------- Login */
.login { max-width: 1050px; margin: 0 auto; padding: 48px 24px; display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; }
.login h1 { font-size: 54px; margin: 0 0 8px; letter-spacing: -1px; color: var(--accent); font-family: Georgia, "Times New Roman", serif; }
.login .lead { font-size: 19px; }
.login-forms { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: var(--bg); padding: 9px; border-radius: 8px; cursor: pointer; }
.tab.active { background: var(--accent); color: #fff; }
.form label { display: block; margin-bottom: 12px; font-weight: 600; }
.form input:not([type=radio]) { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.worlds { border: 0; padding: 0; margin: 0 0 14px; }
.worlds legend { font-weight: 600; margin-bottom: 6px; }
.world-card { display: flex !important; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px !important; font-weight: 400 !important; cursor: pointer; }
.world-card:has(input:checked) { border-color: var(--accent); background: #fbf1e9; }
.wc-body { display: flex; flex-direction: column; gap: 2px; }
.wc-body span { font-size: 13px; color: var(--muted); }
.diff { font-style: normal; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #e9e2d4; margin-left: 4px; }
.diff-mittel { background: #f3e0b8; } .diff-schwer { background: #f2c9bd; }
.msg { color: var(--bad); min-height: 1.4em; }

/* ---------- Spiel */
body.in-game { display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 14px; background: #2f2a24; color: #f3ece0; flex-wrap: wrap; }
.brand { font-family: Georgia, serif; font-size: 20px; color: #f0b48c; }
.brand span { font-family: inherit; font-size: 13px; color: #cfc4b2; margin-left: 6px; }
.clock strong { font-size: 18px; margin: 0 4px; }
.res { display: flex; gap: 14px; }
.speed { display: flex; gap: 3px; }
.speed button { border: 1px solid #5b5248; background: transparent; color: #f3ece0; border-radius: 6px; padding: 2px 8px; cursor: pointer; }
.speed button.on { background: #f0b48c; color: #2f2a24; border-color: #f0b48c; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user .btn { color: #f3ece0; }

.game { flex: 1; display: flex; min-height: 0; }
.mapwrap { flex: 1; position: relative; min-width: 0; background: #3a352e; }
#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#map.placing { cursor: crosshair; }
.zoom { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid rgba(0,0,0,.2); background: rgba(255,253,248,.92); font-size: 18px; cursor: pointer; }
.legend { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: #efe7da; background: rgba(0,0,0,.35); padding: 3px 8px; border-radius: 6px; pointer-events: none; }
.mode { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 7px 14px; border-radius: 20px; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.mode button { margin-left: 8px; }
.hover { position: absolute; pointer-events: none; background: rgba(43,38,32,.92); color: #fff; padding: 5px 9px; border-radius: 7px; font-size: 12px; max-width: 240px; }

.side { width: 380px; display: flex; flex-direction: column; background: var(--paper); border-left: 1px solid var(--line); min-height: 0; }
.sidetabs { display: flex; border-bottom: 1px solid var(--line); }
.sidetabs button { flex: 1; border: 0; background: transparent; padding: 10px 2px; cursor: pointer; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; position: relative; }
.sidetabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.sidetabs .dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
.panel { flex: 1; overflow-y: auto; padding: 14px; }
.panel h3 { margin: 4px 0 8px; font-size: 15px; }
.panel h4 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.box { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; background: #fff; }
.box.alert { border-color: #e6b7ab; background: #fbefeb; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.num { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.num button { border: 0; background: var(--bg); width: 26px; height: 28px; cursor: pointer; }
.num input { width: 40px; border: 0; text-align: center; height: 28px; }
.feedrow { display: flex; align-items: center; justify-content: space-between; margin: 6px 0; }
.bar { height: 7px; border-radius: 4px; background: #eee6d8; overflow: hidden; margin-top: 3px; }
.bar i { display: block; height: 100%; background: var(--accent-2); }
select { padding: 6px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }

.catrow { display: flex; align-items: center; gap: 9px; padding: 7px 4px; border-bottom: 1px solid #f0e9dd; cursor: pointer; }
.catrow:hover { background: #faf5ec; }
.catrow .sw { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.15); }
.catrow .nm { font-weight: 600; }
.catrow .sub { font-size: 12px; color: var(--muted); }
.catrow.dead { opacity: .55; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px; background: #efe8db; margin: 1px 2px 1px 0; }
.tag.bad { background: #f6d9d2; color: var(--bad); }
.tag.good { background: #d9ecd9; color: var(--good); }

.log-item { padding: 7px 0 7px 10px; border-left: 3px solid var(--line); margin-bottom: 6px; }
.log-item .d { font-size: 11px; color: var(--muted); }
.log-item.good { border-color: var(--good); }
.log-item.warn { border-color: var(--warn); }
.log-item.bad { border-color: var(--bad); }
.log-item.learn { border-color: var(--learn); background: #eef4f9; border-radius: 0 8px 8px 0; padding-right: 8px; }
.log-item.learn::before { content: "Wusstest du? "; font-weight: 700; color: var(--learn); }
.log-item[data-cat] { cursor: pointer; }

.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 11px; color: var(--muted); }
#chart { width: 100%; height: 190px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.chartlegend { display: flex; gap: 12px; font-size: 12px; margin: 4px 0 10px; flex-wrap: wrap; }
.chartlegend i { display: inline-block; width: 12px; height: 3px; vertical-align: middle; margin-right: 4px; }

/* ---------- Modal (Katzenkarte, Tierarzt) */
.modal { position: fixed; inset: 0; background: rgba(30,25,20,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--paper); border-radius: 14px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto; position: relative; padding: 20px 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal .close { position: absolute; top: 8px; right: 12px; border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--muted); }
.card-head { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.card-head canvas { flex: none; background: #f1ead9; border-radius: 12px; }
.card-head h2 { margin: 0; font-family: Georgia, serif; }
.vetlist label { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid #f0e9dd; }
.vetlist label span { margin-left: auto; color: var(--muted); }
.report { background: #f4f8f1; border: 1px solid #cfe1c9; border-radius: 10px; padding: 10px; margin-top: 10px; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 60; align-items: center; }
.toast { background: #2f2a24; color: #fff; padding: 9px 14px; border-radius: 9px; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 520px; animation: pop .2s ease-out; }
.toast.err { background: var(--bad); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; padding: 24px 16px; gap: 20px; }
  .login h1 { font-size: 40px; }
  body.in-game { overflow: auto; height: auto; }
  .game { flex-direction: column; }
  .mapwrap { height: max(320px, 72vw); max-height: 70vh; flex: none; }
  .legend { display: none; }
  .side { width: 100%; border-left: 0; min-height: 60vh; }
  .topbar { gap: 10px; font-size: 13px; }
  .user { margin-left: 0; }
}

/* ---------- Fotoszene */
.viewtabs { position: absolute; top: 10px; left: 10px; z-index: 5; display: flex; background: rgba(20,16,12,.7); border-radius: 9px; padding: 3px; }
.viewtabs button { border: 0; background: transparent; color: #f3ece0; padding: 5px 11px; border-radius: 7px; cursor: pointer; }
.viewtabs button.on { background: #f0b48c; color: #2f2a24; }
.scene3d { position: absolute; inset: 0; background: #0f0d0b; overflow: hidden; }
.scene3d .stage { position: absolute; overflow: hidden; }
.scene3d .stage img, .scene3d .stage canvas, .scene3d .stage .tint, .scene3d .stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene3d .stage img { user-select: none; -webkit-user-drag: none; }
.scene3d .tint { background: #0b1640; mix-blend-mode: multiply; opacity: 0; pointer-events: none; }
.scene3d .weather { pointer-events: none; }
.scene3d svg { pointer-events: none; }
.scene3d svg .walk { fill: rgba(0,229,255,.08); stroke: #00e5ff; stroke-width: 2; stroke-dasharray: 8 6; }
.scene3d svg .puddle { fill: rgba(80,160,255,.25); stroke: #4fa3ff; stroke-width: 2; }
.scene3d svg .horizon { stroke: #ffd60a; stroke-width: 1.5; stroke-dasharray: 10 6; }
.scene3d .s-hud { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; z-index: 4; }
.scene3d .s-hud button { background: rgba(255,253,248,.92); border: 1px solid rgba(0,0,0,.2); border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.scene3d .s-hint { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: #efe7da; background: rgba(0,0,0,.4); padding: 3px 8px; border-radius: 6px; pointer-events: none; }
.scene3d .s-label { position: absolute; transform: translate(-50%, -100%); font-size: 11px; background: rgba(0,0,0,.55); color: #fff; padding: 1px 6px; border-radius: 6px; pointer-events: none; white-space: nowrap; }
.scene3d .s-none { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #cfc4b2; }
.avatar-dlg img { max-height: 160px; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0/16px 16px; border-radius: 8px; }

/* ---------- Szenen-Filme */
.scene3d .stage .s-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s; pointer-events: none; }
.scene3d .stage .s-video.on { opacity: 1; }
.scene3d .s-caption { display: none; position: absolute; left: 50%; bottom: 34px; transform: translateX(-50%); background: rgba(20,16,12,.72); color: #f3ece0; padding: 5px 12px; border-radius: 16px; font-size: 13px; white-space: nowrap; }
.scene3d.video-mode .s-caption { display: block; }
.scene3d.video-mode .s-label, .scene3d.video-mode [data-a=avatar], .scene3d.video-mode [data-a=debug] { display: none !important; }
.scene3d.video-mode .s-hint { visibility: hidden; }
