:root {
  --bg: #15171c;
  --panel: #1f232b;
  --panel-2: #282d37;
  --border: #343a46;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --accent: #5fbf4a;
  --accent-2: #4aa339;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* --- Icons --- */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  vertical-align: -0.2em;
}
.icon-xl { width: 48px; height: 48px; }
.logo { width: 28px; height: 28px; flex: none; image-rendering: pixelated; border-radius: 3px; }
.logo-sm { width: 16px; height: 16px; border-radius: 2px; vertical-align: -3px; }

/* --- Kopfzeile --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 18px;
  font-weight: 500;
  white-space: nowrap;
}
.brand strong { color: var(--accent); font-weight: 700; }
.brand:hover .logo { transform: rotate(-8deg) scale(1.05); }
.brand .logo { transition: transform .15s; }
.crumb-back { display: none; }
.crumb {
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb:not(:empty)::before { content: "/ "; }

.view {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}
.view[hidden] { display: none; }

.page-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 16px;
  font-size: 20px;
  font-weight: 600;
}
.page-title .icon { color: var(--accent); }

/* --- Galerie --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.tile {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.tile:hover, .tile:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  outline: none;
}
.tile .thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000 center / cover no-repeat;
  image-rendering: pixelated;
}
.tile .thumb.none {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.tile .thumb.none .icon { width: 32px; height: 32px; }
.tile .play-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .35);
  opacity: 0;
  transition: opacity .15s;
}
.tile .play-overlay span {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-2);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.tile .play-overlay .icon { width: 22px; height: 22px; margin-left: 3px; }
.tile:hover .play-overlay, .tile:focus-visible .play-overlay { opacity: 1; }
.tile .meta { padding: 10px 12px; display: grid; gap: 4px; }
.tile .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .facts { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 13px; }
.tile .facts span { display: inline-flex; align-items: center; gap: 5px; }

.empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  padding: 48px 16px;
}
.empty[hidden] { display: none; }
.empty p { margin: 0; }

/* --- Player --- */
.stage {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  min-height: 200px;
  overflow: hidden;
}
#canvas {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  height: auto;
}
/* Vollbild-Button in der Bildecke */
.stage-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(20, 22, 27, .55);
  border-color: rgba(255, 255, 255, .14);
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background .12s, border-color .12s, opacity .25s;
}
.stage-btn:hover { background: rgba(20, 22, 27, .8); }

/* Steuerleiste im Vollbild */
.fs-bar { display: none; }

