:root {
  --bg: #0a0d12;
  --panel: #131820;
  --panel-raised: #1a202a;
  --field: #0f141b;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e9edf3;
  --text-soft: #9ba7b9;
  --text-faint: #6c778a;
  --blue: #2f6ae0;
  --blue-deep: #1f50b8;
  --red: #e1343f;
  --green: #2fb36d;
  --amber: #e2a43b;
  --radius: 14px;
  --shadow-lg: 0 30px 70px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 10px 24px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(60rem 30rem at 0% -10%, rgba(47, 106, 224, 0.16), transparent 60%),
    radial-gradient(50rem 28rem at 100% -10%, rgba(225, 52, 63, 0.12), transparent 60%),
    var(--bg);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "League Spartan", "Segoe UI", sans-serif;
  font-weight: 700;
  letter-spacing: 0.01em;
}

code {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.85em;
  padding: 0.05rem 0.3rem;
  border-radius: 0.3rem;
  background: rgba(255, 255, 255, 0.08);
}

[hidden] {
  display: none !important;
}

/* Öffentlicher Modus (Strato): nur ansehen und herunterladen. */
.read-only [data-edit-only] {
  display: none !important;
}

/* ---------- Kopfzeile ---------- */

.topbar {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.4rem 1.5rem 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.brand-logo {
  width: 3rem;
  height: 3rem;
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5));
}

.brand h1 {
  font-size: clamp(1.5rem, 2.6vw, 2rem);
  line-height: 1;
  text-transform: uppercase;
}

.brand-sub {
  margin: 0.3rem 0 0;
  color: var(--text-soft);
  font-size: 0.92rem;
}

.icon-btn {
  flex: none;
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text);
  background: var(--panel-raised);
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.icon-btn svg {
  width: 1.3rem;
  height: 1.3rem;
  fill: currentColor;
}

.icon-btn:hover {
  background: #232b37;
  transform: rotate(20deg);
}

.icon-btn.ghost {
  width: 2.2rem;
  height: 2.2rem;
  border-color: transparent;
  background: transparent;
  font-size: 1rem;
}

.icon-btn.ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: none;
}

/* ---------- Layout ---------- */

.studio {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2.5rem;
  display: grid;
  grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 40%), var(--panel);
  box-shadow: var(--shadow-sm);
}

.controls {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.preview {
  position: sticky;
  top: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.section-head {
  margin-top: 0.6rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.section-head h2 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
}

/* ---------- Umschalter ---------- */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--field);
}

.seg-btn {
  border: 0;
  border-radius: 999px;
  padding: 0.6rem 0.9rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
  background: transparent;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease;
}

.seg-btn:hover:not(.active) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.seg-btn.active {
  color: #fff;
  background: linear-gradient(160deg, var(--blue), var(--blue-deep));
  box-shadow: 0 8px 18px rgba(31, 80, 184, 0.35);
}

.segmented.small .seg-btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
}

.preview-head {
  display: flex;
  justify-content: center;
}

.preview-head .segmented {
  width: min(100%, 26rem);
}

/* ---------- Spielliste ---------- */

.game-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 19rem;
  overflow-y: auto;
  padding-right: 0.15rem;
  scrollbar-width: thin;
}

.game-item {
  width: 100%;
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 0.8rem;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.game-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.game-item[aria-checked="true"] {
  border-color: rgba(47, 106, 224, 0.75);
  background: rgba(47, 106, 224, 0.14);
}

.game-logo {
  width: 2.4rem;
  height: 2.4rem;
  object-fit: contain;
}

.game-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.game-opponent {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-meta {
  font-size: 0.82rem;
  color: var(--text-soft);
}

.game-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.07);
  white-space: nowrap;
}

.game-badge.home {
  color: #cfe0ff;
  background: rgba(47, 106, 224, 0.25);
}

.game-badge.win {
  color: #d4f5e2;
  background: rgba(47, 179, 109, 0.3);
}

.game-badge.loss {
  color: #ffd9dc;
  background: rgba(225, 52, 63, 0.3);
}

.game-badge.draw {
  color: #fbeccd;
  background: rgba(226, 164, 59, 0.28);
}

.list-message {
  margin: 0;
  padding: 0.9rem;
  border-radius: 0.8rem;
  border: 1px dashed var(--line-strong);
  color: var(--text-soft);
  font-size: 0.9rem;
}

.list-message.error {
  border-color: rgba(225, 52, 63, 0.5);
  color: #ffc9cd;
}

/* ---------- Editor ---------- */

.editor {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.field-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-soft);
}

