:root {
  color-scheme: dark;
  --bg: #1a1f27;
  --surface: #252d38;
  --text: #f9f6f0;
  --muted: #8a94a3;
  --correct: #4bae4f;
  --present: #fdb813;
  --absent: #3c4858;
  --accent: #48a9b5;
  --accent-warm: #f37021;
  --tile-border: #4a5568;
  --keyboard: #3c4858;
  --keyboard-text: #f9f6f0;
  --radius: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  background-color: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  padding: 0;
}

/* Eine Fläche inkl. Safe-Area – kein Verlauf/Farbsprung (v. a. unten bei PWA) */
.viewport-root {
  min-height: 100dvh;
  min-height: 100svh;
  background-color: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 10px 12px 16px;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: 100svh;
  width: 100%;
  box-sizing: border-box;
}

/* Spielbereich füllt die Höhe stabil, damit Raster + Tastatur nicht kollabieren */
#game[hidden] {
  display: none !important;
}

#game:not([hidden]) {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand img {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

@media (min-width: 400px) {
  .toolbar {
    flex-wrap: nowrap;
  }
}

button.icon-btn,
.kb-key {
  touch-action: manipulation;
}

button.icon-btn {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
}

button.icon-btn.icon-btn-tiny {
  padding: 4px 8px;
  font-size: 0.72rem;
  min-width: 0;
}

button.icon-btn.icon-btn-tiny#btnHelp {
  width: 28px;
  padding-left: 0;
  padding-right: 0;
  font-weight: 800;
}

button.icon-btn:active {
  transform: scale(0.98);
}

button.icon-btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, #3a8a94 100%);
  border-color: transparent;
}

.mode-pill {
  font-size: 0.62rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(72, 169, 181, 0.2);
  color: var(--accent);
  border: 1px solid rgba(72, 169, 181, 0.35);
  white-space: nowrap;
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 400px) {
  .mode-pill {
    max-width: none;
  }
}

