/* ---------------------------------------------------------------
   Bausteine: Buttons, Felder, Karten, Chips, Dialoge, Toasts
   --------------------------------------------------------------- */

/* ------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 11px 18px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: transform 0.14s ease, background 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
  user-select: none;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: rgba(48, 60, 100, 0.8); border-color: var(--line-strong); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.42; }

.btn--primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
  box-shadow: 0 12px 26px -14px rgba(99, 102, 241, 0.9);
}
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, var(--brand), var(--brand-2)); }

.btn--ghost { background: transparent; border-color: var(--line); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn--danger { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }
.btn--danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.26); }
.btn--ok { background: rgba(34, 197, 94, 0.18); border-color: rgba(34, 197, 94, 0.42); color: #bbf7d0; }

.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: 7px 13px; font-size: 0.86rem; }
.btn--lg { min-height: 54px; padding: 15px 26px; font-size: 1.05rem; }
.btn--icon { min-width: var(--tap); padding: 10px; border-radius: 14px; }

/* ------------------------------------------------------------ Felder */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 0.84rem; font-weight: 600; color: var(--text-dim); }
.field__hint { font-size: 0.78rem; color: var(--text-faint); }
.field__error { font-size: 0.82rem; color: #fca5a5; }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: rgba(10, 14, 28, 0.66);
  border: 1px solid var(--line);
  transition: border-color 0.16s ease, background 0.16s ease;
  /* 16px verhindert das automatische Zoomen auf iOS */
  font-size: 16px;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); background: rgba(10, 14, 28, 0.9); }
.input::placeholder { color: var(--text-faint); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23a9b3d4'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 38px;
}
.select option { background: var(--surface-solid); color: var(--text); }

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.32em;
  text-align: center;
  font-weight: 700;
  font-size: 1.15rem;
}

/* Schalter */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 8px 0; min-height: var(--tap); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track {
  flex: 0 0 auto;
  width: 48px; height: 28px;
  border-radius: 999px;
  background: rgba(10, 14, 28, 0.8);
  border: 1px solid var(--line);
  position: relative;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch__track::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch input:checked + .switch__track { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; }
.switch input:checked + .switch__track::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.switch__text { display: flex; flex-direction: column; gap: 2px; }

/* Segment-Auswahl (touchfreundliche Alternative zu Radios) */
.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
.segmented__item {
  flex: 1 1 auto;
  min-width: 84px;
  min-height: var(--tap);
  padding: 9px 14px;
  border-radius: 12px;
  background: rgba(10, 14, 28, 0.6);
  border: 1px solid var(--line);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
}
.segmented__item[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(168, 85, 247, 0.32));
  border-color: rgba(168, 85, 247, 0.6);
  color: #fff;
}

