﻿/* ═══ Grundfarben (Lichess-inspiriert) ════════════════════════════════════ */
:root {
  --bg:        #161512;
  --panel:     #262421;
  --card:      #302e2c;
  --border:    #3d3b39;
  --text:      #c0b9b0;
  --text-dim:  #7a7067;
  --accent:    #629924;
  --accent-h:  #78be2f;
  --sq-light:  #f0d9b5;
  --sq-dark:   #b58863;
  --clock-bg:  #1a1a1a;
  --danger:    #c62828;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  height: 100%;
}

/* ═══ Navbar ═══════════════════════════════════════════════════════════════ */
.navbar { background: var(--panel); border-bottom: 1px solid var(--border); }
.btn-nav {
  background: none; border: none; color: var(--text-dim); padding: 4px 10px;
  border-radius: 4px; transition: all .15s;
}
.btn-nav:hover, .btn-nav.active { background: var(--card); color: #fff; }

/* ═══ Views ════════════════════════════════════════════════════════════════ */
.view { min-height: calc(100vh - 48px); }

/* ═══ Auth ═════════════════════════════════════════════════════════════════ */
.auth-container {
  max-width: 380px; margin: 80px auto; padding: 32px;
  background: var(--panel); border-radius: 12px;
  border: 1px solid var(--border);
}
.auth-logo { font-size: 1.8rem; font-weight: bold; color: #fff; text-align: center; margin-bottom: 24px; }
.nav-tabs { border-bottom-color: var(--border); }
.nav-tabs .nav-link { color: var(--text-dim); background: var(--panel) !important; border: none; padding: 8px 16px; border-radius: 0; }
.nav-tabs .nav-link:hover { color: var(--text); background: var(--card) !important; }
.nav-tabs .nav-link.active { color: #fff; background: var(--card) !important; border-bottom: 2px solid var(--accent); }

/* ═══ Bootstrap-Overrides für dunkles Theme ════════════════════════════════ */
.text-muted { color: #a09890 !important; }
.form-label  { color: #a09890; }

/* ═══ Karten / Inputs ══════════════════════════════════════════════════════ */
.dark-card {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; overflow: hidden;
}
.dark-card .card-header {
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 8px 12px; font-weight: 600; font-size: .85rem;
}
.dark-card .card-body { background: var(--card); }
.dark-input {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 8px 12px;
}
.dark-input:focus   { outline: none; border-color: var(--accent); background: var(--panel); color: #fff; box-shadow: none; }
.dark-input:invalid { box-shadow: none !important; border-color: var(--border) !important; }
.dark-input::placeholder { color: var(--text-dim); }

/* Browser-Autofill-Farbe (rosa/gelb) auf Hintergrundfarbe überschreiben */
.dark-input:-webkit-autofill,
.dark-input:-webkit-autofill:hover,
.dark-input:-webkit-autofill:focus,
.dark-input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 40px var(--panel) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
}

/* ═══ Buttons ══════════════════════════════════════════════════════════════ */
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-time {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 3px 10px; font-size: .8rem; transition: all .15s;
}
.btn-time:hover, .btn-time.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ═══ Spielerliste ═════════════════════════════════════════════════════════ */
.player-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s;
}
.player-item:hover { background: var(--panel); }
.player-item.selected { background: #2a3a1a; }
.player-item .status-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.available { background: #4caf50; }
.status-dot.playing   { background: #ff9800; }
.status-dot.away      { background: #9e9e9e; }
.status-dot.offline   { background: #444; }
.player-elo-badge { color: var(--text-dim); font-size: .8rem; }
.bot-badge {
  display: inline-flex; align-items: center; gap: 2px;
  background: #5865f2; color: #fff;
  font-size: .6rem; font-weight: 700; letter-spacing: .04em;
  padding: 1px 5px; border-radius: 3px;
  vertical-align: middle; margin-left: 4px;
  user-select: none;
}
.btn-player-hist {
  margin-left: auto; flex-shrink: 0;
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 4px; padding: 1px 5px; font-size: .75rem; line-height: 1.4;
  cursor: pointer; transition: all .15s;
}
.btn-player-hist:hover { background: var(--panel); color: var(--text); border-color: var(--accent); }
.status-label { font-size: .75rem; color: var(--text-dim); }

/* ═══ Tabellen ═════════════════════════════════════════════════════════════ */
.table-dark { --bs-table-bg: var(--card); --bs-table-border-color: var(--border); color: var(--text); }
.table-dark th { background: var(--panel); color: var(--text-dim); font-size: .8rem; font-weight: 600; }
.table-dark td { font-size: .85rem; vertical-align: middle; }
.table-hover tbody tr:hover td { background: rgba(255,255,255,.04); cursor: pointer; }

/* ═══ Schachbrett (fluid) ══════════════════════════════════════════════════ */
/*
  --chess-sq: Feldgröße, passt sich glatt dem Fenster an.
  Desktop (>700 px): Sidebar ~320 px abziehen, Rest /8, max. 70 px.
  Mobil  (≤700 px):  Kein Sidebar, nur Rand abziehen.
*/
:root {
  --chess-sq: clamp(40px, calc((100vw - 340px) / 8), 70px);
}
@media (max-width: 700px) {
  :root { --chess-sq: clamp(36px, calc((100vw - 20px) / 8), 52px); }
}

.board-wrap { display: flex; justify-content: center; }

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, var(--chess-sq));
  grid-template-rows:    repeat(8, var(--chess-sq));
  border: 3px solid #444;
  box-shadow: 0 8px 40px rgba(0,0,0,.8);
  user-select: none;
}

.sq {
  position: relative;
  width: var(--chess-sq); height: var(--chess-sq);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark);  }

.sq.selected   { background: rgba(20,120,30,.75) !important; }
.sq.last-from,
.sq.last-to {
  box-shadow: inset 0 0 0 200px rgba(255,195,0,.28);
}
.sq.check      { background: rgba(200,30,30,.6) !important; }

.sq .dot {
  position: absolute; width: 28%; height: 28%;
  background: rgba(0,0,0,.25); border-radius: 50%;
}
.sq.capture-hint::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 5px rgba(0,0,0,.25);
}

.piece-img {
  width: 88%; height: 88%;
  pointer-events: none;
  display: block;
  filter: drop-shadow(1px 2px 2px rgba(0,0,0,.4));
}

.coord-rank {
  position: absolute; top: 2px; left: 3px;
  font-size: 11px; font-weight: bold; opacity: .65;
  color: var(--sq-dark); font-family: sans-serif;
}
.sq.light .coord-rank { color: var(--sq-dark); }
.sq.dark  .coord-rank { color: var(--sq-light); }

.coord-file {
  position: absolute; bottom: 1px; right: 3px;
  font-size: 11px; font-weight: bold; opacity: .65;
  font-family: sans-serif;
}
.sq.light .coord-file { color: var(--sq-dark); }
.sq.dark  .coord-file { color: var(--sq-light); }

/* ═══ Spielansicht Layout ══════════════════════════════════════════════════ */
.game-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  min-height: calc(100vh - 48px);
}
.game-chat-left {
  width: 200px; min-width: 170px; max-width: 220px;
  height: calc(var(--chess-sq) * 8 + 96px);  /* gleiche Höhe wie Brett + Player-Bars */
  display: flex; flex-direction: column;
}
.game-left { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.game-right { width: 240px; min-width: 210px; max-width: 260px; display: flex; flex-direction: column; gap: 8px; }

.player-bar {
  width: calc(var(--chess-sq) * 8);
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; background: var(--panel); border-radius: 6px;
}
.player-name { font-weight: 600; color: #fff; }
.player-elo  { color: var(--text-dim); font-size: .8rem; margin-left: 6px; }

.clock {
  font-family: 'Courier New', monospace;
  font-size: 1.6rem; font-weight: bold;
  background: var(--clock-bg); color: var(--text-dim);
  padding: 4px 12px; border-radius: 6px; letter-spacing: 1px;
  min-width: 100px; text-align: center;
}
.clock.active { color: #fff; background: #1e3a0e; box-shadow: 0 0 8px rgba(100,200,50,.3); }
.clock.danger { color: #ef5350; background: #3a0a0a; }

#move-history { color: var(--text); max-height: 160px; overflow-y: auto; }

/* ═══ Turnier-Spielansicht Layout ══════════════════════════════════════════ */
.tgame-layout {
  display: flex; justify-content: center; align-items: flex-start; gap: 16px;
  padding: 12px 16px; min-height: calc(100vh - 48px);
}
.tgame-left { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.tgame-right { width: 280px; min-width: 220px; display: flex; flex-direction: column; gap: 6px; }

.tg-row { cursor: pointer; }
.tg-row:hover td { background: rgba(255,255,255,.05); }
.tg-row.active-game td { background: rgba(100,200,50,.1); }

/* Auto-Switch-Button aktiv */
#tg-btn-autoswitch.active { background: #0288d1; border-color: #0288d1; color: #fff; }

/* Zugindikatoren in der Partieliste */
.turn-icon { font-size: .85rem; margin-left: 3px; }
.turn-icon.my-turn   { color: #4caf50; }
.turn-icon.urgent    { color: #ef5350; animation: pulse-urgent .6s ease-in-out infinite alternate; }
@keyframes pulse-urgent {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: .5; transform: scale(1.3); }
}

/* ═══ Turnier-Liste ════════════════════════════════════════════════════════ */
.list-group-item-dark {
  background: var(--card); border-color: var(--border); color: var(--text);
  padding: 10px 14px; cursor: pointer; border: none; border-bottom: 1px solid var(--border);
  display: block;
}
.list-group-item-dark:hover { background: var(--panel); }
.list-group-item-dark.active { background: #1e3a0e; }

/* ═══ Modals ═══════════════════════════════════════════════════════════════ */
.dark-modal { background: var(--panel); border: 1px solid var(--border); color: var(--text); }
.dark-modal .modal-header { border-bottom-color: var(--border); }
.dark-modal .modal-footer { border-top-color: var(--border); }
.btn-close-white { filter: invert(1); }

/* ═══ Badges ═══════════════════════════════════════════════════════════════ */
.badge-waiting  { background: #555; }
.badge-active   { background: #1565c0; }
.badge-finished { background: #2e7d32; }
.badge-aborted  { background: #7b1fa2; }

/* ═══ Toast ════════════════════════════════════════════════════════════════ */
#toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast-msg {
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.6);
  animation: fadeInRight .2s ease;
}
@keyframes fadeInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ═══ Chat ══════════════════════════════════════════════════════════════════ */
.chat-msg   { margin-bottom: 4px; word-break: break-word; line-height: 1.5; }
.chat-time  { color: var(--text-dim); font-size: .75rem; }
.chat-me    { color: #ffc107; font-weight: 600; }
.chat-other { color: #64b5f6; font-weight: 600; }
.chat-text  { color: var(--text); }

/* ═══ Spielart-Auswahl ══════════════════════════════════════════════════════ */
.btn-game-type {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 4px 12px; font-size: .85rem; transition: all .15s; cursor: pointer;
}
.btn-game-type:hover { background: var(--card); }
.btn-game-type.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ═══ Xiangqi-Brett (SVG-basiert, via JS gerendert) ════════════════════════ */
.xq-board-wrap { display: flex; justify-content: center; }
/* Das Brett selbst wird via JS inline-styled */

/* Responsive: kleinere Zellgröße auf kleinen Screens */
@media (max-width: 700px) {
  /* Handled via JS: CELL=44, PAD=28, PSIZE=38 */
}
@media (max-width: 480px) {
  /* Handled via JS: CELL=36, PAD=22, PSIZE=30 */
}

/* ═══ Partie-Viewer ════════════════════════════════════════════════════════ */
#viewer-board {
  grid-template-columns: repeat(8, 54px);
  grid-template-rows:    repeat(8, 54px);
  border: 2px solid #444;
}
#viewer-board .sq          { width: 54px; height: 54px; cursor: default; }
#viewer-board .coord-rank  { font-size: 10px; }
#viewer-board .coord-file  { font-size: 10px; }

.viewer-player-bar {
  width: 432px; padding: 4px 8px;
  background: var(--panel); border-radius: 5px;
  display: flex; align-items: center; gap: 8px;
}

.viewer-move-list {
  flex: 1; max-height: 500px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 1px;
  font-family: monospace; font-size: .875rem;
}
.viewer-move-row { display: flex; align-items: center; gap: 2px; padding: 1px 0; }
.viewer-move-num { color: var(--text-dim); min-width: 2.4em; text-align: right; padding-right: 4px; }
.viewer-move-san {
  padding: 2px 7px; border-radius: 4px; cursor: pointer;
  color: var(--text); transition: background .1s; min-width: 4.5em;
}
.viewer-move-san:hover { background: var(--panel); }
.viewer-move-san.active { background: var(--accent); color: #fff; }

/* ═══ Responsive ════════════════════════════════════════════════════════════ */

/* ── Tablet (≤ 900 px) ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --chess-sq: clamp(40px, calc((100vw - 320px) / 8), 60px); }
  .clock { font-size: 1.2rem; }
}

/* ── Großes Smartphone / kleines Tablet (≤ 700 px) ─────────────────────── */
@media (max-width: 700px) {

  /* Navbar: nur Icons, kein Username, weniger Abstand */
  .brand-text            { display: none; }
  .btn-nav span[data-i18n] { display: none; }
  #nav-user              { display: none !important; }
  .navbar .d-flex        { gap: 0.35rem; }

  .coord-rank, .coord-file { font-size: 9px; }

  /* Spielansicht: Chat oben, Brett, Sidebar unten */
  .game-layout      { flex-direction: column; align-items: center; padding: 6px 4px; }
  .game-chat-left   { width: 100%; max-width: 500px; min-width: unset; min-height: 160px; }
  .game-left        { width: 100%; }
  .game-right       { width: 100%; max-width: 500px; min-width: unset; }

  /* Turnier-Spielansicht: Brett oben, Sidebar unten */
  .tgame-layout { flex-direction: column; align-items: center; padding: 6px 4px; }
  .tgame-left   { width: 100%; }
  .tgame-right  { width: 100%; max-width: 500px; min-width: unset; }

  /* Partie-Viewer Modal: Board + Zugliste untereinander */
  .modal-xl                 { margin: 0.25rem; max-width: calc(100% - 0.5rem); }
  .viewer-layout            { flex-direction: column; align-items: center; }
  .viewer-move-list         { width: 352px; max-height: 200px; }
  .viewer-player-bar        { width: 352px; }
  #viewer-board             { grid-template-columns: repeat(8, 44px); grid-template-rows: repeat(8, 44px); }
  #viewer-board .sq         { width: 44px !important; height: 44px !important; }
}

/* ── Kleines Smartphone (≤ 480 px) ─────────────────────────────────────── */
@media (max-width: 480px) {
  .clock       { font-size: 1rem; padding: 3px 8px; min-width: 76px; }

  /* Viewer */
  #viewer-board             { grid-template-columns: repeat(8, 40px); grid-template-rows: repeat(8, 40px); }
  #viewer-board .sq         { width: 40px !important; height: 40px !important; }
  .viewer-move-list         { width: 320px; }
  .viewer-player-bar        { width: 320px; }

  /* Weniger Padding */
  .game-layout, .tgame-layout { padding: 4px 2px; gap: 6px; }
  .container-fluid            { padding-left: 6px !important; padding-right: 6px !important; }

  /* Auth-Formular */
  .auth-container { margin: 20px auto; padding: 20px; }
}
