/* Gemeinsame Styles für Menü (index.html) und Spiel (play.html) */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #07051a;
  color: #e8e6ff;
  font: 15px/1.4 "Trebuchet MS", system-ui, sans-serif;
}

a { color: #5ef2d6; }

.link-btn {
  font: inherit;
  color: #5ef2d6;
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  text-decoration: none;
}
.link-btn:hover, .link-btn:focus { text-decoration: underline; }
.link-btn:focus { outline: 2px solid #5ef2d6; outline-offset: 2px; border-radius: 4px; }

.play-btn {
  display: inline-block;
  font: inherit;
  font-weight: bold;
  color: #0d0b2e;
  background: #5ef2d6;
  border: none;
  border-radius: 8px;
  padding: 12px 28px;
  cursor: pointer;
  text-decoration: none;
}
.play-btn:hover, .play-btn:focus { background: #8ff7e4; outline: 2px solid #fff; outline-offset: 2px; }
.play-btn:disabled { opacity: 0.6; cursor: wait; }
.play-btn[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #1a1540;
  border: 1px solid #5ef2d6;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  animation: toast 3s ease forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; }
}

.pad-hint { color: #9a93c9; font-size: 13px; margin: 12px 0 0; }

.account { color: #9a93c9; font-size: 14px; white-space: nowrap; }
.account-name { color: #e8e6ff; }
.menu-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.owner { color: #9a93c9; }
.finish-login p { color: #9a93c9; margin: 0 0 12px; }
.finish-login[hidden], .finish-save[hidden], .finish-off[hidden] { display: none; }

.note { color: #9a93c9; grid-column: 1 / -1; }
.note.error { color: #ff7a9c; }
.note:empty { display: none; }

/* ---------- Spielseite ---------- */
body.play-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
#game {
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  border-radius: 8px;
  box-shadow: 0 0 40px rgba(94, 242, 214, 0.15);
}
.back-link {
  position: fixed;
  top: 10px;
  left: 16px;
  z-index: 5;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(13, 11, 46, 0.6);
  opacity: 0.75;
  text-decoration: none;
}
.back-link:hover, .back-link:focus-visible { opacity: 1; }
.back-link[hidden] { display: none; }

.load-error {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: rgba(7, 5, 26, 0.85);
}
.load-error[hidden] { display: none; }
.load-error p { color: #ff7a9c; margin: 0; }

.touch {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  justify-content: space-between;
  pointer-events: none;
}
.touch div { display: flex; gap: 12px; }
.touch button {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 24px;
  user-select: none;
}
@media (pointer: coarse) { .touch { display: flex; } }

/* Ziel erreicht */
.finish {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.finish[hidden] { display: none; }
.finish-box {
  width: min(400px, 100%);
  padding: 24px;
  text-align: center;
  background: #1a1540;
  border: 1px solid #5ef2d6;
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(94, 242, 214, 0.25);
}
.finish-box h2 { margin: 0; color: #7fffe4; }
.finish-time { margin: 8px 0 0; font-size: 40px; font-weight: bold; color: #ffd84a; font-variant-numeric: tabular-nums; }
.finish-score { margin: 0 0 18px; color: #9a93c9; }
.finish-box label { display: block; margin-bottom: 6px; color: #9a93c9; }
.finish-row { display: flex; gap: 8px; }
.finish-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: inherit;
  background: #0d0b2e;
  border: 1px solid #2e2660;
  border-radius: 8px;
  padding: 10px 12px;
}
.finish-row input:focus { outline: none; border-color: #5ef2d6; }
.finish-row .play-btn { padding: 10px 16px; }
.finish-links { display: flex; justify-content: space-between; margin-top: 12px; }

/* ---------- Menüseite ---------- */
body.menu-page {
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #3a2463 0%, #0d0b2e 70%) fixed, #0d0b2e;
}
.menu-box {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 16px;
}
.menu-box h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 44px);
  color: #5ef2d6;
  text-shadow: 0 0 24px rgba(94, 242, 214, 0.4);
}
.hint { margin: 6px 0 20px; color: #9a93c9; }
.menu-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}
#search {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: inherit;
  background: rgba(13, 11, 46, 0.8);
  border: 1px solid #2e2660;
  border-radius: 8px;
  padding: 10px 14px;
}
#search:focus { outline: none; border-color: #5ef2d6; }
.menu-bar a { white-space: nowrap; }

.level-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.level-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  color: inherit;
  text-decoration: none;
  background: #1a1540;
  border: 1px solid #2e2660;
  border-radius: 10px;
  transition: transform 0.1s, border-color 0.1s;
}
/* :focus (nicht nur :focus-visible), damit auch die Auswahl per Controller sichtbar ist */
.level-card:hover, .level-card:focus {
  outline: none;
  border-color: #5ef2d6;
  transform: translateY(-2px);
}
.level-card canvas {
  width: 100%;
  image-rendering: pixelated;
  border-radius: 6px;
  margin-bottom: 4px;
}
.level-card strong { font-size: 16px; }
.level-card .meta { color: #9a93c9; font-size: 13px; }
.level-card .best { color: #ffd84a; font-size: 13px; }

/* Level-Seite */
.detail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; margin: 12px 0 8px; }
.detail-head h2 { margin: 0; font-size: clamp(24px, 5vw, 34px); color: #5ef2d6; }
.level-id { color: #9a93c9; font-family: ui-monospace, Consolas, monospace; }
.notice {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(255, 216, 74, 0.12);
  border: 1px solid rgba(255, 216, 74, 0.4);
  color: #ffd84a;
}
.notice[hidden] { display: none; }
.level-desc { margin: 0 0 14px; color: #c9c4ee; white-space: pre-line; }
.level-desc[hidden] { display: none; }
.preview {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid #2e2660;
  background: #2a1d55;
}
.preview:empty { display: none; }
.preview canvas { display: block; image-rendering: pixelated; }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.stat {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  background: #1a1540;
  border: 1px solid #2e2660;
  border-radius: 8px;
}
.stat-value { font-size: 20px; font-weight: bold; font-variant-numeric: tabular-nums; }
.stat-label { color: #9a93c9; font-size: 13px; }
#detailView h3 { margin: 28px 0 10px; }
.times { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.times th { text-align: left; color: #9a93c9; font-weight: normal; font-size: 13px; padding: 6px 8px; border-bottom: 1px solid #2e2660; }
.times td { padding: 8px; border-bottom: 1px solid #1f1950; overflow-wrap: anywhere; }
.times .rank { color: #9a93c9; width: 2em; }
.times .time { color: #ffd84a; font-weight: bold; }
.times tr:nth-child(1) .rank { color: #ffd84a; }
.times tr.mine td { background: rgba(94, 242, 214, 0.12); }
@media (max-width: 520px) { .times .date, .times th:last-child { display: none; } }
