/* TakeFour - pures CSS, kein Framework, kein Build-Schritt. */

:root {
  color-scheme: light dark;

  --bg: #f5f3ed;
  --surface: #fffdf8;
  --surface-2: #efece3;
  --ink: #1b1a18;
  --muted: #6d6a63;
  --line: #e0dbd0;
  --board: #363b45;
  --board-edge: #262a32;
  --hole: #f5f3ed;
  --p1: #3a6ddc;
  --p2: #ef9c2e;
  --p1-ink: #fff;
  --danger: #b23c2e;

  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 8px 24px -12px rgb(0 0 0 / 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f26;
    --surface-2: #23272f;
    --ink: #eceae4;
    --muted: #9b978f;
    --line: #2d323b;
    --board: #262b34;
    --board-edge: #1a1e25;
    --hole: #14161a;
    --p1: #6f9dff;
    --p2: #ffb659;
    --p1-ink: #0d1220;
    --danger: #e3705f;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px -14px rgb(0 0 0 / 0.7);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.page {
  width: min(100%, 40rem);
  margin-inline: auto;
  padding: clamp(1rem, 4vw, 2rem) clamp(1rem, 4vw, 1.5rem) 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* --- Kopfzeile ---------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.wordmark {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0;
  text-decoration: none;
  color: inherit;
}

.wordmark span { color: var(--p2); }

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- Karten ------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1rem, 3.5vw, 1.4rem);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.card h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* --- Bedienelemente ----------------------------------------------------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.7rem 1.1rem;
  min-height: 44px;
  font: inherit;
  font-weight: 550;
  color: var(--ink);
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.06s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) { background: var(--line); }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--p1);
  color: var(--p1-ink);
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--p1); }

.btn-quiet {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.btn-quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn-danger { color: var(--danger); }

:where(.btn, input, a):focus-visible {
  outline: 2px solid var(--p1);
  outline-offset: 2px;
}

.row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.row > .grow { flex: 1 1 8rem; }

input[type="text"] {
  font: inherit;
  min-height: 44px;
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* --- Spielbrett --------------------------------------------------------- */

.board-wrap {
  /* Auf schmalen und flachen Displays soll das Brett ohne Scrollen sichtbar bleiben. */
  width: min(100%, max(16rem, min(30rem, calc((100dvh - 21rem) * 7 / 6))));
  margin-inline: auto;
}

.board {
  --gap: clamp(4px, 1.4vw, 9px);
  position: relative;
  display: grid;
  padding: var(--gap);
  border-radius: calc(var(--radius) + 4px);
  background: var(--board);
  border: 1px solid var(--board-edge);
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.board-grid,
.board-columns {
  grid-area: 1 / 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--gap);
}

.cell {
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--hole);
  box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.35);
  display: grid;
  place-items: center;
}

.disc {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

/* Spieler 1: volle Scheibe. Spieler 2: Ring. Die Form unterscheidet die beiden auch dann,
   wenn die Farben nicht unterscheidbar sind (Farbfehlsichtigkeit, Graustufen-Ausdruck). */
.disc-1 { background: var(--p1); }

.disc-2 { background: var(--p2); }

/* Prozentwerte statt fester Groessen: der Ring bleibt in jeder Brettgroesse gleich kraeftig. */
.disc-2::after {
  content: '';
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  background: var(--hole);
}

/* Der frisch gefallene Stein. --drop = Anzahl der Reihen, die er faellt. */
.disc-dropping {
  animation: drop 340ms cubic-bezier(0.34, 0.62, 0.4, 1);
}

@keyframes drop {
  from { transform: translateY(calc(-1 * var(--drop, 6) * (100% + var(--gap)))); }
  to { transform: translateY(0); }
}

.cell-last { box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.35), 0 0 0 2px var(--surface); }

.cell-winning .disc {
  animation: pulse 1.4s ease-in-out infinite;
  outline: 3px solid var(--surface);
  outline-offset: -3px;
}

@keyframes pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

/* Ganze Spalte als Tap-Flaeche - deutlich groesser als ein einzelnes Feld. */
.column-button {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  min-height: 100%;
}

.column-button:disabled { cursor: default; }

.board:not(.board-locked) .column-button:hover:not(:disabled),
.board:not(.board-locked) .column-button:focus-visible {
  background: rgb(255 255 255 / 0.08);
}

/* Vorschau: wo landet der Stein? */
.cell-hint .disc-ghost {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  opacity: 0.28;
}

.ghost-1 { background: var(--p1); }
.ghost-2 { background: var(--p2); }

@media (prefers-reduced-motion: reduce) {
  .disc-dropping, .cell-winning .disc { animation: none; }
}

/* --- Wer spielt gegen wen ----------------------------------------------- */

.players {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

.players[hidden] { display: none; }

.player-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  font-weight: 550;
}

.player-tag > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-tag .token-chip {
  width: 1.1rem;
  height: 1.1rem;
}

.versus {
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- Statuszeile -------------------------------------------------------- */

.status {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-height: 2.75rem;
}

.status-text {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status-sub {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.token-chip {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
}

/* Auf der Karte ist der Ring nicht ausgestanzt, sondern in Kartenfarbe gefuellt. */
.token-chip.disc-2::after { background: var(--surface); }

/* --- Einladungscode ----------------------------------------------------- */

.invite-code {
  font-size: clamp(1.7rem, 9vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
  padding: 0.5rem 0 0.2rem 0.22em;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* --- Kleinkram ---------------------------------------------------------- */

.notice {
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.notice-error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  color: var(--danger);
}

.notice[hidden] { display: none; }

details.share {
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}

details.share summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 28px;
}

.link-box {
  margin-top: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.link-box code {
  display: block;
  padding: 0.6rem 0.7rem;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 0.8rem;
  word-break: break-all;
  border: 1px solid var(--line);
}

.game-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-list a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  min-height: 44px;
}

.game-list a:hover { background: var(--surface-2); }

.game-list .meta {
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--muted);
}

.footnote {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
