:root {
  --bg: #1f2430;
  --panel: #2a3140;
  --panel-2: #333b4d;
  --text: #e7ecf3;
  --muted: #9aa6bd;
  --accent: #4f8cff;
  --accent-2: #3fb27f;
  --danger: #e0605e;
  --light-sq: #e9d8b8;
  --dark-sq: #9e6b43;
  --highlight: #6fd08c;
  --select: #f1d264;
  --piece-light: #f3ead6;
  --piece-dark: #2b2b2b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
}

header h1 {
  text-align: center;
  font-size: 1.5rem;
  margin: 8px 0 20px;
}

h2 { font-size: 1.1rem; margin: 8px 0 12px; }

.screen { display: flex; flex-direction: column; gap: 12px; }
.hidden { display: none !important; }

button {
  font-size: 1rem;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:active { transform: scale(.98); }
button:hover { filter: brightness(1.1); }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); }
button.danger { background: var(--danger); color: #fff; font-weight: 600; }

/* Bestätigungs-Dialog */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--panel);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.modal-box h3 { margin: 0 0 8px; font-size: 1.15rem; }
.modal-box p { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; }

input {
  font-size: 1.4rem;
  padding: 14px;
  border-radius: 12px;
  border: 2px solid var(--panel-2);
  background: var(--panel);
  color: var(--text);
  text-align: center;
  letter-spacing: .3em;
  width: 100%;
}
input:focus { outline: none; border-color: var(--accent); }

.game-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.game-card {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 16px 8px;
  text-align: center;
  cursor: pointer;
}
.game-card .icon { font-size: 2rem; display: block; margin-bottom: 6px; }
.game-card.selected { border-color: var(--accent); background: var(--panel-2); }

.divider { text-align: center; color: var(--muted); position: relative; margin: 8px 0; }
.divider span { background: var(--bg); padding: 0 12px; position: relative; z-index: 1; }
.divider::before {
  content: ""; position: absolute; top: 50%; left: 0; right: 0;
  height: 1px; background: var(--panel-2);
}

.code-display {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: .25em;
  text-align: center;
  background: var(--panel);
  padding: 20px;
  border-radius: 16px;
  color: var(--accent);
}

.status-bar {
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: .95rem;
  line-height: 1.5;
}
.status-bar .turn-you { color: var(--accent-2); font-weight: 600; }
.status-bar .turn-opp { color: var(--muted); }
.status-bar .warn { color: var(--danger); }

.game-controls { display: flex; gap: 10px; }
.game-controls button { flex: 1; }

.hint-inline { margin: 2px 0 0; font-size: .8rem; color: var(--muted); line-height: 1.4; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 12px 18px; border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); z-index: 50; max-width: 90%;
}

/* ---- Schachbrett / Damebrett ---- */
.board8 {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
  container-type: inline-size; /* Figurengroesse skaliert mit der Brettbreite */
}
.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  font-size: 9cqw;   /* ~72% der Feldbreite, unabhaengig vom Viewport */
  line-height: 1;
}

