:root {
  --bg: #121213;
  --fg: #e6e6e6;
  --muted: #9a9a9a;
  --border: #3a3a3c;
  --cell: #1c1c1d;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --primary: #4f8cff;
  --error: #e07a7a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: contain;
}
.cell, .key, .submit-btn, .show-card, .btn { touch-action: manipulation; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--fg);
  text-decoration: none;
}
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar a { color: var(--fg); }
.player-name { color: var(--muted); }

main {
  max-width: 560px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.card {
  background: var(--cell);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}

@media (max-width: 480px) {
  main { padding: 0 0.5rem; margin: 0.75rem auto; }
  .card { padding: 0.85rem; }
}

h1, h2, h3 { margin-top: 0; }
.muted { color: var(--muted); }
.error { color: var(--error); }

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}
.login-form input {
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

.btn {
  display: inline-block;
  padding: 0.55rem 0.95rem;
  background: var(--border);
  color: var(--fg);
  border: none;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.95rem;
  cursor: pointer;
  margin-right: 0.4rem;
}
.btn.primary { background: var(--primary); color: #fff; }

.game-card { padding-bottom: 1rem; }

.board {
  display: grid;
  gap: 6px;
  margin: 1rem auto;
  /* grid-template-rows + width werden vom JS pro Runde gesetzt */
}
.row { display: grid; gap: 6px; }
.cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--cell);
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 5vw, 1.75rem);
  font-weight: 700;
  text-transform: uppercase;
  transition: border-color 80ms ease;
  will-change: transform;
}
.cell.filled { border-color: #fff; }
.cell.cursor {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.5);
  cursor: text;
}
.cell { cursor: pointer; }
.row.active .cell { cursor: pointer; }
@keyframes cursor-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.55); }
  50%      { box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.0); }
}
.cell.cursor { animation: cursor-pulse 1.1s ease-in-out infinite; }
.cell.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.cell.present { background: var(--present); border-color: var(--present); color: #fff; }
.cell.absent  { background: var(--absent);  border-color: var(--absent);  color: #fff; }

@keyframes pop {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0   rgba(79, 140, 255, 0); }
  45%  { transform: scale(1.18); box-shadow: 0 0 0 5px rgba(79, 140, 255, 0.35); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0   rgba(79, 140, 255, 0); }
}
.cell.pop { animation: pop 170ms ease-out; }

@keyframes flip {
  0%   { transform: rotateX(0deg); }
  45%  { transform: rotateX(90deg); }
  55%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}
.cell.flipping { animation: flip 480ms ease-in-out; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
.row.shake { animation: shake 380ms ease-in-out; }

@keyframes bounce {
  0%   { transform: translateY(0); }
  35%  { transform: translateY(-22px); }
  60%  { transform: translateY(0); }
  80%  { transform: translateY(-8px); }
  100% { transform: translateY(0); }
}
.cell.bounce { animation: bounce 620ms ease-in-out; }

.message {
  min-height: 1.4em;
  text-align: center;
  margin-top: 0.75rem;
  font-weight: 600;
  transition: opacity 200ms ease;
}
.message:empty { opacity: 0; }
.message.error { color: var(--error); }
.message.success { color: var(--correct); font-size: 1.1rem; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message.show { animation: fadeIn 200ms ease-out; }

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 1rem;
}
.kb-row { display: flex; justify-content: center; gap: 4px; }
.key {
  background: #565759;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.6rem 0.4rem;
  font-size: 0.95rem;
  font-weight: 700;
  flex: 1 1 0;
  min-width: 0;
  max-width: 42px;
  cursor: pointer;
  text-transform: uppercase;
  transition: transform 80ms ease, filter 80ms ease, background-color 200ms ease;
  user-select: none;
}
.key:hover { filter: brightness(1.2); }
.key:active, .key.tapped { transform: scale(0.88); filter: brightness(1.6); }
.key.wide { padding: 0.6rem 0.7rem; max-width: 64px; flex: 1.4 1 0; font-size: 0.8rem; }
.key.backspace {
  background: #b85a52;
  font-size: 1.1rem;
}
.key.backspace:hover { filter: brightness(1.15); }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent  { background: var(--absent);  }

.submit-btn {
  display: block;
  margin: 0.85rem auto 0;
  padding: 0.85rem 1.5rem;
  width: min(320px, 95%);
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 100ms ease, filter 120ms ease, background-color 180ms ease, opacity 180ms ease;
  box-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
.submit-btn:hover:not(:disabled) { filter: brightness(1.15); }
.submit-btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }
.submit-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
  box-shadow: none;
}
.submit-btn.ready {
  background: var(--correct);
}
.submit-btn.ready:hover:not(:disabled) { filter: brightness(1.1); }
@keyframes pulse-ready {
  0%, 100% { box-shadow: 0 2px 0 rgba(0,0,0,0.25), 0 0 0 0 rgba(83, 141, 78, 0.55); }
  50%      { box-shadow: 0 2px 0 rgba(0,0,0,0.25), 0 0 0 8px rgba(83, 141, 78, 0.0); }
}
.submit-btn.ready { animation: pulse-ready 1.6s ease-in-out infinite; }

.scroll-hint {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 0.45rem 0.95rem;
  background: rgba(79, 140, 255, 0.92);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  z-index: 100;
  pointer-events: auto;
  animation: hint-bounce 1.4s ease-in-out infinite;
}
.scroll-hint[hidden] { display: none; }

/* Aktive Zeile klebt beim Scrollen am oberen Rand, damit Eingabe + Tastatur
   gleichzeitig sichtbar bleiben. Kein Padding/Border → Zellen behalten exakt
   die gleiche Position wie in den anderen Zeilen. */
.row.sticky-active {
  position: sticky;
  top: 6px;
  z-index: 50;
  background: var(--cell);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.55);
}

