/* ============================================================
   Antigravity Chess Portal – Style Sheet
   Selbst gebauter Board-Renderer, keine externen Abhängigkeiten
   ============================================================ */

/* ── Custom Properties ──────────────────────────────────────── */
:root {
  --bg:           #0f1117;
  --bg-card:      rgba(255,255,255,0.05);
  --bg-card-hov:  rgba(255,255,255,0.09);
  --border:       rgba(255,255,255,0.1);
  --text:         #e8eaf0;
  --text-muted:   #8892a0;
  --accent:       #7c6af7;
  --accent-hov:   #9481ff;
  --danger:       #e05c5c;
  --success:      #4caf7d;
  --warn:         #e0a050;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 8px 32px rgba(0,0,0,0.45);
  --board-size:   min(560px, 90vw);
  --sq-size:      calc(var(--board-size) / 8);
  --transition:   160ms ease;

  /* Standard Brett-Farben (Wood / Default) */
  --sq-light:  #f0d9b5;
  --sq-dark:   #b58863;
}

/* ── Brett-Farbdesigns (CSS Themes) ─────────────────────────── */
body[data-board-theme="wood"] {
  --sq-light: #f0d9b5;
  --sq-dark:  #b58863;
}

body[data-board-theme="green"] {
  --sq-light: #ffffdd;
  --sq-dark:  #86a666;
}

body[data-board-theme="blue"] {
  --sq-light: #dee3e6;
  --sq-dark:  #8ca2ad;
}

body[data-board-theme="dark"] {
  --sq-light: #4a4d58;
  --sq-dark:  #282a32;
}

body[data-board-theme="purple"] {
  --sq-light: #eae3f7;
  --sq-dark:  #8b70b5;
}

body[data-board-theme="glass"] {
  --sq-light: rgba(255, 255, 255, 0.22);
  --sq-dark:  rgba(255, 255, 255, 0.06);
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.logo svg { width: 24px; height: 24px; color: var(--accent); }

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
              opacity var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hov); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-card); color: var(--text); border-color: rgba(255,255,255,0.2); }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

/* ── Layout ──────────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--board-size) 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

/* ── Board Wrapper ───────────────────────────────────────────── */
.board-section { display: flex; align-items: flex-start; justify-content: center; }

#board-wrap {
  width: var(--board-size);
  height: var(--board-size);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 3px rgba(124,106,247,0.25);
  position: relative;
  flex-shrink: 0;
}

#board-wrap::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(135deg, var(--accent) 0%, transparent 60%);
  opacity: 0.35;
  pointer-events: none;
  z-index: -1;
}

/* ── Chess Board Grid ────────────────────────────────────────── */
#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

/* ── Squares ──────────────────────────────────────────────────── */
.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  /* GPU-Compositing vorbereiten für schnelle Highlights */
  will-change: background-color;
  transition: background-color 80ms ease, filter 60ms ease;
}

.sq.light { background-color: var(--sq-light); }
.sq.dark  { background-color: var(--sq-dark); }

.sq:hover { filter: brightness(1.14); }

.sq.is-drag-origin .piece {
  opacity: 0.25;
}

/* ── Pieces (Unicode oder SVG-Image) ────────────────────────── */
.piece {
  /* Größe: 85% der Feldgröße, clamp für Responsivität */
  font-size: clamp(22px, calc(var(--sq-size) * 0.78), 64px);
  width: 86%;
  height: 86%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  transform: translateZ(0);
  transition: transform 80ms ease;
}

.piece img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.sq:hover .piece { transform: translateZ(0) scale(1.06); }

/* Schwebende Drag-Figur */
.drag-piece-ghost {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sq-size);
  height: var(--sq-size);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1000;
  will-change: transform;
  transform: translate(-50%, -50%);
  -webkit-user-select: none;
  user-select: none;
}

.drag-piece-ghost .piece {
  transform: scale(1.22);
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.55));
}

/* Unicode Fallback Konturierung */
.sq[data-pc="w"] .piece:not(:has(img)) {
  color: #fffff0;
  text-shadow:
    0  1px 2px #000,
    0 -1px 2px #000,
    1px 0  2px #000,
   -1px 0  2px #000,
    0 0 6px rgba(0,0,0,0.6);
}

.sq[data-pc="b"] .piece:not(:has(img)) {
  color: #1c1a18;
  text-shadow:
    0  1px 1px rgba(255,255,255,0.15),
    0 -1px 1px rgba(255,255,255,0.1),
    0 0 4px rgba(0,0,0,0.5);
}

/* ── Square Highlights ────────────────────────────────────────── */
.sq.sq-selected {
  background-color: rgba(100, 175, 255, 0.55) !important;
}
.sq.sq-last {
  background-color: rgba(124, 106, 247, 0.38) !important;
}
.sq.sq-check {
  background-color: rgba(220, 55, 55, 0.58) !important;
  animation: pulse-check 0.8s ease infinite alternate;
}

@keyframes pulse-check {
  from { background-color: rgba(220,55,55,0.58); }
  to   { background-color: rgba(220,55,55,0.82); }
}

/* Legaler Zug – leeres Feld: Punkt */
.sq.sq-legal::after {
  content: '';
  position: absolute;
  width: 31%;
  height: 31%;
  border-radius: 50%;
  background: rgba(0,0,0,0.23);
  pointer-events: none;
}

/* Legaler Zug – Schlag-Feld: Ring */
.sq.sq-capture::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 5px solid rgba(0,0,0,0.23);
  pointer-events: none;
}

/* ── Koordinaten ──────────────────────────────────────────────── */
.coord {
  position: absolute;
  font-size: clamp(8px, calc(var(--sq-size) * 0.2), 13px);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  opacity: 0.72;
  z-index: 1;
}
.coord-rank { top: 3px; left: 4px; }
.coord-file { bottom: 3px; right: 4px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark  .coord { color: var(--sq-light); }

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background var(--transition);
}
.card:hover { background: var(--bg-card-hov); }

.card-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── Status ──────────────────────────────────────────────────── */
.status-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.status-row:last-of-type { margin-bottom: 0; }
.label { font-size: 0.85rem; color: var(--text-muted); }
.value { font-size: 0.85rem; font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: 600;
}
.badge::before { content:''; width:8px; height:8px; border-radius:50%; display:inline-block; }
.badge-white { background: rgba(255,255,255,0.12); color: var(--text); }
.badge-white::before { background: #fffff0; border: 1px solid #aaa; }
.badge-black { background: rgba(0,0,0,0.4); color: var(--text); }
.badge-black::before { background: #1c1a18; }

/* ── Game Over Banner ────────────────────────────────────────── */
.game-over-banner {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(124,106,247,0.25), rgba(75,63,209,0.15));
  border: 1px solid rgba(124,106,247,0.4);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; font-weight: 600; font-size: 0.9rem;
}
.game-over-banner[hidden] { display: none; }

/* ── FEN Textarea ────────────────────────────────────────────── */
#fen-display {
  width: 100%; background: rgba(0,0,0,0.3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: 'Cascadia Code','Fira Code', monospace; font-size: 0.78rem;
  line-height: 1.5; padding: 8px 10px; resize: none; margin-bottom: 8px;
  transition: border-color var(--transition);
}
#fen-display:focus { outline: none; border-color: var(--accent); }

/* ── Move List ───────────────────────────────────────────────── */
.move-list {
  list-style: none; max-height: 220px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--accent) transparent;
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px;
}
.move-list li { font-size: 0.82rem; padding: 3px 6px; border-radius: 4px; color: var(--text); }
.move-list li:hover { background: rgba(255,255,255,0.06); }
.move-list li.move-white { color: #d8c89a; }
.move-list li.move-black { color: #a0aab8; }
.move-list li.move-latest { background: rgba(124,106,247,0.2); }
.move-list li.move-white::before { content: attr(data-num)'.'; color: var(--text-muted); margin-right: 4px; }

/* ── Debug Card ──────────────────────────────────────────────── */
.debug-card summary { cursor: pointer; }
.debug-value { display: block; font-family: monospace; font-size: 0.75rem; color: var(--accent); word-break: break-all; margin-top: 4px; }

/* ── Promotion Dialog ────────────────────────────────────────── */
#promotion-dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #1a1d28; color: var(--text); padding: 28px 32px;
  box-shadow: var(--shadow); text-align: center;
}
#promotion-dialog::backdrop { background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
#promotion-dialog h3 { font-size: 1rem; font-weight: 600; margin-bottom: 20px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }

.promotion-options { display: flex; gap: 12px; justify-content: center; }

.promo-btn {
  width: 64px; height: 64px; font-size: 2.4rem; line-height: 1;
  background: var(--bg-card); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}
.promo-btn:hover { background: var(--bg-card-hov); border-color: var(--accent); transform: translateY(-3px); }
.promo-btn:active { transform: scale(0.95); }

/* ── Toast Notifications ─────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column-reverse; gap: 10px;
  z-index: 9999; pointer-events: none;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm); font-size: 0.875rem;
  font-weight: 500; color: #fff; max-width: 320px; box-shadow: var(--shadow);
  pointer-events: auto; animation: toast-in 250ms ease forwards;
  border-left: 4px solid transparent;
}
.toast.error   { background: #2d1a1a; border-color: var(--danger);  }
.toast.success { background: #1a2d22; border-color: var(--success); }
.toast.info    { background: #1a1e2d; border-color: var(--accent);  }
.toast.warn    { background: #2d2416; border-color: var(--warn);    }
.toast.toast-out { animation: toast-out 300ms ease forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-8px); } }

/* ── Lobby / Start Dialog ────────────────────────────────────── */
.lobby-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #141721;
  color: var(--text);
  padding: 32px;
  box-shadow: var(--shadow);
  max-width: 480px;
  width: 90vw;
  margin: auto;
}
.lobby-dialog::backdrop {
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
}
.lobby-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #fff;
}
.lobby-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.lobby-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.lobby-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lobby-box h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-hov);
}
.lobby-input-row {
  display: flex;
  gap: 8px;
}
.lobby-input {
  flex: 1;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 8px 12px;
  text-align: center;
}
.lobby-input:focus { outline: none; border-color: var(--accent); }