.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper__value { min-width: 46px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ Flaechen */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.panel--pad { padding: 18px; }
@media (min-width: 720px) { .panel--pad { padding: 22px; } }

.divider { height: 1px; background: var(--line); border: 0; margin: 14px 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(148, 163, 208, 0.14);
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip--ok { background: rgba(34, 197, 94, 0.16); border-color: rgba(34, 197, 94, 0.4); color: #bbf7d0; }
.chip--warn { background: rgba(245, 158, 11, 0.16); border-color: rgba(245, 158, 11, 0.4); color: #fde68a; }
.chip--bad { background: rgba(239, 68, 68, 0.16); border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }
.chip--live { background: rgba(99, 102, 241, 0.2); border-color: rgba(99, 102, 241, 0.5); color: #c7d2fe; }
.chip--coin {
  background: rgba(240, 180, 41, 0.16);
  border-color: rgba(240, 180, 41, 0.45);
  color: #fde68a;
  font-variant-numeric: tabular-nums;
}
.chip--coin svg { flex: 0 0 auto; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto; }
.dot--on { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
.dot--off { background: var(--text-faint); }

.avatar {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 0.95rem;
  color: #0b1020;
  background: var(--avatar, #64748b);
  box-shadow: inset 0 -2px 6px rgba(0, 0, 0, 0.24);
}
.avatar--sm { width: 30px; height: 30px; border-radius: 10px; font-size: 0.8rem; }
.avatar--lg { width: 52px; height: 52px; border-radius: 16px; font-size: 1.2rem; }

/* ------------------------------------------------------------ Kopfzeile */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 14px) 10px calc(var(--safe-l) + 14px);
  background: rgba(11, 16, 32, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
@media (max-width: 520px) { .hide-sm { display: none !important; } }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.02em; }
.brand__mark {
  width: 34px; height: 34px; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center;
  font-size: 1rem; color: #fff;
  box-shadow: 0 10px 22px -12px rgba(99, 102, 241, 0.9);
}
.brand__text { font-size: 1.02rem; }

/* ------------------------------------------------------------ Spielkacheln */
.game-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) { .game-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .game-grid { grid-template-columns: repeat(3, 1fr); } }

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: left;
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease;
}
.game-card::before {
  content: "";
  position: absolute; inset: -40% 45% 40% -20%;
  background: radial-gradient(circle, var(--accent, var(--brand)) 0%, transparent 70%);
  opacity: 0.24;
  pointer-events: none;
}
.game-card:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--line-strong); }
.game-card:active:not(:disabled) { transform: scale(0.99); }
.game-card:disabled { opacity: 0.55; }
.game-card__icon {
  width: 54px; height: 54px;
  border-radius: 16px;
  display: grid; place-items: center;
  background: rgba(10, 14, 28, 0.55);
  border: 1px solid var(--line);
}
.game-card__title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.game-card__meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }

/* ------------------------------------------------------------ Listen */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: rgba(10, 14, 28, 0.42);
  border: 1px solid var(--line);
  text-align: left;
  width: 100%;
}
.list-item--button { transition: background 0.16s ease, border-color 0.16s ease; }
.list-item--button:hover { background: rgba(24, 32, 58, 0.7); border-color: var(--line-strong); }
.list-item--active { border-color: rgba(99, 102, 241, 0.6); background: rgba(99, 102, 241, 0.14); }

.empty {
  padding: 26px 18px;
  text-align: center;
  color: var(--text-faint);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------ Dialoge */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(4, 7, 16, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade 0.16s ease;
  padding: 0;
}
@media (min-width: 640px) { .overlay { align-items: center; padding: 24px; } }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(180deg, #1a2340, #131a30);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  padding: 20px 18px calc(var(--safe-b) + 20px);
  animation: sheet-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@media (min-width: 640px) {
  .sheet { border-radius: var(--radius-lg); padding: 24px; animation: pop 0.18s ease; }
}
.sheet__grip {
  width: 42px; height: 4px; border-radius: 999px;
  background: var(--line-strong);
  margin: -6px auto 14px;
}
@media (min-width: 640px) { .sheet__grip { display: none; } }
.sheet__head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.sheet__actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.sheet__actions .btn { flex: 1 1 140px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ------------------------------------------------------------ Toasts */
.toasts {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + 12px);
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 15px;
  border-radius: 14px;
  background: rgba(24, 32, 58, 0.95);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  animation: toast-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.toast--error { border-color: rgba(239, 68, 68, 0.55); background: rgba(60, 20, 28, 0.95); }
.toast--ok { border-color: rgba(34, 197, 94, 0.5); background: rgba(16, 48, 30, 0.95); }
.toast--leaving { animation: toast-out 0.2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ------------------------------------------------------------ Chat */
.chat { display: flex; flex-direction: column; min-height: 0; }
.chat__log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-right: 4px;
  scrollbar-width: thin;
}
.chat__msg { font-size: 0.87rem; line-height: 1.4; word-break: break-word; }
.chat__msg--system { color: var(--text-faint); font-style: italic; font-size: 0.8rem; }
.chat__from { font-weight: 700; }
.chat__form { display: flex; gap: 8px; margin-top: 10px; }
.chat__form .input { flex: 1 1 auto; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 208, 0.28); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }
