:root {
  --bg: #0e0f13;
  --panel: #181a21;
  --line: #2a2d38;
  --text: #f3f3f5;
  --muted: #9a9cab;
  --accent: #ffd400;
  --accent-text: #111;
  --hit: #e0174f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 8px;
}
.avatar {
  width: 72px;
  height: 72px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  object-position: 25% 30%;
  border: 3px solid var(--accent);
}
h1 { margin: 0; font-size: 1.8rem; letter-spacing: -0.02em; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
.sub, .muted { color: var(--muted); margin: 4px 0 0; }
.small { font-size: 0.85rem; }
#logout { margin-left: auto; }

/* minmax(0, 1fr) überall: sonst bläst min-content (lange Wörter, nowrap) das Layout auf. */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-width: 0; }

.banner { margin: 0; padding: 10px 14px; border-radius: 10px; background: #3a2a00; color: var(--accent); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 12px; background: var(--bg); }
.tabs button { background: transparent; color: var(--muted); padding: 10px 8px; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }

form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 12px; }
input {
  font: inherit;
  font-size: 16px; /* verhindert Auto-Zoom auf iOS */
  width: 100%;
  min-width: 0;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

button {
  font: inherit;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 8px 12px; }
.error { color: #ff6b8e; min-height: 1.2em; margin: 0; }
.error button { all: unset; color: var(--accent); text-decoration: underline; cursor: pointer; }

#game { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; min-width: 0; }
.stats strong { display: block; font-size: 1.4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats span { color: var(--muted); font-size: 0.8rem; }

.card { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.cell {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  padding: 4px;
  font-size: clamp(0.65rem, 2.8vw, 0.85rem);
  font-weight: 500;
  line-height: 1.15;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  hyphens: auto;
  overflow-wrap: anywhere;
  touch-action: manipulation;
  transition: transform 0.1s, background 0.15s;
}
.cell:active { transform: scale(0.95); }
.cell[aria-busy="true"] { opacity: 0.55; }
.cell.marked { background: var(--hit); border-color: var(--hit); color: #fff; }
.cell .when { font-size: 0.85em; font-weight: 700; white-space: nowrap; }
.cell.win { border: 3px solid var(--accent); box-shadow: 0 0 10px rgba(255, 212, 0, 0.45); }
.cell.pulse { animation: pulse 0.9s ease 2; }
.cell.free {
  background: url(img/leo.jpg) 25% 30% / cover;
  border: 2px solid var(--accent);
  cursor: default;
}
.hint { text-align: center; font-size: 0.85rem; margin: 0; }

@keyframes pulse { 50% { transform: scale(1.08); } }

summary { cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary h2 { display: inline; }
summary::after { content: " ▾"; color: var(--muted); }
details[open] summary::after { content: " ▴"; }
details[open] summary { margin-bottom: 12px; }

.history { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.history h3 { margin: 0 0 6px; font-size: 0.85rem; color: var(--accent); font-weight: 600; }
.history ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.history li { display: flex; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--bg); min-width: 0; }
.history time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.history span { min-width: 0; overflow-wrap: anywhere; }

.board { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.board li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); min-width: 0; }
.board .pos { width: 1.8em; flex: none; color: var(--muted); font-weight: 700; }
.board .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .who small { display: block; color: var(--muted); font-size: 0.75rem; }
.board .me { outline: 1px solid var(--accent); }
.board .nums { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.board .nums b { color: var(--accent); }
.board .gap { background: none; justify-content: center; color: var(--muted); padding: 0; }

.toast {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.65);
  animation: pop 2.6s ease forwards;
  pointer-events: none;
  z-index: 10;
}
.toast strong { font-size: 4rem; font-weight: 900; color: var(--accent); }
.toast span { font-size: 1.2rem; }
.toast.error { place-content: end center; background: none; padding-bottom: 32px; animation-duration: 3.5s; }
.toast.error strong { font-size: 1rem; padding: 12px 16px; border-radius: 10px; background: var(--hit); color: #fff; }
@keyframes pop {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.1); }
  85% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; }
}

@media (max-width: 480px) {
  main { padding-inline: 10px; }
  .hero { padding-inline: 10px; }
  .card { gap: 4px; }
  .cell { padding: 3px; aspect-ratio: 4 / 5; border-radius: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation-name: fade; }
  .cell.pulse { animation: none; }
  .cell { transition: none; }
  @keyframes fade { 0%, 100% { opacity: 0; } 10%, 90% { opacity: 1; } }
}