@keyframes sticky-exit {
  0%   { transform: translateY(0);     opacity: 1; }
  100% { transform: translateY(-110%); opacity: 0; }
}
.row.exiting-sticky {
  animation: sticky-exit 280ms cubic-bezier(0.45, 0, 0.55, 0.2) forwards;
}

.hint {
  margin: 0.25rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}
.hint strong { color: var(--fg); }

.attempt-indicator {
  margin: 0.6rem 0 0.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.attempt-indicator[hidden] { display: none; }
@keyframes hint-bounce {
  0%, 100% { transform: translate(-50%, 0);   opacity: 0.92; }
  50%      { transform: translate(-50%, 5px); opacity: 1; }
}

.ranking {
  list-style: decimal inside;
  padding-left: 0;
}
.ranking li {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.ranking.failed { list-style: none; }
.ranking.failed li { color: var(--muted); }
.solution { letter-spacing: 0.2em; }

.breadcrumb { margin-top: 0; font-size: 0.9rem; color: var(--muted); }
.breadcrumb a { color: var(--muted); }

.round-list { list-style: none; padding-left: 0; margin: 0; }
.round-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.round-item:last-child { border-bottom: none; }
.round-label { display: flex; align-items: center; gap: 0.6rem; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--border);
  color: var(--fg);
}
.badge.solved { background: var(--correct); color: #fff; }
.badge.failed { background: var(--error); color: #fff; }
.badge.progress { background: var(--present); color: #fff; }
.badge.open { background: var(--border); color: var(--fg); }

.table-wrap { overflow-x: auto; }
.ranking-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 1rem;
}
.ranking-table th, .ranking-table td {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.ranking-table th:nth-child(2),
.ranking-table td:nth-child(2) { text-align: left; }
.ranking-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.score-cell.failed { color: var(--error); }
.score-cell.absent { color: var(--muted); }
.total { font-weight: 700; }
.solution-list { padding-left: 1.1rem; }

.words-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0.75rem 0 1rem;
}
.words-form label { font-weight: 600; }
.words-form textarea {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 180px;
}
.words-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.3);
}
.success-headline { color: var(--correct); }
.word-bulk {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  word-break: break-word;
}
.word-bulk.added { color: var(--correct); }

.show-list { list-style: none; padding-left: 0; margin: 0.5rem 0 0; display: flex; flex-direction: column; gap: 0.5rem; }
.show-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  text-decoration: none;
  transition: border-color 120ms ease, transform 100ms ease;
}
.show-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.show-title { font-weight: 700; }
.show-meta { color: var(--muted); font-size: 0.9rem; }