/* ── Role Badges & Room Pill ─────────────────────────────────── */
.role-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.role-tutor { background: rgba(124,106,247,0.25); color: var(--accent-hov); border: 1px solid var(--accent); }
.role-student { background: rgba(76,175,125,0.2); color: var(--success); border: 1px solid var(--success); }

.room-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-family: monospace;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}
.room-pill:hover { background: rgba(255,255,255,0.12); }

/* ── Tutor Control Panel (Rechteverwaltung) ──────────────────── */
.control-panel {
  border-color: rgba(124,106,247,0.4);
  background: linear-gradient(180deg, rgba(124,106,247,0.08) 0%, rgba(255,255,255,0.03) 100%);
}
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
.toggle-label {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text);
}
.toggle-desc {
  font-size: 0.74rem;
  color: var(--text-muted);
  display: block;
}

/* Custom Switch Slider */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(255,255,255,0.15);
  transition: 0.2s;
  border-radius: 24px;
  border: 1px solid var(--border);
}
.slider::before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider::before { transform: translateX(20px); }

/* Gefahr / Sperren Switch */
input:checked + .slider.slider-danger { background-color: var(--danger); }

/* ── Schüler Brett-Sperre Overlay ────────────────────────────── */
.board-lock-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 23, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 500;
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  border-radius: var(--radius);
  animation: toast-in 200ms ease;
  pointer-events: all;
}
.board-lock-overlay[hidden] { display: none; }
.board-lock-icon { font-size: 2.2rem; }

/* ── SVG Pfeil Overlay ───────────────────────────────────────── */
#arrows-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
}


/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .board-section { justify-content: center; }
  #board-wrap { width: min(480px, 95vw); height: min(480px, 95vw); }
}
@media (max-width: 500px) {
  .app-header { padding: 10px 16px; }
  .logo span  { display: none; }
  .app-layout { padding: 16px; gap: 16px; }
}

/* ── Settings Dialog ─────────────────────────────────────────── */
.settings-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #141721;
  color: var(--text);
  padding: 28px;
  box-shadow: var(--shadow);
  max-width: 440px;
  width: 92vw;
  margin: auto;
}
.settings-dialog::backdrop {
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.settings-title {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-group {
  margin-bottom: 20px;
}
.settings-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.settings-select {
  width: 100%;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.95rem;
  padding: 10px 14px;
  cursor: pointer;
}
.settings-select:focus {
  outline: none;
  border-color: var(--accent);
}

.theme-preview-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 6px;
}
.theme-preview-light { flex: 1; }
.theme-preview-dark { flex: 1; }

/* ── Feste dezente Fußleiste unten rechts ─────────────────────── */
.fixed-legal-links {
  position: fixed;
  bottom: 8px;
  right: 14px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  opacity: 0.55;
  transition: opacity 160ms ease;
  pointer-events: auto;
}
.fixed-legal-links:hover {
  opacity: 1;
}
.fixed-legal-links a {
  color: var(--text-muted);
  text-decoration: none;
}
.fixed-legal-links a:hover {
  color: var(--accent-hov);
  text-decoration: underline;
}
.fixed-legal-links span {
  color: var(--text-muted);
}
