:root {
  --bg: #0f1512;
  --surface: #17201c;
  --surface-2: #1e2a24;
  --line: #2c3a32;
  --text: #e8efe9;
  --text-dim: #9db0a4;
  --pitch: #2e7d46;
  --pitch-dark: #256b3b;
  --accent: #38d66b;
  --accent-ink: #06210f;
  --danger: #e5533d;
  --team-a: #e5443b;
  --team-b: #2f6df6;
  --gk: #f4c430;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4em; font-weight: 700; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------- Auth-Seiten --------------------------- */

.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(56, 214, 107, 0.12), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.brand {
  display: flex;
  align-items: center;
  margin-bottom: 22px;
}
.brand img {
  height: 34px;
  width: auto;
  display: block;
}
.brand.center { justify-content: center; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }

.field input {
  width: 100%;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: #26332c; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #45e178; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: rgba(229, 83, 61, 0.12); }
.btn.danger-solid { background: var(--danger); color: #fff; }
.btn.danger-solid:hover { background: #ef6a55; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.block { width: 100%; }

.form-msg {
  min-height: 1.2em;
  margin: 4px 0 14px;
  font-size: 0.9rem;
  color: var(--danger);
}
.form-msg.ok { color: var(--accent); }

.muted { color: var(--text-dim); font-size: 0.9rem; }
.center { text-align: center; }
.mt { margin-top: 16px; }

/* ---------------------------- App-Layout --------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-header .brand { margin: 0; }
.app-header .brand img { height: 28px; }

.header-user { display: flex; align-items: center; gap: 12px; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card .thumb {
  aspect-ratio: 3 / 2;
  background: var(--pitch-dark);
  background-size: cover;
  background-position: center;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
}

.card .card-body { padding: 12px 14px; }
.card .card-title { font-weight: 700; margin-bottom: 2px; }
.card .card-meta { font-size: 0.8rem; color: var(--text-dim); }
.card .card-actions { display: flex; gap: 8px; padding: 0 14px 14px; }
.card .card-actions .btn { padding: 7px 10px; font-size: 0.85rem; }

.card.new {
  align-items: center;
  justify-content: center;
  min-height: 190px;
  border-style: dashed;
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 600;
}
.card.new:hover { color: var(--text); border-color: var(--accent); }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

/* ------------------------------ Editor ---------------------------- */

.editor-body { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
/* Beim Ziehen auf dem Feld keine Text-Markierung */
.stage-wrap, #stage, #stage * { user-select: none; -webkit-user-select: none; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 6px; }
.toolbar .spacer { flex: 1; }

.grid-size-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.grid-size-wrap input {
  width: 46px;
  padding: 7px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}
.grid-size-wrap.off { opacity: 0.4; }

.zoom-label {
  min-width: 44px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.tool-title {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 180px;
}

.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
}
.tbtn:hover { background: #26332c; }
.tbtn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tbtn:disabled { opacity: 0.45; cursor: not-allowed; }

.editor-main { flex: 1; display: flex; min-height: 0; }

.framebar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.framebar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.framebar-speed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.framebar-speed input { width: 90px; }
.anim-scrub { flex: 1; min-width: 120px; max-width: 340px; }
.tbtn.play { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.tbtn.play:hover { background: #45e178; }

.frames { display: flex; gap: 6px; flex-wrap: wrap; }
.frame-chip {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.82rem;
  white-space: nowrap;
}
.frame-chip:hover { background: #26332c; }
.frame-chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }

body.playing .palette,
body.playing .inspector,
body.playing .toolbar .tbtn:not(#saveBtn),
body.playing .toolbar select,
body.playing #frames,
body.playing #addFrameBtn,
body.playing #delFrameBtn {
  pointer-events: none;
  opacity: 0.5;
}

.palette {
  width: 190px;
  padding: 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.palette h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin: 14px 0 8px; }
.palette h3:first-child { margin-top: 0; }

.palette-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.palette-item {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: grab;
  padding: 6px;
}
.palette-item:hover { border-color: var(--accent); }
.palette-item svg { width: 100%; height: 100%; pointer-events: none; }

.stage-wrap {
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: safe center;
  padding: 20px;
  overflow: auto;
  background:
    linear-gradient(var(--bg), var(--bg)) padding-box,
    repeating-linear-gradient(45deg, #131a16 0 10px, #10150f 10px 20px);
}

#stage {
  background: var(--pitch);
  border-radius: 8px;
  box-shadow: var(--shadow);
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
}

.inspector {
  width: 240px;
  padding: 14px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}
.inspector h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.inspector .hint { color: var(--text-dim); font-size: 0.85rem; }
.inspector .field { margin-bottom: 12px; }
.inspector .field label { font-size: 0.8rem; }
.inspector .row { display: flex; gap: 8px; }
.inspector input[type="text"], .inspector select {
  width: 100%;
  padding: 8px 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.inspector input[type="range"] { width: 100%; }
.inspector input[type="color"] { width: 100%; height: 34px; padding: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); color: #ffd7d0; }

/* ------------------------------ Modal --------------------------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 8, 0.6);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 22px 18px;
}
.modal h2 { font-size: 1.1rem; margin: 0 0 8px; }
.modal p { margin: 0 0 18px; color: var(--text-dim); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.modal-choices { display: grid; gap: 8px; margin-bottom: 16px; }
.modal-choice {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.modal-choice:hover:not(:disabled) { border-color: var(--accent); background: #26332c; }
.modal-choice:disabled { opacity: 0.45; cursor: not-allowed; }
.modal-choice .mc-label { font-weight: 700; }
.modal-choice .mc-note { color: var(--text-dim); font-size: 0.85rem; }

@media (max-width: 900px) {
  .palette, .inspector { display: none; }
}

/* ---------------------------- Admin/Einladungen ------------------- */

.invite-form {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin: 18px 0 4px;
}
.invite-form .field { margin-bottom: 0; }
.invite-form input[type="email"] {
  width: 320px;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.invite-form input[type="number"] {
  width: 90px;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.invite-result {
  margin: 14px 0 4px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  max-width: 720px;
}
.link-row { display: flex; gap: 8px; margin-top: 8px; }
.link-row input {
  flex: 1;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.85rem;
}

.table-wrap { overflow-x: auto; margin-top: 12px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 640px; }
.tbl th, .tbl td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.tbl th { color: var(--text-dim); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tbl tr.st-benutzt td, .tbl tr.st-abgelaufen td { color: var(--text-dim); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
}
.badge-offen { background: rgba(56, 214, 107, 0.15); color: var(--accent); border-color: transparent; }
.badge-benutzt { background: var(--surface-2); color: var(--text-dim); }
.badge-abgelaufen { background: rgba(229, 83, 61, 0.15); color: #f0a596; border-color: transparent; }
