:root {
  --c-red: #e53935;
  --c-orange: #fb8c00;
  --c-yellow: #f3c614;
  --c-green: #43a047;
  --c-blue: #1e88e5;
  --c-purple: #8e24aa;

  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #211f1c;
  --muted: #8a8478;
  --tile-bg: #1c1a17;
  --accent: #1e88e5;
  --accent-2: #43a047;
  --danger: #e53935;
  --cell-empty: #e7e2d6;
  --cell-border: #d5cfc0;
  --gold: #e8b93a;

  --tile-size: 48px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.hidden { display: none !important; }

/* --- Join / Waiting / End screens --- */

#screen-join, #screen-waiting, #screen-end {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.join-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,0.08);
}

.join-card h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 0.95rem;
}

#name-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: 2px solid var(--cell-border);
  border-radius: 12px;
  margin-bottom: 12px;
  outline: none;
}
#name-input:focus { border-color: var(--accent); }

button {
  font-family: inherit;
  font-size: 1rem;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
}

#join-btn, .primary {
  width: 100%;
  background: var(--tile-bg);
  color: #fff;
  font-weight: 600;
}
#join-btn:active, .primary:active { opacity: 0.85; }
.primary:disabled { background: #c9c3b4; cursor: default; }

.status { min-height: 1.2em; color: var(--danger); font-size: 0.9rem; margin-top: 12px; }

.seat-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.seat-list li {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--cell-empty);
  margin-bottom: 8px;
  font-weight: 500;
}
.seat-list li.empty { color: var(--muted); font-style: italic; font-weight: normal; }

.change-name-link {
  display: inline-block;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: underline;
}
.change-name-link.small {
  display: block;
  text-align: center;
  margin: 0 0 6px;
  font-size: 0.75rem;
}

#end-scores { white-space: pre-line; font-size: 1.1rem; color: var(--ink); }

/* --- Game screen --- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  gap: 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--cell-border);
}

.player-badge {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 8px;
  border-radius: 12px;
  transition: background 0.2s;
}
.player-badge.active {
  background: rgba(30, 136, 229, 0.12);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.player-badge.offline .p-name {
  color: var(--danger);
}
.p-name { font-size: 0.85rem; font-weight: 600; }
.p-score { font-size: 1.4rem; font-weight: 700; }

.bag-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
  color: var(--muted);
}
.bag-count { font-size: 1.2rem; font-weight: 700; color: var(--ink); }
.bag-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; }

.turn-banner {
  text-align: center;
  margin: 8px 0;
  font-weight: 600;
  min-height: 1.2em;
}
.turn-banner.mine { color: var(--accent-2); }
.turn-banner.theirs { color: var(--muted); }

#board-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
  background: var(--bg);
  touch-action: pan-x pan-y;
}

#board {
  display: grid;
  gap: 4px;
  padding: 24px;
  width: max-content;
  margin: 0 auto;
}

.cell {
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 8px;
  background: var(--cell-empty);
  border: 1px dashed var(--cell-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.placeable {
  background: rgba(67, 160, 71, 0.15);
  border: 1px dashed var(--accent-2);
}

.cell.filled {
  border: none;
  padding: 0;
}

.cell.staged {
  box-shadow: 0 0 0 2px var(--accent-2);
}
.cell.staged.invalid {
  box-shadow: 0 0 0 2px var(--danger);
}

.tile {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--tile-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 3px rgba(0,0,0,0.25);
}

.tile svg { width: 78%; height: 78%; }

.msg-line {
  text-align: center;
  min-height: 1.4em;
  color: var(--danger);
  font-size: 0.85rem;
  margin: 2px 0;
  padding: 0 12px;
}

#hand-area {
  background: var(--panel);
  border-top: 1px solid var(--cell-border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.hand {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 4px 0 10px;
  min-height: calc(var(--tile-size) + 8px);
}

.hand-tile {
  position: relative;
  width: var(--tile-size);
  height: var(--tile-size);
  border-radius: 10px;
  background: var(--tile-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 3px rgba(0,0,0,0.25);
  border: 3px solid transparent;
  transition: transform 0.1s;
}
.hand-tile svg { width: 78%; height: 78%; }
.hand-tile.selected {
  border-color: var(--accent);
  transform: translateY(-4px);
}
.hand-tile.selected-exchange {
  border-color: var(--orange, #fb8c00);
  transform: translateY(-4px);
}
.hand-tile.new-tile {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(232, 185, 58, 0.35), 0 2px 3px rgba(0,0,0,0.25);
}

.controls {
  display: flex;
  gap: 8px;
}
.secondary {
  background: var(--cell-empty);
  color: var(--ink);
  font-weight: 600;
}
.secondary:active { opacity: 0.8; }
.secondary.active-mode {
  background: var(--tile-bg);
  color: #fff;
}
#confirm-btn { flex: 1; }

/* --- Qwirkle-Feier --- */

.cell.qwirkle-glow .tile {
  animation: qwirkle-pulse 0.55s ease-in-out 3;
  box-shadow: 0 0 0 3px var(--gold), 0 0 16px 4px rgba(232, 185, 58, 0.7);
}

@keyframes qwirkle-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.qwirkle-toast {
  position: fixed;
  left: 50%;
  top: 14%;
  transform: translate(-50%, 0) scale(1);
  background: var(--tile-bg);
  color: var(--gold);
  border: 2px solid var(--gold);
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 0.95rem;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  z-index: 50;
  animation: qwirkle-toast-in 0.35s ease-out;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.qwirkle-toast strong {
  display: block;
  font-size: 1.3rem;
  letter-spacing: 0.03em;
}
.qwirkle-toast.fade-out {
  opacity: 0;
  transform: translate(-50%, -10px) scale(0.96);
}

@keyframes qwirkle-toast-in {
  from { opacity: 0; transform: translate(-50%, -12px) scale(0.9); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
