:root {
  --bg: #1b1b1b;
  --bg-soft: #1f1f1f;
  --card-bg: #242424;
  --card-hover: #2a2a2a;
  --border-color: #333333;
  --text: #ffffff;
  --text-muted: #8e8e93;
  --accent: #8354f7;
  --accent-hover: #9b72f9;
  --accent-tint: rgba(131, 84, 247, 0.12);
  --up: #34c759;
  --down: #ff3b30;
  --radius: 8px;
  --radius-lg: 10px;
  --btn-radius: 6px;
  --font: "Montserrat", "Codec Pro", system-ui, -apple-system, sans-serif;
  --brand-gradient: linear-gradient(135deg, #8354f7, #9b72f9);
}

[data-theme="light"] {
  --bg: #f4f4f6;
  --bg-soft: #ececf0;
  --card-bg: #ffffff;
  --card-hover: #efeff2;
  --border-color: #e2e2e7;
  --text: #1c1c1e;
  --text-muted: #6b6b72;
  --up: #1f9d49;
  --down: #e02424;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  width: 100%;
  max-width: 520px;
  padding: 28px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app__head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--brand-gradient);
  color: #fff;
  display: grid;
  place-items: center;
}

.brand svg {
  width: 24px;
  height: 24px;
}

.app__title {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
}

.app__sub {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 5px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.tab {
  flex: 1;
  min-height: 42px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  background: var(--card-hover);
  color: var(--text);
}

.tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.score {
  display: flex;
  gap: 12px;
}

.score__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 14px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.score__item--mid,
.score__item--right {
  align-items: center;
}

.score__item--right {
  align-items: flex-end;
}

.score__label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.score__value {
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* Board ------------------------------------------------------------------ */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: min(100%, calc(var(--avail) * 1));
  min-width: 240px;
  margin-inline: auto;
  aspect-ratio: 1 / 1;
}

.cell {
  display: grid;
  place-items: center;
  padding: 0;
  aspect-ratio: 1;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: clamp(2rem, 10vmin, 3.4rem);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    transform 0.15s ease;
}

.cell:hover:not(:disabled) {
  background: var(--card-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.cell:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.cell:disabled {
  cursor: default;
}

.cell.mark-x {
  color: var(--accent-hover);
}

.cell.mark-o {
  color: var(--up);
}

.cell.is-win {
  background: var(--accent-tint);
  border-color: var(--accent);
}

/* Aktionen --------------------------------------------------------------- */
.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.status {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.status strong {
  color: var(--accent-hover);
}

.actions__buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  min-height: 46px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease,
    border-color 0.2s ease;
}

.btn--primary {
  background: var(--accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text);
}

.btn--ghost:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.app__foot {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Zurück zur Spielhalle -------------------------------------------------- */
.backlink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  width: fit-content;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  transition: color 0.2s ease;
}

.backlink svg {
  width: 16px;
  height: 16px;
}

.backlink:hover {
  color: var(--accent-hover);
}

.backlink:focus-visible {
  outline: none;
  color: var(--accent-hover);
}


/* Vollbild-/Fokusmodus (mobile) --------------------------------------- */
:root {
  --avail: calc(100svh - 480px);
}

html.is-fs {
  --avail: calc(100dvh - 240px);
}
