:root {
  color-scheme: dark;
  --bg: #101927;
  --panel: #18263a;
  --panel-2: #20334a;
  --ink: #f8f5ed;
  --muted: #aab8c8;
  --accent: #f7c950;
  --accent-ink: #251b00;
  --empty: #24364b;
  --danger: #ff7f8e;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
/* Die Seite selbst ist fix: kein Scrollen, kein Gummiband, kein Zoomen – nur die Kastln bewegen sich. */
html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-y;
  -webkit-text-size-adjust: 100%;
}
body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 20% 0%, #24415b 0, transparent 35rem),
    linear-gradient(155deg, #101927, #0b1421 80%);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input { -webkit-user-select: text; user-select: text; }
button, input { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* Alles passt auf einen Bildschirm: Das Spielfeld nimmt sich den Platz, der übrig bleibt.
   Nur auf sehr kleinen Bildschirmen (z. B. Handy quer) darf der Inhalt scrollen. */
.game-shell {
  width: min(100%, 620px);
  height: 100%;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) clamp(14px, 4vw, 28px) max(8px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none;
}
/* Punktezeile + Spielfeld: Das Feld ist so groß, wie Breite und übrige Höhe erlauben.
   Übriger Platz bleibt oben unter dem Header – Spielfeld, Kastln und Knöpfe bleiben beisammen beim Daumen. */
.board-wrap {
  --status-h: 56px;   /* Höhe der Punktezeile inkl. Abstand */
  flex: 1 1 0;
  min-height: calc(230px + var(--status-h));
  container-type: size;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}
.topbar { display: grid; grid-template-columns: 1fr 1.35fr 1fr; gap: 8px; align-items: stretch; }
.player-block, .score-card {
  min-width: 0;
  border: 1px solid #ffffff12;
  border-radius: 16px;
  background: #18263acc;
  box-shadow: 0 9px 30px #0002;
}
.plain-button { width: 100%; height: 100%; padding: 10px 11px; text-align: left; border: 0; background: none; cursor: pointer; }
.score-card { padding: 10px 11px; text-align: right; }
.global-card {
  position: relative;
  display: block;
  width: 100%;
  padding-inline: 18px;
  text-align: center;
  background: #f7c950;
  color: #2b2105;
  cursor: pointer;
}
.global-card:active { transform: scale(.97); }
/* Pfeil rechts: Antippen öffnet die Bestenliste */
.global-card .more-hint {
  position: absolute;
  top: 50%;
  right: 6px;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  opacity: .45;
  transform: translateY(-50%);
}
.eyebrow { display: block; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; opacity: .68; }
.score-card strong, .player-block strong { display: block; overflow: hidden; font-size: clamp(1rem, 4vw, 1.4rem); text-overflow: ellipsis; white-space: nowrap; }
.score-card small { display: block; overflow: hidden; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; opacity: .72; }

/* Eigener Rekord geknackt / neuer allgemeiner Rekord */
.personal-card.record-blink { animation: record-blink .42s ease-in-out 4; }
.global-card.crown-blink { animation: crown-blink .42s ease-in-out 4; }
@keyframes record-blink {
  50% { background: var(--accent); color: var(--accent-ink); transform: scale(1.06); box-shadow: 0 0 0 3px #fff9, 0 0 32px #f7c950cc; }
}
@keyframes crown-blink {
  50% { background: #fff6d6; transform: scale(1.06); box-shadow: 0 0 0 3px #fff, 0 0 36px #f7c950; }
}

.status-row {
  position: relative;
  flex: none;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--status-h) - 12px);
  margin: 6px 4px;
}
.clock { color: var(--muted); font-size: .95rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.score-card .record-time { font-variant-numeric: tabular-nums; }
/* Leere Zeit-Zeile trotzdem gleich hoch – sonst springt das Spielfeld, wenn sie auftaucht. */
.score-card .record-time:empty::before { content: "\00a0"; }
.undo-count {
  display: inline-grid;
  min-width: 1.5em;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #ffffff1c;
  font-size: .85em;
  font-variant-numeric: tabular-nums;
}
.kicker { margin: 0 0 2px; color: var(--accent); font-size: .76rem; font-weight: 850; letter-spacing: .11em; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: -.06em; line-height: .95; }
h1 { font-size: clamp(2.8rem, 12vw, 4.8rem); }
h2 { font-size: clamp(2.3rem, 10vw, 3.6rem); }
#score { color: var(--ink); font-size: 1.2rem; font-weight: 850; font-variant-numeric: tabular-nums; }

#board {
  flex: none;
  width: 100%;
  width: min(100cqw, calc(100cqh - var(--status-h)));
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  gap: clamp(3px, .8vw, 6px);
  padding: clamp(7px, 1.8vw, 11px);
  border: 1px solid #ffffff0d;
  border-radius: 22px;
  background: #091320cc;
  box-shadow: 0 22px 65px #0006, inset 0 1px #ffffff0c;
  touch-action: none;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}
#board.over .cell { filter: saturate(.55) brightness(.75); transition: filter .25s ease; }

/* Spielende: sofort und groß, damit man es gleich merkt */
.over-banner {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 50%;
  z-index: 8;
  display: grid;
  gap: 2px;
  padding: 14px 12px;
  border-radius: 18px;
  background: #ff7f8ef2;
  color: #2a0710;
  text-align: center;
  box-shadow: 0 0 0 3px #fff6, 0 20px 60px #000b;
  transform: translateY(-50%);
  animation: banner-in .32s cubic-bezier(.2, .9, .3, 1.3);
  pointer-events: none;
}
.over-banner[hidden] { display: none; }
.over-banner strong { font-size: clamp(1.5rem, 7vw, 2.2rem); font-weight: 900; letter-spacing: -.02em; }
.over-banner span { font-size: .95rem; font-weight: 800; opacity: .8; }
@keyframes banner-in { from { opacity: 0; transform: translateY(-50%) scale(.7); } }
.cell, .mini i {
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: clamp(4px, 1.2vw, 8px);
  background: var(--fill, var(--empty));
}
.cell { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.cell.paint, .mini i.paint, .floating i.paint {
  background: var(--fill);
  box-shadow: inset 0 3px #ffffff3d, inset 0 -4px #00000026, 0 4px 9px #0003;
}
.cell.placed { animation: place-pop .2s ease-out; }
@keyframes place-pop { from { transform: scale(.8); filter: brightness(1.35); } }

/* Vorschau beim Drüberziehen: wo das Kastl landet … */
.cell.ghost { background: var(--fill); opacity: .5; box-shadow: inset 0 0 0 2px #ffffffb0; }
/* … und welche Reihen/Spalten damit verschwinden würden – ruhig, ohne Pulsieren */
.cell.will-clear {
  z-index: 1;
  filter: brightness(1.2);
  box-shadow: inset 0 3px #ffffff55, inset 0 -4px #00000026, 0 0 0 2px #ffffffc0;
}
/* Einfarbige Linie in der Vorschau: goldener Rahmen */
.cell.will-clear.mono { box-shadow: inset 0 3px #ffffff55, inset 0 -4px #00000026, 0 0 0 2px #f7c950, 0 0 10px #f7c95080; }

/* Abgeräumte Linien: einmal sanft aufleuchten, dann ausblenden */
.cell.clearing { background: var(--empty); z-index: 2; }
.cell.clearing::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--fill);
  animation: clear-fade .46s ease-out forwards;
}
.cell.clearing.mono::after { box-shadow: 0 0 0 2px #f7c950, 0 0 12px #f7c95099; }
@keyframes clear-fade {
  0% { filter: brightness(1); transform: scale(1); opacity: 1; }
  35% { filter: brightness(1.55); transform: scale(1.03); opacity: 1; }
  100% { filter: brightness(1.2); transform: scale(.55); opacity: 0; }
}

.points-pop {
  position: absolute;
  z-index: 5;
  color: #fff;
  font-size: clamp(1rem, 4.5vw, 1.4rem);
  font-weight: 900;
  white-space: nowrap;
  text-shadow: 0 2px 10px #000a, 0 0 2px #000;
  pointer-events: none;
  animation: points-pop .9s ease-out forwards;
}
.points-pop.combo { color: var(--accent); font-size: clamp(1.1rem, 5vw, 1.6rem); }
.points-pop.mono { font-size: clamp(1.25rem, 6vw, 1.9rem); text-shadow: 0 0 18px #f7c950, 0 2px 10px #000a; }
@keyframes points-pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); }
  18% { opacity: 1; transform: translate(-50%, -75%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

#tray { --slot-h: clamp(78px, 19vw, 112px); display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 10px; }
.slot {
  -webkit-touch-callout: none;
  height: var(--slot-h);
  display: grid;
  place-content: center;
  border: 2px solid transparent;
  border-radius: 17px;
  background: var(--panel);
  touch-action: none;
  user-select: none;
}
.slot:enabled { cursor: grab; }
.slot.active { border-color: var(--accent); background: var(--panel-2); }
.mini { display: grid; gap: 3px; pointer-events: none; transition: opacity .12s ease; }
.slot.lifted .mini { opacity: .18; }

/* Spielende: übrige Kastln zeigen, dass sie nicht mehr passen */
.slot.stuck { border-color: #ff7f8e99; background: #2a1f2e; animation: stuck-shake .42s ease-in-out 2; }
.slot.stuck .mini { filter: saturate(.4); opacity: .8; }
@keyframes stuck-shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.primary-button.attention { animation: attention 1.3s ease-in-out infinite; }
@keyframes attention { 50% { box-shadow: 0 0 0 4px #f7c95055, 0 0 26px #f7c95099; } }
.mini i {
  width: min(clamp(11px, 3.6vw, 20px), calc((var(--slot-h) - 18px - (var(--n, 1) - 1) * 3px) / var(--n, 1)));
  aspect-ratio: 1;
  background: transparent;
}

.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-row button { white-space: nowrap; }
.primary-button, .secondary-button {
  min-height: 46px;
  padding: 11px 16px;
  border: 0;
  border-radius: 13px;
  font-weight: 850;
  cursor: pointer;
}
.primary-button { background: var(--accent); color: var(--accent-ink); }
.secondary-button { background: var(--panel-2); }
.secondary-button:disabled { cursor: default; opacity: .4; }
.bottom-links { display: flex; justify-content: center; gap: 6px; }
.link-button {
  margin-top: 2px;
  padding: 4px 10px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: .8rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  opacity: .7;
  cursor: pointer;
}
.link-button:disabled { opacity: .35; cursor: default; }
/* Feste Höhe (2 Zeilen), damit das Spielfeld nicht springt, wenn der Text wechselt */
.info {
  height: 2.7em;
  margin: 6px 4px 0;
  overflow: hidden;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.35;
  text-align: center;
}

.floating { position: fixed; left: 0; top: 0; z-index: 20; pointer-events: none; will-change: transform; }
.floating-piece {
  display: grid;
  opacity: .92;
  filter: drop-shadow(0 12px 16px #0008);
  animation: lift .14s ease-out;
}
@keyframes lift { from { transform: scale(var(--from, .6)); opacity: .6; } }
.floating i { width: 100%; height: 100%; border-radius: clamp(4px, 1.2vw, 8px); }
.floating.blocked .paint { background: var(--danger) !important; }
.floating.scoring .floating-piece { opacity: 1; }
body.dragging, body.dragging * { cursor: grabbing; }

dialog {
  width: min(calc(100% - 28px), 440px);
  padding: 0;
  border: 1px solid #ffffff18;
  border-radius: 25px;
  background: #142236;
  color: var(--ink);
  box-shadow: 0 35px 100px #000b;
}
dialog::backdrop { background: #07101dcc; backdrop-filter: blur(8px); }
.login-dialog form, .result-dialog > div { padding: clamp(24px, 7vw, 38px); }
.login-dialog h2, .result-dialog h2 { margin-bottom: 18px; }
.login-dialog p, .result-dialog p { color: var(--muted); line-height: 1.5; }
.login-dialog label { display: block; margin: 21px 0 7px; font-size: .85rem; font-weight: 800; }
.login-dialog input { width: 100%; padding: 14px; border: 2px solid #ffffff20; border-radius: 12px; outline: none; background: #0d1929; color: #fff; }
.login-dialog input:focus { border-color: var(--accent); }
.login-dialog .primary-button, .result-dialog .primary-button, .leaderboard-dialog .primary-button { width: 100%; margin-top: 10px; }
.login-dialog .field-hint { margin: 6px 0 0; font-size: .78rem; line-height: 1.4; }
.wide-button { width: 100%; margin-top: 8px; }
.dialog-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.dialog-row .secondary-button { padding-inline: 8px; }

/* Bestenliste */
.leaderboard-dialog > div { padding: clamp(20px, 6vw, 32px); }
.leaderboard-dialog h2 { margin-bottom: 14px; }
.leader-list { margin: 0; padding: 0; list-style: none; }
.leader-row {
  display: grid;
  grid-template-columns: 2.1em minmax(0, 1fr) auto;
  grid-template-areas: "rank name score" "rank name time";
  align-items: center;
  column-gap: 8px;
  padding: 6px 10px;
  border-radius: 12px;
}
.leader-row:nth-child(odd) { background: #ffffff08; }
.leader-row.me { background: #f7c95026; box-shadow: inset 0 0 0 1px #f7c95066; }
.leader-rank { grid-area: rank; font-weight: 850; text-align: center; color: var(--muted); }
.leader-name { grid-area: name; overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.leader-score { grid-area: score; text-align: right; font-variant-numeric: tabular-nums; }
.leader-time { grid-area: time; color: var(--muted); font-size: .72rem; text-align: right; font-variant-numeric: tabular-nums; }
.leader-time:empty { display: none; }
.leader-me, .leader-empty { margin: 12px 0 0; color: var(--muted); text-align: center; }
.leader-me:empty { display: none; }
.privacy-note { margin-bottom: 0; font-size: .75rem; opacity: .72; }
.error { min-height: 1.4em; margin: 7px 0 !important; color: #ff9ba7 !important; font-size: .88rem; }
.logo-mark { width: 56px; display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 20px; transform: rotate(-4deg); }
.logo-mark i { aspect-ratio: 1; border-radius: 6px; background: var(--accent); box-shadow: inset 0 3px #fff5, inset 0 -3px #0002; }

/* Popup legt sich kurz über die ganze Statuszeile – Header-Karten und Spielfeld bleiben frei */
.toast {
  position: absolute;
  inset: 50% 0 auto;
  z-index: 6;
  padding: 7px 14px;
  border-radius: 14px;
  background: #fff6d6;
  color: #2b2105;
  font-size: .95rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: center;
  box-shadow: 0 14px 40px #0008;
  opacity: 0;
  transform: translateY(-50%) scale(.9);
  transition: opacity .2s ease, transform .32s cubic-bezier(.2, .9, .3, 1.25);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(-50%) scale(1); }
.toast[data-level="great"] { background: var(--accent); }
.toast[data-level="record"] { background: #fff6d6; box-shadow: 0 0 0 2px #f7c950, 0 14px 40px #0008; }
.toast.pop { animation: toast-pop .28s ease-out; }
@keyframes toast-pop { from { transform: translateY(-50%) scale(1.08); } }

@media (max-width: 390px) {
  .topbar { gap: 5px; }
  .eyebrow { font-size: .62rem; }
  .score-card, .plain-button { padding: 8px 7px; }
  .global-card { padding-inline: 15px; }
  .action-row button { padding-inline: 10px; }
}
/* Niedrige Bildschirme (z. B. kleines iPhone im Browser): alles etwas kompakter, damit das Feld groß bleibt */
@media (max-height: 620px) {
  .game-shell { padding-top: max(6px, env(safe-area-inset-top)); }
  .score-card, .plain-button { padding-block: 5px; }
  .score-card strong, .player-block strong { font-size: 1.05rem; }
  .board-wrap { --status-h: 42px; min-height: calc(200px + var(--status-h)); }
  #score { font-size: 1.05rem; }
  #tray { --slot-h: 62px; margin: 8px 0 6px; }
  .primary-button, .secondary-button { min-height: 40px; padding-block: 8px; }
  .info { height: 2.5em; margin-top: 4px; font-size: .8rem; line-height: 1.25; }
  .link-button { margin-top: 0; padding-block: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  /* Ausnahme: Die Punkte-Blasen steigen immer wie am Desktop auf – auch wenn am Handy
     „Bewegung reduzieren“ bzw. Energiesparen an ist. Sonst wären sie sofort unsichtbar. */
  .points-pop { animation: points-pop .9s ease-out forwards !important; }
}