.boards {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

/* Mobil & schmale PWA: ein Wordle, horizontal wischen (Scroll-Snap) */
.boards-inner {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  gap: 0;
  width: 100%;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.boards-inner::-webkit-scrollbar {
  display: none;
}

.boards-dots {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 2px 0 6px;
  flex-shrink: 0;
}

.boards-dot {
  touch-action: manipulation;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  padding: 0;
  border: none;
  background: var(--muted);
  opacity: 0.35;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s, background 0.15s;
}

.boards-dot.active {
  opacity: 1;
  background: var(--accent);
  transform: scale(1.2);
}

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

.board-wrap {
  background: rgba(37, 45, 56, 0.65);
  border-radius: 10px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  min-width: 0;
  display: flex;
  flex-direction: column;
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  box-sizing: border-box;
}

.board-wrap.solved {
  box-shadow: inset 0 0 0 2px rgba(75, 174, 79, 0.45);
}

.board-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
  text-align: center;
}

.board-grid {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(9, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
  aspect-ratio: 5 / 9;
  min-height: 0;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: 1fr;
  gap: 3px;
  min-height: 0;
  height: 100%;
  align-items: stretch;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: 2px solid var(--tile-border);
  background: transparent;
  font-weight: 800;
  font-size: clamp(0.62rem, 2.4vw, 0.88rem);
  text-transform: uppercase;
  color: var(--text);
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  user-select: none;
}

.tile.filled {
  border-color: #6b7280;
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: #fff;
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #1a1f27;
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: #e5e7eb;
}

.tile.current {
  border-color: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

/* Mobil: höheres Raster (Platz durch schmale Titelleiste ohne Fließtext) */
@media (max-width: 768px) {
  .app {
    min-height: 0;
    padding: 6px 10px 8px;
  }

  .app-header {
    margin-bottom: 4px;
    gap: 6px;
  }

  .brand img {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }

  .app-header h1 {
    font-size: 0.95rem;
  }

  .mode-pill {
    font-size: 0.58rem;
    padding: 2px 6px;
  }

  button.icon-btn.icon-btn-tiny {
    padding: 3px 7px;
    font-size: 0.68rem;
  }

  button.icon-btn.icon-btn-tiny#btnHelp {
    width: 26px;
  }

  #game:not([hidden]) {
    justify-content: flex-start;
  }

  .boards {
    flex: 0 1 auto;
    min-height: 0;
    gap: 2px;
    margin-bottom: 4px;
  }

  .boards-dots {
    padding: 0 0 2px;
  }

  .board-wrap {
    padding: 4px;
  }

  .board-title {
    font-size: 0.58rem;
    margin-bottom: 2px;
  }

  .board-grid {
    gap: 3px;
    width: 100%;
    height: min(80svh, 540px);
    min-height: 0;
    margin: 0 auto;
    aspect-ratio: unset;
    grid-template-rows: repeat(9, minmax(0, 1fr));
  }

  .board-row {
    gap: 3px;
  }

  .tile {
    border-width: 1px;
    border-radius: 3px;
    font-size: clamp(0.58rem, 3.6vw, 0.92rem);
  }

  .keyboard {
    gap: 4px;
    padding-top: 4px;
    margin-top: 0;
    padding-bottom: 0;
    background-color: transparent;
  }

  .kb-row {
    gap: 3px;
  }

  .kb-key-wide {
    height: 40px;
    font-size: 0.68rem;
  }

  .kb-key-letter {
    height: 40px;
  }

  .kb-key-label {
    font-size: 0.7rem;
  }
}

/* Desktop: vier Felder gleichzeitig im 2×2-Raster */
@media (min-width: 769px) {
  .app-header h1 {
    font-size: 1.2rem;
  }

  .brand img {
    width: 36px;
    height: 36px;
  }

  .mode-pill {
    font-size: 0.68rem;
    padding: 3px 10px;
  }

  .boards-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    overflow: visible;
    scroll-snap-type: none;
    touch-action: auto;
    overscroll-behavior-x: auto;
  }

  .board-wrap {
    flex: initial;
    width: auto;
    max-width: none;
    scroll-snap-align: none;
    scroll-snap-stop: normal;
  }

  .boards-dots {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .boards-inner {
    scroll-behavior: auto;
  }
}

@keyframes pulse {
  0%,
  100% {
    border-color: var(--accent);
  }
  50% {
    border-color: var(--accent-warm);
  }
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
  padding-top: 8px;
  flex-shrink: 0;
  width: 100%;
}

.kb-row {
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: nowrap;
  width: 100%;
}

.kb-key {
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  text-transform: uppercase;
}

.kb-key-wide {
  min-width: 36px;
  flex: 1.35;
  max-width: none;
  height: 46px;
  background: var(--keyboard);
  color: var(--keyboard-text);
  font-weight: 700;
  font-size: 0.72rem;
  padding: 0 6px;
}

.kb-key-letter {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  width: 0;
  height: 48px;
  padding: 0;
  background: transparent;
  color: var(--keyboard-text);
}

.kb-key-quads {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1px;
  border-radius: 4px;
  overflow: hidden;
  background: #2a3442;
}

.kbq {
  display: block;
  min-height: 0;
}

.kbq[data-state='empty'] {
  background: var(--keyboard);
}

.kbq[data-state='absent'] {
  background: #2a3442;
}

.kbq[data-state='present'] {
  background: var(--present);
}

.kbq[data-state='correct'] {
  background: var(--correct);
}

.kb-key-label {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-weight: 800;
  font-size: 0.78rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.kb-key:active {
  filter: brightness(1.12);
}

.kb-key-wide:active {
  filter: brightness(1.12);
}

.toast {
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 100;
}

.toast.show {
  opacity: 1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  max-width: 360px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.modal p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.modal-install .install-body {
  margin: 0 0 12px;
}

.modal-install .install-body p {
  margin: 0 0 12px;
}

.modal-install .install-steps {
  margin: 0 0 16px;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.modal-install .install-steps li {
  margin-bottom: 8px;
}

.modal-install .install-note {
  margin: 0 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-actions button {
  flex: 1;
  min-width: 120px;
}

.loader {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

@media (min-width: 480px) {
  .tile {
    font-size: 0.95rem;
  }
  .kb-key-letter {
    max-width: 48px;
    height: 50px;
  }
  .kb-key-wide {
    height: 50px;
  }
}