.field-row {
  display: flex;
  gap: 0.35rem;
}

input[type="text"],
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 0.65rem;
  padding: 0.6rem 0.7rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--field);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
  resize: vertical;
  min-height: 6.2rem;
  font-size: 0.88rem;
  line-height: 1.45;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: rgba(47, 106, 224, 0.8);
  box-shadow: 0 0 0 3px rgba(47, 106, 224, 0.22);
}

input:disabled {
  opacity: 0.55;
}

.reset-btn {
  flex: none;
  width: 2.4rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.65rem;
  font-size: 1.05rem;
  color: var(--text-soft);
  background: transparent;
  cursor: pointer;
}

.reset-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.result-fields {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: -0.35rem;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-soft);
}

.hint.warning {
  color: #f1c27a;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.score-row input {
  width: 4.2rem;
  text-align: center;
  font-family: "League Spartan", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-faint);
}

.hint:empty {
  display: none;
}

.hint .remembered {
  color: #9ec0ff;
}

.editor-note {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--text-faint);
}

.csv-export {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.csv-export + .hint a {
  color: #9ec0ff;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.75rem;
  padding: 0.75rem 1.1rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-raised);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.btn svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: currentColor;
}

.btn:hover:not(:disabled) {
  background: #232b37;
  transform: translateY(-1px);
}

.btn.primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(160deg, var(--blue), var(--blue-deep));
  box-shadow: 0 12px 24px rgba(31, 80, 184, 0.35);
}

.btn.primary:hover:not(:disabled) {
  background: linear-gradient(160deg, #3b76ec, #2459c7);
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 0.55rem 0.8rem;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.is-busy {
  cursor: progress;
}

.text-btn {
  border: 0;
  padding: 0.2rem 0.3rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: #9ec0ff;
  background: transparent;
  cursor: pointer;
}

.text-btn:hover {
  text-decoration: underline;
}

.file-btn {
  position: relative;
  overflow: hidden;
  align-self: flex-start;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------- Vorschau ---------- */

.canvas-stage {
  display: grid;
  place-items: center;
  padding: 1.1rem;
  border-radius: 0.9rem;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.04), transparent 70%),
    repeating-conic-gradient(#121820 0% 25%, #0e131a 0% 50%) 0 0 / 22px 22px;
}

.canvas-frame {
  --ratio: 1;
  position: relative;
  width: min(100%, max(18rem, calc((100vh - 15.5rem) * var(--ratio))));
  aspect-ratio: var(--ratio);
  border-radius: 0.4rem;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: #0e1218;
}

.canvas-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem;
  text-align: center;
  color: var(--text-soft);
  background: rgba(10, 13, 18, 0.72);
  backdrop-filter: blur(2px);
  transition: opacity 200ms ease;
}

.preview-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 0.6rem;
}

.status {
  margin: 0;
  min-height: 1.3rem;
  font-size: 0.88rem;
  color: var(--text-soft);
  text-align: center;
}

.status.success {
  color: #8fe0b4;
}

.status.error {
  color: #ff9ea5;
}

/* ---------- Einstellungen ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(4px);
  animation: fadeIn 160ms ease;
}

.modal.is-hidden {
  display: none;
}

.modal-card {
  width: min(680px, 100%);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1.2rem 1.3rem 1.3rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  animation: popIn 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-size: 1.4rem;
}

.settings-block {
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.settings-block h3 {
  font-size: 1.05rem;
}

.optional {
  margin-left: 0.3rem;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-faint);
}

.asset-preview {
  display: grid;
  place-items: center;
  min-height: 4rem;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
}

.sponsor-preview {
  background: #fff;
}

.sponsor-preview .hint {
  color: #5c6676;
}

.background-preview {
  background: var(--field);
}

.asset-preview img {
  display: block;
  max-width: 100%;
  max-height: 12rem;
  object-fit: contain;
}

.label-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.label-list li {
  display: grid;
  grid-template-columns: 4.2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.86rem;
}

.label-kind {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.label-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-soft);
}

.label-text strong {
  color: var(--text);
  font-weight: 600;
}

.label-list .empty {
  display: block;
  color: var(--text-faint);
  background: none;
  padding: 0;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (max-width: 920px) {
  .studio {
    grid-template-columns: minmax(0, 1fr);
  }

  .preview {
    position: static;
    order: -1;
  }

  .canvas-frame {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar,
  .studio {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .actions,
  .csv-export,
  .field-pair {
    grid-template-columns: minmax(0, 1fr);
  }

  .canvas-stage {
    padding: 0.6rem;
  }

  .brand-sub {
    display: none;
  }
}
