:root {
  --sky: #bdeef7;
  --sea: #0891b2;
  --sea-strong: #067a94;
  --sand: #f4dfae;
  --card: #fffaf0;
  --border: #e0c07a;
  --text: #3b2412;
  --text-dim: #8a6a42;
  --accent: #f97316;
  --accent-strong: #ea6a0a;
  --gold: #eab308;
  --danger: #ef4444;
  --good: #22c55e;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  position: fixed;
  overflow: hidden;
  width: 100%;
}

body {
  background:
    radial-gradient(circle at 20% -10%, #e6f9fc 0%, transparent 55%),
    linear-gradient(180deg, var(--sky) 0%, var(--sky) 38%, var(--sand) 38%, #e9cd8e 100%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
}

h1 { font-size: clamp(24px, 6vw, 32px); margin: 0; letter-spacing: -0.01em; }
h2 { font-size: clamp(19px, 5vw, 24px); margin: 0; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen.hidden { display: none; }

.card {
  width: min(460px, 92vw);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 22px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 16px 40px rgba(59, 36, 18, 0.18);
  animation: rise .3s ease;
  max-height: 92vh;
  overflow-y: auto;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.5;
}

/* --- Ladebildschirm --- */
.loading-card { display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--text); }
.spinner { font-size: 56px; animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Formulare --- */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.field input {
  font-size: 18px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text);
}

.field input:focus {
  outline: 3px solid var(--sea);
  outline-offset: 1px;
}

.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.avatar-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: #fff;
  font-size: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform .12s ease, border-color .12s ease;
}

.avatar-btn:active { transform: scale(0.94); }
.avatar-btn.active {
  border-color: var(--accent);
  background: #fff3e6;
  transform: scale(1.08);
}

/* --- Buttons: grosse Touch-Flaechen --- */
.btn {
  border: none;
  border-radius: 16px;
  padding: 16px 20px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  transition: transform .1s ease, filter .12s ease;
  font-family: inherit;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  box-shadow: 0 8px 18px rgba(234, 106, 10, 0.35);
}

.btn-primary:disabled {
  background: #d8c9ae;
  color: #8a7a5c;
  box-shadow: none;
  cursor: default;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 2px solid var(--border);
  min-height: 48px;
  font-size: 15px;
}

.btn:hover { filter: brightness(1.05); }

/* --- Beitreten-Seite / Raumliste --- */
.rooms-card { gap: 14px; }

.btn-create { margin-bottom: 4px; }

.room-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.room-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 2px solid var(--border);
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  min-height: 64px;
  transition: transform .1s ease, background .12s ease;
}

.room-card:active { transform: scale(0.98); background: #fff3e6; }

.room-card .avatar { font-size: 30px; flex: none; }

.room-card .info { flex: 1; min-width: 0; }
.room-card .info .host-name { font-weight: 700; font-size: 16px; }
.room-card .info .player-count { color: var(--text-dim); font-size: 13px; }

.room-card .go { font-size: 22px; color: var(--accent); flex: none; }

.empty-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  margin: 8px 0;
}

/* --- Lobby --- */
.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 10px 14px;
}

.player-row .avatar { font-size: 26px; }
.player-row .name { flex: 1; font-weight: 600; }
.player-row .host-badge { font-size: 12px; color: var(--accent); font-weight: 700; }
.player-row.disconnected { opacity: .45; }
.player-row .dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--good); flex: none;
}
.player-row.disconnected .dot { background: var(--text-dim); }

/* --- Spielbildschirm --- */
.game-screen {
  justify-content: flex-start;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.game-topbar {
  width: min(680px, 96vw);
  margin: 0 auto 6px;
}

.leave-btn {
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 40px;
}

.leave-btn:active { transform: scale(0.96); }

.progress-path {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: min(680px, 96vw);
  margin: 4px auto 10px;
  flex-wrap: wrap;
}

.progress-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex: none;
  transition: transform .2s ease, background .2s ease;
}

.progress-line {
  width: 18px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  flex: none;
}

