:root {
  --green: #2dbe64;
  --berry: #d7144b;
  --graphite: #333333;
  --bg: #fafafa;
  --surface: #ffffff;
  --line: #e4e4e4;
  --muted: #8a8a8a;
  --radius: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 20px;
  background: var(--bg);
  color: var(--graphite);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.app { width: 100%; max-width: 420px; }

/* --- Экраны --- */
.screen { display: none; animation: fade 0.2s var(--ease); }
.screen.is-active { display: block; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.title {
  margin: 0 0 24px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
}
.title--sm { font-size: 22px; margin-bottom: 16px; }

/* --- Карточка / форма --- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field { display: flex; flex-direction: column; gap: 8px; }
.field__label { font-size: 13px; color: var(--muted); }
.field-error { margin: -2px 0 0; font-size: 13px; color: var(--berry); }

input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s var(--ease);
}
input[type="text"]:focus { border-color: var(--graphite); }
input[type="text"].is-invalid { border-color: var(--berry); }

/* --- Сегментированный переключатель --- */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  text-align: center;
  padding: 8px 6px;
  font-size: 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.segmented input:checked + span { background: var(--graphite); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--berry); outline-offset: 1px; }

/* --- Кнопки --- */
.btn {
  font: inherit;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s var(--ease), transform 0.05s var(--ease), border-color 0.15s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--berry); color: #fff; }
.btn--primary:hover { background: #bf1043; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--graphite); }
.btn--ghost:hover { border-color: var(--graphite); }
.btn--link {
  background: none; border: none; color: var(--muted);
  padding: 6px; text-decoration: underline; text-underline-offset: 3px;
}
.btn--link:hover { color: var(--graphite); }

.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

/* --- Экран игры --- */
.game-head { text-align: center; margin-bottom: 16px; }
.turn { font-size: 16px; color: var(--muted); }
.mark { font-weight: 700; }
.mark--x { color: var(--berry); }
.mark--o { color: var(--green); }

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--graphite);
  padding: 8px;
  border-radius: var(--radius);
}

.cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  font-size: clamp(40px, 16vw, 64px);
  font-weight: 700;
  line-height: 1;
  color: var(--graphite);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s var(--ease);
}
.cell:disabled { cursor: default; }
.cell.is-x { color: var(--berry); }
.cell.is-o { color: var(--green); }

.cell .glyph {
  display: inline-block;
  animation: pop 0.16s var(--ease);
}
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Подсказка при наведении на пустую клетку */
.cell.hint-x:not(:disabled):hover::after { content: "X"; color: var(--berry); opacity: 0.25; }
.cell.hint-o:not(:disabled):hover::after { content: "O"; color: var(--green); opacity: 0.25; }

/* Выигрышная линия */
.cell.is-win { background: var(--berry); color: #fff; animation: pulse 0.9s var(--ease) infinite alternate; }
@keyframes pulse {
  from { box-shadow: inset 0 0 0 0 rgba(255,255,255,0); }
  to   { box-shadow: inset 0 0 0 3px rgba(255,255,255,0.55); }
}

.banner {
  margin: 16px 0 0;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
}

.scoreboard {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 16px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
}

/* --- Лидерборд --- */
.lb-status { font-size: 14px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.lb-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb-table th, .lb-table td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--line); }
.lb-table th { color: var(--muted); font-weight: 500; }
.lb-table td:nth-child(2) { text-align: left; font-weight: 600; }
.lb-table tbody tr:last-child td { border-bottom: none; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