.stage.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  border-radius: 0;
}
.stage.is-fullscreen #canvas {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
}
.stage.is-fullscreen .stage-btn {
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 46px;
  height: 46px;
}
.stage.is-fullscreen .fs-bar {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(760px, calc(100% - 32px));
  padding: 8px 12px;
  background: rgba(20, 22, 27, .7);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity .25s, transform .25s;
}
.fs-bar .icon-btn { height: 40px; background: transparent; border-color: transparent; color: #fff; }
.fs-bar .icon-btn.primary { background: var(--accent-2); border-color: var(--accent-2); }
.fs-bar input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 32px; }
.fs-info {
  min-width: 64px;
  text-align: right;
  font-size: 13px;
  color: #d5d9e0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Nach Inaktivität ausblenden */
.stage.is-fullscreen.idle { cursor: none; }
.stage.is-fullscreen.idle .stage-btn { opacity: 0; pointer-events: none; }
.stage.is-fullscreen.idle .fs-bar {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
}

/* Fallback-Vollbild (ohne Fullscreen-API): Seite nicht mitscrollen */
body.fs-lock { overflow: hidden; }

.loading {
  position: absolute; inset: 0;
  z-index: 2;
  display: grid; place-content: center; gap: 10px;
  padding: 16px;
  background: rgba(0, 0, 0, .7);
}
.loading[hidden] { display: none; }
.loading-text { text-align: center; }
.bar { width: min(260px, 70vw); height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
#loading-bar { height: 100%; width: 0; background: var(--accent); transition: width .1s; }

.controls {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 12px;
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row input[type=range] { flex: 1; min-width: 140px; accent-color: var(--accent); height: 24px; }
.lbl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 92px;
  color: var(--muted);
  font-size: 13px;
}
.lbl .icon { color: var(--accent); }
.frame-info {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
button:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.primary:hover { background: var(--accent); }
button.ghost { background: transparent; }

.btn-group { display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 36px; padding: 0; }
.icon-btn.primary { width: 52px; }
.icon-btn .icon { width: 18px; height: 18px; }

.presets-row { align-items: flex-start; }
.presets-row .lbl { padding-top: 7px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.presets button { min-width: 46px; font-variant-numeric: tabular-nums; }
.presets button.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

#fps-input {
  width: 80px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}

/* --- Fußzeile --- */
.footer {
  margin-top: 24px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 24px;
  font-size: 14px;
  color: var(--muted);
}
.footer-copy { display: inline-flex; align-items: center; gap: 8px; }
.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-weight: 500;
}
.footer-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 0;
}
.footer-links a:hover { color: var(--text); text-decoration: underline; }

/* --- Responsive --- */

/* Tablet */
@media (max-width: 1024px) {
  .view { padding: 16px; }
  #canvas { max-height: 62vh; max-height: 62svh; }
}

/* Touch-Geräte: größere Tippflächen, keine Hover-Effekte */
@media (pointer: coarse) {
  .icon-btn { width: 48px; height: 44px; }
  .icon-btn.primary { width: 60px; }
  button { min-height: 40px; }
  .row input[type=range] { height: 36px; }
  #fps-input { padding: 9px 8px; font-size: 16px; } /* 16px verhindert iOS-Zoom */
  .presets button { min-width: 52px; }
  .footer-links a { padding: 8px 0; }
  .stage.is-fullscreen .fs-bar .icon-btn { width: 48px; height: 46px; }
}
@media (hover: none) {
  .tile:hover { transform: none; box-shadow: none; border-color: var(--border); }
  .tile .play-overlay { opacity: 1; background: linear-gradient(transparent 55%, rgba(0, 0, 0, .45)); place-items: end; padding: 10px; }
  .tile .play-overlay span { width: 40px; height: 40px; }
  .tile .play-overlay .icon { width: 18px; height: 18px; margin-left: 2px; }
}
@media (max-width: 760px) {
  .lbl { width: 76px; }
  .btn-label { display: none; }
  #btn-reload { width: 40px; height: 36px; padding: 0; }
}

@media (max-width: 600px) {
  body { font-size: 14px; }
  .topbar { gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .view { padding: 12px 16px; }
  .page-title { font-size: 18px; margin-bottom: 12px; }

  /* Im Player: Logo + Zurück-Pfeil + Projektname statt vollem Titel */
  body.in-player .brand-text { display: none; }
  body.in-player .crumb-back {
    display: inline-flex;
    align-items: center;
    color: var(--text);
    padding: 4px;
  }
  body.in-player .crumb::before { content: none; }
  .brand { font-size: 16px; }
  .brand-text { overflow: hidden; text-overflow: ellipsis; }

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

  /* Player randlos bis zum Bildschirmrand */
  #view-player { padding: 0 0 12px; }
  .stage-btn { top: 8px; right: 8px; }
  .stage.is-fullscreen .fs-bar { padding: 6px 8px; gap: 4px; width: calc(100% - 20px); }
  .fs-info { min-width: 0; font-size: 12px; }
  .stage { border-radius: 0; border-left: 0; border-right: 0; min-height: 160px; }
  #canvas { max-height: 55vh; max-height: 55svh; }
  .controls { margin: 12px 16px 0; padding: 12px; }

  /* Transport: Buttons über volle Breite, Frame-Info darunter */
  .transport .btn-group { flex: 1; }
  .transport .icon-btn { flex: 1; height: 44px; }
  .transport .icon-btn.primary { flex: 1.4; }
  #btn-reload { height: 44px; width: 44px; }
  .frame-info { order: 3; flex-basis: 100%; margin-left: 0; font-size: 13px; }

  .row { gap: 8px; }
  .lbl { width: 100%; }
  .presets-row .lbl { padding-top: 0; }
  .row input[type=range] { min-width: 0; height: 32px; }
  #fps-input { width: 72px; }

  .presets { display: grid; grid-template-columns: repeat(4, 1fr); }
  .presets button { min-width: 0; height: 40px; }

  .footer-inner { flex-direction: column; align-items: flex-start; padding: 16px; }
}

@media (max-width: 360px) {
  .grid { grid-template-columns: 1fr; }
}

/* Querformat auf dem Handy: möglichst viel Bild */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { position: static; }
  #canvas { max-height: 80vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
