/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #4f46e5;
  --accent-dark: #3730a3;
  --accent-light: #e0e7ff;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --yellow: #ca8a04;
  --yellow-light: #fef9c3;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ── App shell ────────────────────────────────────────────── */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Header ───────────────────────────────────────────────── */
.app-header {
  background: var(--accent);
  color: white;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}
.app-header h1 { font-size: 1rem; font-weight: 700; flex: 1; }
.tab-btn {
  background: transparent;
  border: 1.5px solid rgba(255,255,255,.5);
  color: white;
  padding: .35rem .8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  transition: background .15s;
}
.tab-btn.active { background: rgba(255,255,255,.2); border-color: white; }
.tab-btn:hover:not(.active) { background: rgba(255,255,255,.1); }

/* ── Notice banner ────────────────────────────────────────── */
.notice {
  padding: .6rem 1rem;
  font-size: .9rem;
  text-align: center;
}
.notice.success { background: var(--green-light); color: var(--green); }
.notice.error   { background: var(--red-light);   color: var(--red); }
.notice.info    { background: var(--accent-light); color: var(--accent-dark); }

/* ── Cards & containers ───────────────────────────────────── */
.page { flex: 1; padding: 1rem; max-width: 720px; margin: 0 auto; width: 100%; }
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  transition: opacity .15s, background .15s;
  min-height: 44px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: var(--gray-200); color: var(--gray-900); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-300); }
.btn-danger  { background: var(--red-light); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: #fca5a5; }
.btn-success { background: var(--green-light); color: var(--green); }
.btn-success:hover:not(:disabled) { background: #86efac; }
.btn-sm { padding: .4rem .75rem; font-size: .8rem; min-height: 36px; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  padding: .4rem; border-radius: var(--radius);
  font-size: 1rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; min-height: 36px;
  transition: background .15s;
}
.btn-icon:hover { background: var(--gray-100); }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: .9rem; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; color: var(--gray-700); }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  background: white;
  color: var(--gray-900);
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; cursor: pointer; }
.form-check input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* ── Row actions ──────────────────────────────────────────── */
.row-actions { display: flex; gap: .35rem; align-items: center; }

/* ── Table ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; padding: .55rem .75rem; background: var(--gray-100); border-bottom: 1.5px solid var(--gray-200); font-weight: 700; color: var(--gray-700); white-space: nowrap; }
td { padding: .55rem .75rem; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
tr:last-child td { border-bottom: none; }

/* ── Tags/pills ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red   { background: var(--red-light);   color: var(--red); }
.badge-gray  { background: var(--gray-200);    color: var(--gray-700); }

/* ── Admin nav ────────────────────────────────────────────── */
.admin-nav {
  display: flex;
  gap: .35rem;
  padding: .75rem 1rem;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
}
.admin-nav-btn {
  padding: .45rem .9rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--gray-200);
  background: white;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-700);
  transition: all .15s;
}
.admin-nav-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ── Pupil game area ──────────────────────────────────────── */
.game-topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 52px;
  z-index: 9;
}
.score-display {
  font-size: .95rem;
  font-weight: 700;
  color: var(--accent);
  flex: 1;
}
.timer-display {
  font-size: .95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 3rem;
  text-align: right;
}
.timer-display.warning { color: var(--red); }

.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* Sentence placeholder */
.sentence-zone {
  min-height: 80px;
  background: white;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: .75rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-content: flex-start;
  transition: border-color .15s;
}
.sentence-zone.has-tiles { border-style: solid; border-color: var(--gray-200); }
.sentence-zone-label {
  color: var(--gray-500);
  font-size: .85rem;
  width: 100%;
}

/* Word bank */
.word-bank {
  background: var(--gray-100);
  border-radius: var(--radius);
  padding: .75rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  min-height: 60px;
}

/* Tiles */
.tile {
  display: inline-flex;
  align-items: center;
  padding: .5rem .85rem;
  background: white;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.2;
  min-height: 44px;
  transition: background .12s, border-color .12s, transform .1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tile:hover { background: var(--accent-light); border-color: var(--accent); }
.tile:active { transform: scale(.96); }
.tile.placed { background: var(--accent-light); border-color: var(--accent); }

/* Hint blink animations */
@keyframes blink-green {
  0%, 100% { background: white; border-color: var(--gray-300); }
  50%       { background: var(--green-light); border-color: var(--green); }
}
@keyframes blink-red {
  0%, 100% { background: white; border-color: var(--gray-300); }
  50%       { background: var(--red-light); border-color: var(--red); }
}
.tile.hint-green { animation: blink-green .5s ease 3; }
.tile.hint-red   { animation: blink-red .4s ease 6; }

@media (prefers-reduced-motion: reduce) {
  .tile.hint-green, .tile.hint-red { animation: none; }
  .tile.hint-green { background: var(--green-light); border-color: var(--green); }
  .tile.hint-red   { background: var(--red-light);   border-color: var(--red); }
}

/* Swap-pending tile (blinking border, waiting for replacement) */
@keyframes blink-swap {
  0%, 100% { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
  50%       { border-color: var(--accent-dark); box-shadow: 0 0 0 4px var(--accent-light); }
}
.tile.tile-swap {
  animation: blink-swap .5s ease-in-out infinite;
  border-color: var(--accent);
}
@media (prefers-reduced-motion: reduce) {
  .tile.tile-swap { animation: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
}

/* Result feedback */
.result-banner {
  padding: 1rem;
  border-radius: var(--radius);
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
}
.result-banner.correct { background: var(--green-light); color: var(--green); }
.result-banner.wrong   { background: var(--red-light);   color: var(--red); }
.result-banner.timeout { background: var(--yellow-light); color: var(--yellow); }

/* Action buttons row */
.game-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: center;
}
.game-actions .btn { flex: 1; min-width: 100px; max-width: 200px; }

/* Name entry screen */
.name-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.name-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.name-card h2 { font-size: 1.3rem; margin-bottom: .5rem; color: var(--gray-900); }
.name-card p  { font-size: .9rem; color: var(--gray-500); margin-bottom: 1.5rem; }

/* Login screen */
.auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}
.auth-card h2 { font-size: 1.25rem; margin-bottom: 1.25rem; text-align: center; }

/* Tile editor */
.tile-editor {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .75rem;
  background: var(--gray-100);
  border-radius: var(--radius);
  min-height: 54px;
  margin-bottom: .5rem;
  align-items: center;
}
.tile-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .6rem;
  background: white;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9rem;
  cursor: default;
}
.tile-chip input {
  border: none;
  background: transparent;
  font-size: .9rem;
  font-family: var(--font);
  width: 6ch;
  min-width: 4ch;
  max-width: 20ch;
  color: var(--gray-900);
  outline: none;
}
.tile-chip input:focus { border-bottom: 1.5px solid var(--accent); }
.tile-chip .remove-tile {
  background: none; border: none; cursor: pointer;
  color: var(--gray-500); font-size: .8rem; padding: 0 2px;
  line-height: 1; transition: color .12s;
}
.tile-chip .remove-tile:hover { color: var(--red); }