/* Achsenbeschriftung (1-8 links, a-h unten) neben dem Brett */
.board-wrap {
  display: grid;
  grid-template-columns: 1.5em 1fr;
  grid-template-rows: auto 1.5em;
  width: 100%;
}
.board-wrap > .board8 { grid-column: 2; grid-row: 1; }
.rank-axis { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; }
.file-axis { grid-column: 2; grid-row: 2; display: flex; }
.axis-cell {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.sel { box-shadow: inset 0 0 0 4px var(--select); }
.sq.target::after {
  content: ""; position: absolute; width: 30%; height: 30%;
  border-radius: 50%; background: rgba(111,208,140,.85);
}
.sq.target.occupied::after {
  width: 86%; height: 86%; background: transparent;
  border: 5px solid rgba(111,208,140,.85);
}
.sq.lastmove { box-shadow: inset 0 0 0 4px rgba(79,140,255,.6); }
.sq.check { box-shadow: inset 0 0 0 4px var(--danger); }
/* Beim letzten Zug geschlagenes Feld (Dame): rotes Kreuz */
.sq.captured::before {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  font-size: 6cqw;
  font-weight: 800;
  pointer-events: none;
}

.chess-piece.white { color: var(--piece-light); text-shadow: 0 1px 2px #000, 0 0 2px #000; }
.chess-piece.black { color: var(--piece-dark); text-shadow: 0 1px 1px rgba(255,255,255,.3); }

/* Ein-Gerät-Modus: Figuren des gegenübersitzenden Spielers zeigen zu ihm (analog). */
.chess-piece.flip, .disc.flip { transform: rotate(180deg); }

/* Dame-Steine */
.disc {
  width: 72%; height: 72%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.35), 0 2px 3px rgba(0,0,0,.4);
}
.disc.A { background: radial-gradient(circle at 35% 30%, #fff, var(--piece-light)); }
.disc.B { background: radial-gradient(circle at 35% 30%, #555, var(--piece-dark)); }
.disc.king::after { content: "♛"; font-size: 1.1rem; color: rgba(0,0,0,.55); }
.disc.B.king::after { color: rgba(255,255,255,.7); }

/* ---- Muehle ---- */
#morris-svg { width: 100%; height: auto; display: block; touch-action: manipulation; }
.m-line { stroke: var(--muted); stroke-width: 3; }
.m-spot { fill: var(--panel-2); stroke: var(--muted); stroke-width: 2; cursor: pointer; }
.m-spot.target { fill: var(--highlight); }
.m-spot.removable { fill: var(--danger); }
.m-piece { stroke: rgba(0,0,0,.4); stroke-width: 2; cursor: pointer; }
.m-piece.A { fill: var(--piece-light); }
.m-piece.B { fill: var(--piece-dark); }
.m-piece.sel { stroke: var(--select); stroke-width: 5; }
/* Letzter Zug: Ziel (Halo), Herkunft (gestrichelt), entfernter Stein (rotes Kreuz) */
.m-last-dest { fill: none; stroke: var(--accent); stroke-width: 5; pointer-events: none; }
.m-last-from { fill: none; stroke: var(--accent); stroke-width: 4; stroke-dasharray: 5 5; pointer-events: none; }
.m-last-removed { stroke: var(--danger); stroke-width: 5; stroke-linecap: round; pointer-events: none; }

/* ---- Konto / Auth ---- */
.account {
  background: var(--panel);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.account-info { font-size: 1rem; }
.account:has(.account-info) {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-actions { display: flex; gap: 10px; }
.auth-actions button { flex: 1; }
.auth-hint { margin: 0; font-size: .8rem; color: var(--muted); line-height: 1.4; }
/* Normales Textfeld (ohne die grosse Sperrschrift des Code-Feldes) */
.text-input {
  font-size: 1rem;
  letter-spacing: normal;
  text-align: left;
  padding: 12px 14px;
}

/* ---- Navigation / Tabs ---- */
.nav-row { display: flex; gap: 10px; margin-top: 4px; }
.nav-row button { flex: 1; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: .9rem;
}
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ---- Rangliste ---- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 8px; text-align: center; }
.table th { color: var(--muted); font-size: .8rem; font-weight: 600; border-bottom: 1px solid var(--panel-2); }
.table td:nth-child(2), .table th:nth-child(2) { text-align: left; }
.table tbody tr { border-bottom: 1px solid rgba(255,255,255,.05); }
.table tbody tr.me { background: rgba(79,140,255,.15); }

/* ---- Verlauf ---- */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item { background: var(--panel); border-radius: 12px; padding: 12px 14px; }
.hi-top { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.hi-players { font-size: 1.05rem; margin-bottom: 2px; }
.hi-result { font-size: .95rem; }

.badge {
  display: inline-block;
  background: var(--accent-2);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  vertical-align: middle;
}
.muted { color: var(--muted); }