.progress-dot.done { background: var(--gold); border-color: var(--gold); }
.progress-dot.current { border-color: var(--accent); transform: scale(1.15); box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.25); }
.progress-line.done { background: var(--gold); }

.game-content {
  width: min(680px, 96vw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* .clue-cards haelt 1-3 Karten (je nachdem, wie viele Hinweis-
   Dimensionen ein Spieler bei weniger Mitspielern als Dimensionen
   abbekommt, siehe Room.assignClues()) - flex-wrap statt festem Grid,
   damit 1 Karte breit bleibt und 2-3 sich nebeneinander/darunter
   einordnen, je nach Platz. */
.clue-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.clue-card {
  flex: 1 1 170px;
  background: linear-gradient(135deg, #fff3d6, #ffe6b0);
  border: 3px solid var(--gold);
  border-radius: 20px;
  padding: 16px 16px;
  text-align: center;
  box-shadow: 0 10px 22px rgba(234, 179, 8, 0.25);
}

.clue-icon { font-size: 38px; line-height: 1; margin-bottom: 6px; }
.clue-text { font-size: 17px; font-weight: 700; margin: 0; }
.clue-hint { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); text-align: center; }

.station-header { text-align: center; }
.station-header h2 { margin-bottom: 2px; }

.island-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.island-card {
  background: #fff;
  border: 3px solid var(--border);
  border-radius: 18px;
  padding: 14px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
  min-height: 120px;
  transition: transform .1s ease, border-color .12s ease, background .15s ease;
}

.island-card:active { transform: scale(0.96); }
.island-card .icons { font-size: 30px; display: flex; gap: 6px; }
.island-card .name { font-weight: 700; font-size: 14px; text-align: center; }

.island-card.wrong { animation: shake .4s ease; border-color: var(--danger); background: #fff0f0; }
.island-card.correct { border-color: var(--good); background: #f0fff4; animation: pop .4s ease; }

/* Bleibt (anders als .wrong, das nach der Shake-Animation wieder
   verschwindet) dauerhaft stehen: einmal falsch getippte Inseln gelten
   fuer den Rest der Station als ausgeschlossen - aus Rumprobieren wird so
   echtes Ausschluss-Denken statt "nochmal versuchen". */
.island-card.excluded {
  opacity: .45;
  background: #f3f0e8;
}
.island-card.excluded .icons,
.island-card.excluded .name {
  text-decoration: line-through;
}

.island-card:disabled { cursor: default; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* --- Kompass-Overlay beim Loesen einer Station --- */
.compass-overlay {
  position: fixed;
  inset: 0;
  background: rgba(59, 36, 18, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 20;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.compass-overlay.hidden { display: none; }

.compass { width: 96px; height: 96px; display: flex; align-items: center; justify-content: center; }
.compass-needle {
  font-size: 76px;
  animation: spinCompass 1.6s cubic-bezier(.2,.6,.3,1);
}

@keyframes spinCompass {
  from { transform: rotate(0deg) scale(0.7); }
  60% { transform: rotate(620deg) scale(1.1); }
  to { transform: rotate(720deg) scale(1); }
}

/* --- Schatz gefunden --- */
.treasure-card { text-align: center; align-items: center; }
.treasure-chest { font-size: 76px; animation: bounce 1s ease infinite; }

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.confetti-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation-name: confettiFall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  from { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  to { transform: translateY(110vh) rotate(540deg); opacity: 0.9; }
}

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 30;
  max-width: 90vw;
  text-align: center;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.hidden {
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
}

/* --- Querformat: Karten nicht ueber den sichtbaren Bereich hinaus wachsen lassen --- */
@media (orientation: landscape) and (max-height: 480px) {
  .card { padding: 18px 20px; gap: 10px; max-height: 94vh; }
  .clue-icon { font-size: 34px; }
  .treasure-chest { font-size: 52px; }
}

@media (max-width: 380px) {
  body { font-size: 16px; }
  .island-card { min-height: 104px; }
}