/* Filters row */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1rem;
  align-items: flex-end;
}
.filter-row .form-input,
.filter-row .form-select { width: auto; flex: 1; min-width: 120px; }

/* Misc */
.text-muted { color: var(--gray-500); font-size: .85rem; }
.text-sm    { font-size: .85rem; }
.font-mono  { font-family: monospace; }
.gap-1  { gap: .25rem; }
.mb-1   { margin-bottom: .25rem; }
.mb-2   { margin-bottom: .5rem; }
.mb-4   { margin-bottom: 1rem; }
.flex   { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.spin::after {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Share link badge (pupil name screen) ─────────────────── */
.share-set-badge {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent-dark);
  border-radius: 99px;
  padding: .3rem .9rem;
  font-size: .85rem;
  font-weight: 700;
  margin-bottom: .75rem;
}

/* ── Share button ─────────────────────────────────────────── */
.share-btn { color: var(--accent-dark); }

/* ── Help nav button ──────────────────────────────────────── */
.admin-nav-help {
  font-weight: 800;
  font-size: 1rem;
  min-width: 36px;
  padding: .45rem .7rem;
  border-radius: 50%;
  line-height: 1;
}

/* ── Help page ────────────────────────────────────────────── */
.help-page { max-width: 680px; }

.help-hero {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  color: white;
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.5rem;
}
.help-hero-icon { font-size: 2.5rem; line-height: 1; flex-shrink: 0; }
.help-title  { font-size: 1.25rem; font-weight: 800; margin-bottom: .2rem; }
.help-subtitle { font-size: .9rem; opacity: .85; }

.help-section {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: .75rem;
}
.help-section-last { margin-bottom: 2rem; }

.help-h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}
.help-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 800;
  flex-shrink: 0;
}

.help-section p { font-size: .9rem; color: var(--gray-700); line-height: 1.6; margin-bottom: .5rem; }
.help-section p:last-child { margin-bottom: 0; }

.help-ol, .help-ul {
  font-size: .9rem;
  color: var(--gray-700);
  line-height: 1.7;
  padding-left: 1.4rem;
}
.help-ol li, .help-ul li { margin-bottom: .2rem; }

.help-table-wrap { overflow-x: auto; margin-top: .25rem; }
.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.help-table th {
  text-align: left;
  padding: .5rem .75rem;
  background: var(--gray-100);
  border-bottom: 1.5px solid var(--gray-200);
  font-weight: 700;
  color: var(--gray-700);
  white-space: nowrap;
}
.help-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: top;
  color: var(--gray-700);
}
.help-table tr:last-child td { border-bottom: none; }
.help-table-mono td:first-child, .help-table-mono td:nth-child(2) {
  font-family: monospace;
  font-size: .8rem;
  white-space: nowrap;
}

.help-example {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  margin-top: .75rem;
  padding: .6rem .75rem;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}
.help-chip {
  display: inline-flex;
  align-items: center;
  padding: .3rem .65rem;
  background: white;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
}
.help-chip-merged {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
}
.help-arrow { color: var(--gray-500); font-size: 1.1rem; }

.help-badge {
  display: inline-block;
  padding: .1rem .45rem;
  border-radius: 99px;
  font-size: .8rem;
  font-weight: 700;
}
.help-badge-green { background: var(--green-light); color: var(--green); }
.help-badge-red   { background: var(--red-light);   color: var(--red); }

/* ── Sentence list (admin Предложения section) ────────────── */
.sentence-list { display: flex; flex-direction: column; gap: .6rem; }
.sentence-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.sentence-card-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1.5;
}
.sentence-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
  .app-header { padding: 0 .75rem; }
  .app-header h1 { font-size: .9rem; }
  .game-area { padding: .75rem; }
  .tile { font-size: .9rem; padding: .45rem .7rem; }
  .page { padding: .75rem; }
  .filter-row .form-input, .filter-row .form-select { min-width: 100px; }
}
