:root {
  --cell-font-weight: 700;
  --cell-font-size: 1.5rem;
  --grid-max-px: 540px;
  --cell-gap: 3px;
  --cell-radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f5;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
}

body.on-landing,
body.on-settings {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  align-items: flex-start;
}

body.on-landing { padding: 12px; }

body.on-settings {
  padding: 22px 28px;
}

/* ─── LANDING SCREEN ─── */
#screen-landing {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  padding: 16px 18px 16px;
  width: 100%;
  max-width: 560px;
  max-height: 100%;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.lang-btn.landing-lang {
  top: 18px;
  right: 18px;
  z-index: 4;
}

/* On phones/tablets the tagline sits right under the title: lift the
   language button so it doesn't touch the text */
@media (max-width: 1024px) {
  .lang-btn.landing-lang { top: 13px; }
}
@media (max-width: 600px) {
  .lang-btn.landing-lang { top: 5px; }
}

.demo-grid.demo-5 { grid-template-columns: repeat(5, 1fr); }
.landing-demo .demo-cell {
  aspect-ratio: auto;
  font-size: clamp(.7rem, 2.4vmin, 1.15rem);
}
.landing-demo .demo-dot {
  display: block;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
}

.landing-title {
  text-align: center;
  font-size: clamp(1.3rem, 4vmin, 1.7rem);
  font-weight: 700;
  color: #222;
  margin: 0 48px 6px;
  flex-shrink: 0;
}

.landing-tagline {
  text-align: center;
  font-size: clamp(.88rem, 2.4vmin, 1rem);
  line-height: 1.35;
  color: #555;
  margin: 0 auto 12px;
  max-width: 420px;
  flex-shrink: 0;
}

#screen-landing .btn-train {
  margin: 12px auto 0;
  flex-shrink: 0;
}

.landing-secondary {
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 10px;
  flex-shrink: 0;
}
.landing-link {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  max-width: 180px;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #cfdfcf;
  border-radius: 9px;
  background: #f7fbf7;
  color: #2e7d32;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.landing-link:hover { background: #edf7ed; border-color: #b5cfb7; }
.landing-link:focus-visible { outline: 3px solid rgba(46, 125, 50, .22); outline-offset: 2px; }

.landing-desc {
  color: #444;
  font-size: .94rem;
  line-height: 1.45;
}

.landing-desc p {
  margin-bottom: 10px;
}
.landing-desc p:last-child { margin-bottom: 0; }

.btn-train {
  display: block;
  width: 200px;
  margin: 20px auto 0;
  padding: 14px 0;
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-train:hover { background: #218838; }

/* ─── ABOUT SCREEN ─── */
#screen-about {
  display: none; /* shown by JS */
  background: #fff;
  border-radius: 12px;
  padding: 20px 36px 28px;
  width: 100%;
  max-width: 680px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

/* ─── ABOUT CAROUSEL ─── */
.about-carousel {
  position: relative;
  width: 100%;
  margin-top: 16px;
}
.about-viewport {
  overflow: hidden;
  border-radius: 18px;
  outline: none;
  touch-action: pan-y;
  cursor: grab;
}
.about-viewport.is-dragging { cursor: grabbing; }
.about-viewport:focus-visible {
  box-shadow: 0 0 0 3px rgba(46, 125, 50, .25);
}
.about-track {
  display: flex;
  transition: transform .45s cubic-bezier(.22, .61, .36, 1);
  will-change: transform;
}
.about-slide {
  --accent: #2e7d32;
  --accent-soft: #e8f5e9;
  --accent-glow: rgba(46, 125, 50, .16);
  position: relative;
  flex: 0 0 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 26px;
  align-items: center;
  padding: 30px 30px 28px;
  min-height: 360px;
  background: linear-gradient(135deg, var(--accent-soft) 0%, #fff 58%, #fff 100%);
  border: 1px solid #e7eee7;
  border-radius: 18px;
  overflow: hidden;
}
.about-slide[data-visual="benefits"] {
  --accent: #0f766e;
  --accent-soft: #e6f7f4;
  --accent-glow: rgba(15, 118, 110, .15);
}
.about-slide[data-visual="practice"] {
  --accent: #b45309;
  --accent-soft: #fff4e5;
  --accent-glow: rgba(180, 83, 9, .14);
}
.about-slide[data-visual="formats"] {
  --accent: #15803d;
  --accent-soft: #e9f9ee;
  --accent-glow: rgba(21, 128, 61, .15);
}
.about-slide::before {
  content: '';
  position: absolute;
  top: -120px;
  right: -80px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow), transparent 68%);
  pointer-events: none;
}
.about-slide::after {
  content: '';
  position: absolute;
  bottom: -140px;
  left: -100px;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  opacity: .55;
  pointer-events: none;
}
.about-slide > * { position: relative; z-index: 1; }
.about-slide-num {
  position: absolute;
  top: 10px;
  right: 24px;
  z-index: 0;
  font-size: 4.8rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.06em;
  color: var(--accent);
  opacity: .08;
  pointer-events: none;
}
.about-copy { min-width: 0; }
.about-kicker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.about-kicker::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.about-slide h2 {
  font-size: 1.5rem;
  line-height: 1.18;
  letter-spacing: -.01em;
  color: #1d2b22;
  margin-bottom: 12px;
}
.about-body {
  color: #516258;
  font-size: .92rem;
  line-height: 1.65;
}
.about-body p + p { margin-top: 9px; }
.about-body b,
.about-body strong { color: #24352a; font-weight: 700; }
.about-steps {
  display: grid;
  gap: 7px;
  margin: 2px 0 0;
  padding-left: 1.15em;
}
.about-steps li { padding-left: 2px; }
.about-steps li::marker { color: var(--accent); font-weight: 700; }
.about-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}
.about-tags span {
  padding: 4px 9px;
  border: 1px solid rgba(0, 0, 0, .06);
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: #5d6d62;
  font-size: .7rem;
  font-weight: 600;
  white-space: nowrap;
}
.about-train:focus-visible { outline: 3px solid rgba(40, 167, 69, .35); outline-offset: 2px; }

/* Per-slide visual: a small table with a center dot */
.about-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}
.about-table-card {
  position: relative;
  z-index: 1;
  width: 190px;
  aspect-ratio: 1;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 18px;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 18px 35px -18px rgba(29, 43, 34, .35), 0 0 0 1px rgba(46, 125, 50, .05);
  transform: rotate(-3deg);
}
.about-table {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: 100%;
  height: 100%;
}
.about-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(31, 58, 41, .06);
  border-radius: 5px;
  background: rgba(255, 255, 255, .7);
  color: #6b7d70;
  font-size: .64rem;
  font-weight: 600;
  line-height: 1;
}
.about-cell.is-lit {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: 0 0 0 2px rgba(46, 125, 50, .07);
}
.about-table-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 11px;
  height: 11px;
  margin: -5.5px 0 0 -5.5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(46, 125, 50, .13), 0 0 0 12px rgba(46, 125, 50, .05);
}
.about-monogram {
  position: absolute;
  top: -14px;
  right: -36px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .04em;
  box-shadow: 0 8px 18px rgba(46, 125, 50, .25);
  transform: rotate(3deg);
}
.about-visual-practice::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 232px;
  height: 232px;
  border: 1px dashed rgba(180, 83, 9, .28);
  border-radius: 50%;
  transform: translate(-50%, -58%);
  pointer-events: none;
}
.about-sizes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
}
.about-sizes span {
  padding: 4px 7px;
  border: 1px solid var(--accent-soft);
  border-radius: 6px;
  background: rgba(255, 255, 255, .8);
  color: var(--accent);
  font-size: .66rem;
  font-weight: 700;
}
.about-visual-note {
  max-width: 205px;
  color: var(--accent);
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
}

.about-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 0 2px;
}
.about-dots { display: flex; align-items: center; gap: 7px; }
.about-dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: #cfdacf;
  cursor: pointer;
  transition: width .2s, background .2s;
}
.about-dot.active { width: 24px; background: #2e7d32; }
.about-nav { display: flex; align-items: center; gap: 8px; }
.about-count {
  min-width: 44px;
  color: #7a8a7e;
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.about-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid #d8e2d8;
  border-radius: 50%;
  background: #fff;
  color: #2e7d32;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.about-arrow:hover:not(:disabled) { background: #f2f8f2; border-color: #b9cdb9; }
.about-arrow:disabled { opacity: .35; cursor: default; }
.about-arrow:focus-visible,
.about-dot:focus-visible { outline: 2px solid #43a047; outline-offset: 2px; }

@media (max-width: 720px) {
  .about-carousel { margin-top: 10px; }
  .about-slide {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 22px 18px 20px;
    min-height: 0;
    border-radius: 16px;
  }
  .about-slide-num { top: 8px; right: 14px; font-size: 3.4rem; }
  .about-visual { order: -1; }
  .about-table-card { width: 150px; padding: 8px; }
  .about-cell { font-size: .56rem; }
  .about-slide h2 { font-size: 1.25rem; }
  .about-body { font-size: .88rem; }
  .about-monogram { top: -12px; right: -30px; width: 36px; height: 36px; font-size: .62rem; }
  .about-visual-practice::before { width: 188px; height: 188px; }
  .about-controls { margin-top: 10px; }
  .about-arrow { width: 38px; height: 38px; }
  .about-count { font-size: .72rem; }
}

@media (max-width: 600px) {
  .about-train { min-height: 48px; font-size: 1.05rem; }
}

/* ─── GUIDE CAROUSEL ─── */
.about-slide[data-visual="principle"] {
  --accent: #2e7d32;
  --accent-soft: #e8f5e9;
  --accent-glow: rgba(46, 125, 50, .16);
}
.about-slide[data-visual="glow"] {
  --accent: #b45309;
  --accent-soft: #fff4e5;
  --accent-glow: rgba(245, 183, 0, .2);
}
.about-slide[data-visual="dot"] {
  --accent: #0f766e;
  --accent-soft: #e6f7f4;
  --accent-glow: rgba(15, 118, 110, .15);
}
.about-slide[data-visual="records"] {
  --accent: #64748b;
  --accent-soft: #f1f5f9;
  --accent-glow: rgba(100, 116, 139, .15);
}
.about-slide[data-visual="finish"] {
  --accent: #15803d;
  --accent-soft: #e9f9ee;
  --accent-glow: rgba(21, 128, 61, .15);
}

.guide-visual-glow::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 230px;
  height: 230px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 183, 0, .2), transparent 70%);
  transform: translate(-50%, -58%);
  pointer-events: none;
}
.guide-target {
  position: relative;
  z-index: 2;
  border-color: #e0a800 !important;
  background: #fff8e1 !important;
  color: #8a5a00 !important;
  box-shadow: 0 0 0 3px rgba(245, 183, 0, .35), 0 0 18px rgba(245, 183, 0, .45) !important;
  animation: guideTargetPulse 1.8s ease-in-out infinite;
}
@keyframes guideTargetPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(245, 183, 0, .3), 0 0 14px rgba(245, 183, 0, .35); }
  50% { box-shadow: 0 0 0 5px rgba(245, 183, 0, .18), 0 0 24px rgba(245, 183, 0, .55); }
}
.guide-dot-chip {
  position: absolute;
  left: -14px;
  bottom: -12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .66rem;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(15, 118, 110, .22);
  transform: rotate(2deg);
}
.guide-steps {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  padding: 0;
  list-style: none;
}
.guide-steps li {
  position: relative;
  padding-left: 18px;
  color: #516258;
  font-size: .84rem;
  line-height: 1.45;
}
.guide-steps li::before {
  content: '✓';
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent);
  font-weight: 700;
}
.guide-records {
  display: grid;
  gap: 8px;
  width: 190px;
}
.guide-record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 13px;
  border: 1px solid #e4e9ef;
  border-radius: 12px;
  background: #f8fafc;
  color: #94a3b8;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.guide-record strong {
  color: #94a3b8;
  font-size: 1.15rem;
  font-weight: 700;
}
.guide-record-note {
  justify-self: start;
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef2f6;
  color: #64748b;
  font-size: .66rem;
  font-weight: 700;
  transform: rotate(-2deg);
}
.guide-finish {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 190px;
  min-height: 190px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 18px;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 18px 35px -18px rgba(29, 43, 34, .35), 0 0 0 1px rgba(21, 128, 61, .05);
  transform: rotate(-3deg);
}
.guide-finish-check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(21, 128, 61, .22);
}
.guide-finish strong {
  color: var(--accent);
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.05em;
}
.guide-finish-label {
  color: #516258;
  font-size: .75rem;
  font-weight: 600;
  text-align: center;
}

@media (max-width: 720px) {
  .guide-records,
  .guide-finish { width: 150px; }
  .guide-finish { min-height: 150px; padding: 12px; }
  .guide-finish strong { font-size: 2.6rem; }
  .guide-finish-check { width: 36px; height: 36px; font-size: 1rem; }
  .guide-record { padding: 10px 11px; font-size: .6rem; }
  .guide-record strong { font-size: 1rem; }
  .guide-dot-chip { left: -10px; bottom: -10px; padding: 5px 8px; font-size: .62rem; }
  .guide-steps li { font-size: .8rem; }
}
@media (prefers-reduced-motion: reduce) {
  .guide-target { animation: none; }
}

/* ─── CONTACTS SCREEN ─── */
#screen-contacts {
  display: none;
  width: 100%;
  max-width: 680px;
  padding: 24px 30px 26px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
.contacts-hero {
  position: relative;
  overflow: hidden;
  padding: 28px 30px 26px;
  border: 1px solid #dcebdc;
  border-radius: 18px;
  background: linear-gradient(135deg, #e8f5e9 0%, #f7fcf7 55%, #eaf4ff 100%);
}
.contacts-hero::before {
  content: '';
  position: absolute;
  top: -100px;
  right: -70px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(34, 158, 217, .15), transparent 70%);
}
.contacts-hero::after {
  content: '';
  position: absolute;
  bottom: -120px;
  left: -70px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(46, 125, 50, .12), transparent 70%);
}
.contacts-hero > * { position: relative; z-index: 1; }
.contacts-hero-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin-bottom: 16px;
  border-radius: 16px;
  background: #fff;
  color: #2e7d32;
  box-shadow: 0 10px 24px -14px rgba(46, 125, 50, .45);
}
.contacts-hero-icon svg { width: 26px; height: 26px; }
.contacts-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #e8f5e9;
  color: #2e7d32;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.contacts-eyebrow::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2e7d32;
}
.contacts-hero h1 {
  margin: 11px 0 8px;
  color: #1f2b22;
  font-size: 1.7rem;
  line-height: 1.15;
  letter-spacing: -.02em;
}
.contacts-hero p {
  max-width: 470px;
  color: #536458;
  font-size: .94rem;
  line-height: 1.6;
}
.contacts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
.contact-card {
  position: relative;
  display: flex;
  gap: 12px;
  min-width: 0;
  padding: 18px;
  border: 1px solid #e4ebe4;
  border-radius: 16px;
  background: #fff;
  color: inherit;
  text-decoration: none;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.contact-card:hover {
  transform: translateY(-2px);
  border-color: #cfdccf;
  box-shadow: 0 12px 28px -18px rgba(29, 43, 34, .35);
}
.contact-card:focus-visible { outline: 3px solid rgba(46, 125, 50, .25); outline-offset: 2px; }
.contact-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
}
.contact-icon svg { width: 20px; height: 20px; }
.contact-tg .contact-icon { background: #e8f6fd; color: #229ED9; }
.contact-email .contact-icon { background: #e8f5e9; color: #2e7d32; }
.contact-body { min-width: 0; padding-right: 14px; }
.contact-label {
  display: block;
  color: #7a8a7e;
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.contact-value {
  display: block;
  margin: 3px 0 5px;
  color: #1f2b22;
  font-size: .92rem;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.contact-desc {
  display: block;
  color: #68776c;
  font-size: .77rem;
  line-height: 1.45;
}
.contact-arrow {
  position: absolute;
  top: 14px;
  right: 14px;
  color: #9aac9d;
  font-size: 1rem;
  line-height: 1;
  transition: color .15s, transform .15s;
}
.contact-card:hover .contact-arrow { color: #2e7d32; transform: translate(1px, -1px); }
.contact-tg:hover .contact-arrow { color: #229ED9; }
.contacts-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}
.contacts-back {
  flex: 0 0 auto;
  min-height: 50px;
  padding: 0 22px;
  border: 1px solid #cfd9cf;
  border-radius: 8px;
  background: #fff;
  color: #445;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.contacts-back:hover { background: #f5f9f5; border-color: #b9cbb9; }
.contacts-back:focus-visible { outline: 3px solid rgba(46, 125, 50, .25); outline-offset: 2px; }
.contacts-actions .btn-train {
  flex: 1 1 0;
  width: auto;
  max-width: 240px;
  min-height: 50px;
  margin: 0;
}

@media (max-width: 600px) {
  #screen-contacts { padding: 16px 16px 20px; border-radius: 14px; }
  .contacts-hero { padding: 22px 20px 20px; border-radius: 16px; }
  .contacts-hero h1 { font-size: 1.45rem; }
  .contacts-hero p { font-size: .88rem; }
  .contacts-hero-icon { width: 46px; height: 46px; border-radius: 13px; margin-bottom: 14px; }
  .contacts-hero-icon svg { width: 23px; height: 23px; }
  .contacts-grid { grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
  .contact-card { padding: 15px; }
  .contacts-actions { margin-top: 18px; }
  .contacts-actions .btn-train { min-height: 48px; font-size: 1.05rem; }
  .contacts-back { min-height: 48px; padding: 0 18px; }
}

/* ─── TRAINING GUIDE SCREEN ─── */
#screen-guide {
  display: none; /* shown by JS */
  background: #fff;
  border-radius: 12px;
  padding: 20px 36px 28px;
  width: 100%;
  max-width: 680px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.guide-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 6px;
}
.guide-header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  color: #222;
}
.guide-back {
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  color: #444;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.guide-back:hover { background: #f0f0f0; border-color: #aaa; }

.guide-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 28px;
  padding: 18px 0 20px;
  margin-bottom: 18px;
  border-bottom: 1px solid #eee;
}
/* Reset auto margins — as flex items they would eat the free space */
.guide-hero .demo-wrap,
.guide-hero .training-steps { margin: 0; }

/* ─── MINI DEMO (intro overlay + guide) ─── */
.demo-wrap {
  position: relative;
  width: 136px;
  flex-shrink: 0;
  margin: 0 auto 18px;
}
.demo-wrap.landing-demo {
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: 1;
  width: min(100%, calc(100dvh - 230px));
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
}
.landing-demo .demo-grid {
  width: 100%;
  height: 100%;
  grid-template-rows: repeat(5, 1fr);
}
.demo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.demo-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  font-size: .95rem;
  font-weight: 700;
  color: #1a1a1a;
  transition: background .2s, color .2s;
}
.demo-cell.found { background: #e8f5e9; color: #b3c6b5; }
.demo-cell.hint {
  animation: hint-pulse .7s ease-in-out infinite alternate;
  z-index: 2;
}
.demo-dot {
  position: absolute;
  top: 50%; left: 50%;
  width: 9px; height: 9px;
  margin: -4.5px 0 0 -4.5px;
  background: #28a745;
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
}

/* ─── TRAINING STEPS ─── */
.training-steps {
  list-style: none;
  text-align: left;
  max-width: 300px;
  margin: 0 auto 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.training-steps li {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: .95rem;
  line-height: 1.3;
  color: #444;
}
.step-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f8f2;
  border-radius: 50%;
  font-size: 1rem;
}

/* ─── SETTINGS LAYOUT (settings card + aside) ─── */
#settings-layout {
  display: none; /* shown by JS */
  align-items: stretch;
  gap: 0;
  width: min(560px, 100%);
  height: 100%;
  max-height: 100%;
}

#settings-aside {
  display: flex;
  align-items: flex-start;
  padding-top: 4px;
  padding-right: 12px;
}

.aside-btn {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 14px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  color: #444;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
  letter-spacing: .03em;
}
.aside-btn:hover { background: #f0f0f0; border-color: #aaa; }

@media (max-width: 560px) {
  #settings-aside { display: none; }
}

/* ─── SETTINGS SCREEN ─── */
#screen-settings {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  background: #fff;
  border-radius: 16px;
  padding: clamp(14px, 2.2vh, 26px) clamp(20px, 2.8vw, 28px) clamp(16px, 2.4vh, 28px);
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

.settings-top {
  flex: 0 0 auto;
  padding-top: 10px;
}

.settings-lower {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  gap: 8px;
  justify-content: space-between;
}
#screen-settings > .settings-lower { flex-shrink: 1; }
.settings-lower > * { flex-shrink: 0; }

/* Even distribution: the lower flex container supplies the spacing, so
   per-item margins must not make some gaps larger than others. */
.settings-lower > *,
.settings-lower #alpha-options .setting-group,
.settings-lower .settings-2col .setting-group {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Settings may scroll on short screens, but the scrollbar itself is hidden */
html.on-settings,
body.on-settings {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html.on-settings::-webkit-scrollbar,
body.on-settings::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

@media (max-width: 1024px) {
  #btn-appearance { margin-top: 18px; }
}

#screen-settings.has-alpha {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#screen-settings.has-alpha::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}
#screen-settings.has-alpha .save-setting-group {
  margin-top: 12px;
  margin-bottom: 4px;
}
/* Alphabetic mode has two extra rows: tighten the vertical rhythm so the
   Start button stays inside the screen instead of asking for a scroll. */
#screen-settings.has-alpha .setting-group,
#screen-settings.has-alpha .settings-2col .setting-group {
  margin-bottom: clamp(3px, .7vh, 7px);
}
#screen-settings.has-alpha #btn-start { margin-top: 6px; }

@media (max-width: 600px) {
  #screen-settings.has-alpha .setting-group,
  #screen-settings.has-alpha .settings-2col .setting-group {
    margin-bottom: 2px;
  }
  #screen-settings.has-alpha .save-setting-group {
    margin-top: 10px;
    margin-bottom: 2px;
  }
  #screen-settings.has-alpha #btn-start { margin-top: 4px; }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: clamp(14px, 2.4vh, 24px);
}

@media (min-width: 1025px) and (max-height: 740px) {
  .settings-header { margin-bottom: 12px; }
}

.settings-header h1 {
  font-size: clamp(1.05rem, 2.2vh, 1.3rem);
  font-weight: 600;
  color: #222;
}

.settings-home {
  position: absolute;
  left: 0;
}

.lang-btn {
  position: absolute;
  right: 0;
  padding: 5px 11px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  color: #444;
  transition: background .15s, border-color .15s;
}
.lang-btn:hover { background: #f0f0f0; border-color: #aaa; }

/* ─── TRAINING MODE SWITCH ─── */
.mode-switch {
  display: flex;
  justify-content: center;
  margin-bottom: clamp(6px, 1.2vh, 12px);
  padding: clamp(4px, 0.8vh, 8px) 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  transition: background .15s, border-color .15s;
  cursor: pointer;
  user-select: none;
}
.mode-switch:hover { border-color: #c5c5c5; }
.mode-switch.on:hover { border-color: #7fc98a; }
.mode-switch.on {
  background: #e8f5e9;
  border-color: #7fc98a;
}
.mode-switch .checkbox-label {
  font-size: 1rem;
  font-weight: 500;
  color: #444;
  width: 100%;
}
.mode-switch.on .checkbox-label { color: #1f7a35; }

/* Two mode switches side by side (Learning mode + Sprint) */
.mode-switch-row {
  display: flex;
  gap: 8px;
  padding-top: 16px;
  margin-bottom: clamp(6px, 1.2vh, 12px);
}
.mode-switch-row .mode-switch {
  flex: 1 1 0;
  min-width: 0;
  margin-bottom: 0;
}

/* Sprint mode tooltip (shown on hover / keyboard focus) */
#sprint-mode-row { position: relative; }
#sprint-mode-row .checkbox-label { padding-right: 32px; }
.sprint-direction {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #c8d6c9;
  border-radius: 6px;
  background: #fff;
  color: #2e7d32;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background .15s, border-color .15s;
}
.sprint-direction:hover,
.sprint-direction:focus-visible {
  background: #e8f5e9;
  border-color: #7fc98a;
  outline: none;
  box-shadow: 0 0 0 2px rgba(67, 160, 71, .22);
}
.mode-tooltip {
  display: none;
  position: absolute;
  top: 50%;
  right: calc(100% + 9px);
  left: auto;
  transform: translateY(-50%);
  width: max-content;
  max-width: min(240px, calc(100vw - 32px));
  padding: 8px 11px;
  background: #fff;
  color: #333;
  border: 1px solid #d8dee6;
  font-size: .78rem;
  font-weight: 400;
  line-height: 1.35;
  text-align: left;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .14);
  pointer-events: none;
  z-index: 20;
}
.mode-tooltip::before,
.mode-tooltip::after {
  content: '';
  position: absolute;
  top: 50%;
  border: solid transparent;
}
.mode-tooltip::before {
  right: -8px;
  margin-top: -7px;
  border-width: 7px;
  border-left-color: #d8dee6;
}
.mode-tooltip::after {
  right: -6px;
  margin-top: -6px;
  border-width: 6px;
  border-left-color: #fff;
}
@media (hover: hover) {
  #sprint-mode-row:hover .mode-tooltip {
    display: block;
  }
}

.setting-group {
  margin-bottom: clamp(4px, 1.1vh, 10px);
  text-align: center;
}

.setting-group label {
  display: block;
  font-size: clamp(.88rem, 1.8vh, 1.05rem);
  color: #555;
  margin-bottom: clamp(3px, 0.7vh, 8px);
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.btn-group button {
  padding: clamp(4px, 0.7vh, 7px) 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: clamp(.78rem, 1.5vh, .88rem);
  cursor: pointer;
  color: #333;
  transition: background .15s, border-color .15s;
}

.btn-group button:hover { background: #e8f5e9; border-color: #a5d6a7; }

/* Four table styles must stay on one row even on a phone */
#grp-style {
  flex-wrap: nowrap;
  gap: 4px;
  width: 100%;
}
#grp-style button {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 3px;
  font-size: 11px;
  line-height: 1.15;
  white-space: normal;
}
@media (min-width: 480px) {
  #grp-style button { white-space: nowrap; }
}
@media (max-width: 600px) {
  #grp-style button { font-size: 10.5px; }
}
.btn-group button.active {
  background: #e8f5e9;
  border-color: #43a047;
  color: #2e7d32;
  font-weight: 600;
}

/* The eight size buttons always stay in one row, even with several selected */
#grp-size {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
}
#grp-size button {
  min-width: 0;
  padding: 6px 0;
  font-size: clamp(.62rem, 2.6vw, .82rem);
  white-space: nowrap;
}

/* Sprint: several table sizes can stay selected at once */
#grp-size.sprint-on button.sprint-picked {
  background: #e8f5e9;
  border-color: #43a047;
  color: #2e7d32;
  font-weight: 600;
}
.sprint-size-hint {
  margin-top: 7px;
  font-size: .78rem;
  line-height: 1.3;
  color: #6b7280;
}

/* Locked settings (Gorbo disables style/order) */
.setting-group.locked {
  opacity: 0.38;
  pointer-events: none;
  user-select: none;
}

#alpha-options {
  display: none;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 16px;
  align-items: start;
}
#alpha-options > .setting-group { min-width: 0; }
#screen-settings.has-alpha #sg-size,
#screen-settings.has-alpha #sg-type {
  margin-bottom: clamp(4px, 1.1vh, 10px);
}
@media (max-width: 600px) {
  #screen-settings.has-alpha #sg-size,
  #screen-settings.has-alpha #sg-type {
    margin-bottom: 12px;
  }
}
#alpha-options .btn-group { gap: 4px; }
#alpha-options .btn-group button {
  padding: 6px 4px;
  font-size: 11.5px;
}

/* ─── SAVE CHECKBOX ─── */
.save-setting-group { margin-bottom: 8px; }

#screen-settings > * {
  flex-shrink: 0;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-size: .92rem;
  color: #555;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #28a745;
  cursor: pointer;
}

.appearance-open {
  width: 100%;
  padding: 9px 14px;
  background: #f4f4f4;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: .9rem;
  color: #444;
  cursor: pointer;
  transition: background .15s;
}
.appearance-open:hover { background: #eaeaea; }

/* ─── RANGE SLIDER ─── */
.size-slider {
  width: 100%;
  margin-top: 8px;
  accent-color: #28a745;
  cursor: pointer;
}

/* ─── 2-column grid for compact Yes/No toggles ─── */
.settings-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 28px;
  width: 100%;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}
.settings-2col .setting-group {
  margin-bottom: clamp(4px, 1.1vh, 10px);
}

#btn-start {
  display: block;
  width: 140px;
  margin: clamp(6px, 1vh, 12px) auto 0;
  padding: clamp(8px, 1.1vh, 11px) 0;
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
#btn-start:hover { background: #218838; }

/* ─── GAME SCREEN ─── */
#screen-game {
  --game-w: min(var(--grid-max-px), 100%);
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.game-header {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 680px;
  margin-bottom: 8px;
  gap: 8px;
}

.header-left {
  display: flex;
  gap: 6px;
  align-items: center;
}

#btn-back,
#btn-run {
  padding: 7px 14px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: .88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
  color: #333;
}
#btn-back:hover,
#btn-run:hover { background: #f0f0f0; }

/* Waiting for the player: the button is the obvious next step */
#btn-run.is-start {
  background: #28a745;
  border-color: #28a745;
  color: #fff;
  font-weight: 600;
}
#btn-run.is-start:hover { background: #218838; border-color: #218838; }

#btn-run:disabled { opacity: .45; cursor: default; }
#btn-run.is-start:disabled:hover { background: #28a745; border-color: #28a745; }

#btn-run.has-hint {
  position: relative;
}
#btn-run.has-hint::after {
  content: attr(data-hint);
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  width: max-content;
  max-width: 240px;
  padding: 8px 11px;
  background: #222;
  color: #fff;
  font-size: .78rem;
  font-weight: 400;
  line-height: 1.35;
  border-radius: 8px;
  white-space: normal;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 30;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  transition: opacity .15s, visibility .15s;
}
#btn-run.has-hint::before {
  content: '';
  position: absolute;
  left: 16px;
  top: calc(100% + 2px);
  border: 6px solid transparent;
  border-bottom-color: #222;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 31;
  transition: opacity .15s, visibility .15s;
}
#btn-run.has-hint:hover::after,
#btn-run.has-hint:hover::before {
  opacity: 1;
  visibility: visible;
}

.hdr-toggle {
  padding: 5px 10px;
  border: 1.5px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  color: #aaa;
  line-height: 1;
}
.hdr-toggle:hover { background: #f0f0f0; border-color: #bbb; color: #555; }
.hdr-toggle.on    { background: #e8f5e9; border-color: #28a745; color: #28a745; }
/* Help is not a toggle — it never lights up, so keep it readable */
.help-toggle      { color: #666; font-weight: 700; }
.dot-toggle.on    { background: #e8f5e9; border-color: #28a745; color: #28a745; }

/* ── Game Size Selector ─────────────────── */
#game-size-selector {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
}

.gs-btn {
  padding: 4px 9px;
  border: 1.5px solid #d0d8e8;
  border-radius: 20px;
  background: #fff;
  font-size: .75rem;
  font-weight: 500;
  color: #555;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .15s, border-color .15s, color .15s;
}

.gs-btn:hover {
  border-color: #7aabde;
  color: #2563c7;
  background: #eef4fd;
}

.gs-btn.active {
  background: #e8f5e9;
  border-color: #28a745;
  color: #28a745;
  font-weight: 700;
}

/* ── Game Stats Cards ───────────────────── */
.game-stats {
  display: flex;
  gap: 5px;
  width: 100%;
  max-width: 680px;
  margin-bottom: 10px;
}

.stat-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 5px;
  background: #fff;
  border: 1px solid #dbe8f8;
  border-radius: 8px;
  padding: 5px 8px;
  min-width: 0;
}

/* compact record cards */
.stat-card-rec {
  flex: 0.7;
  justify-content: center;
  gap: 4px;
}

.stat-label {
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #7aabde;
  white-space: nowrap;
  flex-shrink: 0;
}

.stat-value {
  font-size: .92rem;
  font-weight: 700;
  color: #2563c7;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-rec-icon { font-size: .8rem; flex-shrink: 0; }

.stat-card-rec.muted { opacity: .35; }

.stat-errors      { color: #e53935; }
.stat-best        { color: #28a745; }
.stat-best-shuffle{ color: #f59e0b; }

#timer { font-size: .92rem; font-weight: 700; color: #1a1a1a; }

#target-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: #2563c7;
}

#target-value[data-gorbo-color="black"] {
  color: #fff;
  background: #1a1a1a;
  border-radius: 6px;
  padding: 2px 10px;
}

#target-value[data-gorbo-color="red"] {
  color: #fff;
  background: #d32f2f;
  border-radius: 6px;
  padding: 2px 10px;
}

/* ─── GRID ─── */
.grid-wrapper {
  position: relative;
  width: var(--game-w);
  max-width: 100%;
  container-type: inline-size;
}

#grid {
  --grid-cols: 5;
  --grid-gap: var(--cell-gap);
  display: grid;
  width: 100%;
  gap: var(--grid-gap);
}

.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Grid items default to min-width:auto — on dense grids the text would
     then force the columns wider than the table */
  min-width: 0;
  min-height: 0;
  font-size: var(--cell-font-size);
  /* Dense grids on narrow screens: shrink the symbol to the cell width */
  font-size: min(var(--cell-font-size), calc((100cqw - (var(--grid-cols) - 1) * var(--grid-gap)) / var(--grid-cols) * .56));
  line-height: 1;
  font-weight: var(--cell-font-weight);
  cursor: pointer;
  user-select: none;
  border: 1px solid #ddd;
  border-radius: var(--cell-radius);
  background: #fff;
  transition: background .15s, transform .1s;
  color: #1a1a1a;
}
.cell:hover { background: #f8f8f8; transform: scale(1.04); }

/* Disable transitions during bulk shuffle so updates are instant */
#grid.shuffling .cell { transition: none !important; }

/* Pre-start: cells stay in place, only the symbols become unreadable.
   Cells stay clickable — a click on any of them starts the game. */
#grid.blurred .cell {
  color: transparent !important;
  text-shadow: 0 0 11px rgba(26, 26, 26, .6);
}
#grid.blurred .cell:hover { transform: none; }
#grid.blurred .cell.gorbo-bg-black,
#grid.blurred .cell.gorbo-bg-red {
  text-shadow: 0 0 11px rgba(255, 255, 255, .7);
}

#grid.style-rounded .cell { border-radius: 50%; }
#grid.style-colored .cell {
  border-color: transparent;
  border-radius: 8px;
  color: #1a1a1a;
}
#grid.style-colored-elements .cell {
  background: #fff;
  border-color: #ddd;
}

.cell.found {
  background: #e8f5e9 !important;
  color: #aaa !important;
  cursor: default;
  transform: none !important;
}


.cell.flash-green { background: #4caf50 !important; color: #fff !important; transform: scale(1.06); }
.cell.flash-red   { background: #f44336 !important; color: #fff !important; transform: scale(1.06); }

/* Correct answer on Gorbo / colored cells: golden glow, background untouched */
.cell.flash-gold {
  box-shadow:
    0 0 0 3px #FFC107,
    0 0 16px 5px rgba(255, 193, 7, .75) !important;
  transform: scale(1.06);
  z-index: 3;
}

/* Wrong answer on Gorbo / colored cells: shake only, colors untouched */
@keyframes cell-shake {
  0%        { transform: translateX(0); }
  15%       { transform: translateX(-6px); }
  35%       { transform: translateX(6px); }
  55%       { transform: translateX(-5px); }
  70%       { transform: translateX(4px); }
  85%       { transform: translateX(-2px); }
  100%      { transform: translateX(0); }
}
.cell.flash-shake {
  animation: cell-shake 0.38s ease;
}

/* ─── TRAINING MODE HINT ─── */
@keyframes hint-pulse {
  from {
    transform: scale(1);
    box-shadow:
      0 0 0 2px rgba(255, 214, 0, .85),
      0 0 10px 3px rgba(255, 214, 0, .45);
  }
  to {
    transform: scale(1.03);
    box-shadow:
      0 0 0 3px rgba(255, 214, 0, 1),
      0 0 18px 6px rgba(255, 214, 0, .7);
  }
}
.cell.hint {
  animation: hint-pulse .7s ease-in-out infinite alternate;
  z-index: 2;
}

/* Gorbo: black/red cells with white numbers */
.cell.gorbo-bg-black {
  background: #111 !important;
  color: #fff !important;
  border-color: #000;
}
.cell.gorbo-bg-red {
  background: #e53935 !important;
  color: #fff !important;
  border-color: #c62828;
}

/* ─── CENTER DOT ─── */
.center-dot {
  position: absolute;
  width: 10px; height: 10px;
  background: #28a745;
  border-radius: 50%;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 10;
}


/* ─── RESULT OVERLAY ─── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#overlay.visible { display: flex; }

.overlay-box {
  background: #fff;
  border-radius: 14px;
  padding: 32px 36px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  max-width: 420px;
  width: 92%;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
}
.overlay-box h2 { font-size: 1.6rem; margin-bottom: 16px; color: #222; }
.overlay-box p  { font-size: 1rem; color: #555; margin-bottom: 8px; }
.overlay-box .result-time {
  font-size: 2.2rem;
  font-weight: 700;
  color: #28a745;
  margin: 12px 0 16px;
}

#overlay-size-selector {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
}

/* In a sprint the result is a series, so a single-size selector is hidden */
#overlay.is-sprint #overlay-size-selector { display: none; }

.result-breakdown {
  max-width: 260px;
  margin: 0 auto 14px;
  text-align: left;
  font-size: .86rem;
  color: #555;
}
.result-breakdown:empty { display: none; }
.result-breakdown .rb-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
}
.result-breakdown .rb-row:last-child { border-bottom: none; }
.result-breakdown .rb-time {
  color: #28a745;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#btn-play-again {
  display: inline-block;
  padding: 12px 28px;
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: background .15s;
}
#btn-play-again:hover { background: #218838; }

#btn-to-settings {
  display: inline-block;
  padding: 10px 20px;
  background: transparent;
  color: #555;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: .9rem;
  cursor: pointer;
  margin-top: 10px;
  transition: background .15s;
}
#btn-to-settings:hover { background: #f5f5f5; }

/* ─── APPEARANCE MODAL ─── */
#appearance-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, #fafcfa 0%, #e7eee7 75%);
  align-items: center;
  justify-content: center;
  border-radius: 0;
  z-index: 5;
}
#appearance-overlay.visible { display: flex; }

/* Live transparent table behind the modal */
#appearance-preview {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
}
.appearance-preview-wrap {
  container-type: inline-size;
  width: min(var(--grid-max-px), 94vw, calc(100dvh - 40px));
  max-width: 94%;
}
.appearance-preview-grid {
  --grid-cols: 5;
  --grid-gap: var(--cell-gap);
  display: grid;
  width: 100%;
  gap: var(--grid-gap);
}
.appearance-preview-grid .cell {
  background: transparent;
  border-color: rgba(67, 160, 71, .4);
  color: rgba(26, 26, 26, .5);
  cursor: default;
  transition: none;
}
.appearance-preview-grid .cell:hover {
  background: transparent;
  transform: none;
}

.appearance-box {
  position: relative;
  z-index: 1;
  max-width: min(420px, calc(100% - 32px));
  padding: 22px 24px 20px;
  background: rgba(255, 255, 255, .7);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  border: 1px solid rgba(255, 255, 255, .7);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #777;
  font: inherit;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.modal-close:hover { background: rgba(0, 0, 0, .07); color: #222; }
.modal-close:focus-visible { outline: 2px solid #43a047; outline-offset: 2px; }
@media (pointer: coarse) {
  .modal-close { top: 6px; right: 6px; width: 40px; height: 40px; font-size: 28px; }
}

/* On wide screens shift the panel left so the live table stays visible */
@media (min-width: 760px) {
  .appearance-box {
    transform: translateX(-18vw);
    background: rgba(255, 255, 255, .86);
  }
}
.appearance-box h2 {
  font-size: 1.25rem;
  margin-bottom: 18px;
}
.appearance-box .setting-group {
  margin-bottom: 14px;
}
.appearance-box .btn-primary {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 11px 20px;
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.appearance-box .btn-primary:hover { background: #218838; }

/* ─── TRAINING INTRO OVERLAY ─── */
#training-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  align-items: center;
  justify-content: center;
  z-index: 110;
}
#training-overlay.visible { display: flex; }

.training-box {
  position: relative;
  max-width: 400px;
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.training-box h2 { margin-bottom: 20px; }

.training-intro-actions .btn-primary {
  display: block;
  width: 100%;
  padding: 11px 20px;
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.training-intro-actions .btn-primary:hover { background: #218838; }

.training-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 12px;
  margin-top: 12px;
}
.training-links .link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 6px 6px;
  font-size: .95rem;
  font-weight: 500;
  line-height: 1.2;
}
.link-btn {
  background: none;
  border: none;
  padding: 4px 2px;
  color: #2563c7;
  font-size: .86rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color .15s;
}
.link-btn:hover { color: #16408a; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE: tablets & phones
   The desktop layout above is untouched; everything below only
   applies on narrow / touch devices.
   ═══════════════════════════════════════════════════════════════ */

/* ─── Touch foundation ─── */
button, .cell, .demo-cell, .size-slider {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Form controls don't inherit the page font by default (most noticeable in
   Safari) — keep the typography consistent on touch layouts */
@media (max-width: 1024px), (pointer: coarse) {
  button, input, select, textarea { font-family: inherit; }
}

/* A tap must not leave a cell stuck in a hover state */
@media (hover: none) {
  .cell:hover {
    background: #fff;
    transform: none;
  }
  /* Hover-only tooltips never open on touch, but their hidden box still
     widens the page — drop them entirely */
  #btn-run.has-hint::after,
  #btn-run.has-hint::before {
    display: none;
  }
}

/* ─── Coarse pointer: finger-sized controls (phones + tablets) ─── */
@media (pointer: coarse) {
  .btn-group button {
    min-height: 38px;
    padding: 8px 12px;
    font-size: .86rem;
  }
  .settings-2col .btn-group button { min-width: 46px; }
  .guide-back, .lang-btn, .aside-btn { min-height: 38px; }
  .hdr-toggle { min-width: 38px; min-height: 38px; }
  #btn-back, #btn-run { min-height: 38px; }
  #btn-start { min-height: 46px; }
  #btn-play-again, #btn-to-settings { min-height: 44px; }
  .appearance-open { min-height: 44px; }
  .checkbox-label input[type="checkbox"] { width: 20px; height: 20px; }
  .link-btn { min-height: 36px; padding: 8px 2px; }
  .size-slider { height: 28px; }
  .gs-btn { min-height: 34px; }
  .sprint-direction { width: 26px; height: 26px; right: 5px; }
  /* A tidy 4×2 keypad beats an accidental 7+1 wrap on a tablet */
  #overlay-size-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  #overlay-size-selector .gs-btn { padding: 6px 0; }
}

/* ─── Tablets & small laptops: let the settings page grow and scroll ─── */
@media (max-width: 1024px) {
  #screen-game {
    --game-w: min(var(--grid-max-px), 100%, calc(100dvh - 150px));
  }

  body.on-settings {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
    align-items: flex-start;
    padding: 14px;
  }
  #settings-layout {
    height: auto;
    max-height: none;
  }
  #screen-settings {
    height: auto;
    max-height: none;
    min-height: calc(100dvh - 28px);
    overflow: visible;
    justify-content: flex-start;
  }

  /* Without space-between the "save settings" row would sit flush against
     the appearance button above it — give it its own breathing room */
  .save-setting-group { margin-top: 16px; }

  /* The settings card no longer fills the screen — anchor the modal
     to the viewport instead of to the card */
  #appearance-overlay {
    position: fixed;
    border-radius: 0;
  }

  /* Dense grids: gaps must not eat the cells on a narrow/short screen */
  #grid {
    --grid-gap: min(var(--cell-gap), 8px);
    --grid-gap: min(var(--cell-gap), 8px, calc(100cqw / var(--grid-cols) * .12));
  }
}

/* ─── Large tablets: the single-row header needs a little more room ─── */
@media (min-width: 861px) and (max-width: 1024px) {
  .game-header,
  .game-stats { max-width: 760px; }
}

/* ─── Small tablets / large phones: two-row game header ─── */
@media (max-width: 860px) {
  #screen-game {
    --game-w: min(var(--grid-max-px), 100%, calc(100dvh - 195px));
  }
  .game-header {
    flex-wrap: wrap;
    gap: 6px;
  }
  .header-left { width: 100%; }
  #game-size-selector {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    width: 100%;
  }
  #game-size-selector .gs-btn { padding: 4px 2px; }
}

/* ─── Phones ─── */
@media (max-width: 600px) {
  body {
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }
  body.on-landing { padding: 8px; }
  body.on-settings { padding: 8px; }

  /* Home card */
  #screen-landing {
    padding: 14px 14px 16px;
    border-radius: 14px;
  }
  .landing-title { font-size: 1.35rem; margin: 0 44px 6px; }
  .landing-tagline { font-size: .9rem; margin-bottom: 10px; }
  #screen-landing .btn-train { min-height: 48px; font-size: 1.05rem; }

  /* About / guide */
  #screen-about,
  #screen-guide {
    padding: 16px 16px 22px;
    border-radius: 14px;
  }
  .guide-header {
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-bottom: 10px;
  }
  .guide-header h1 { font-size: 1.15rem; }
  .guide-hero {
    gap: 18px;
    padding: 14px 0 16px;
    margin-bottom: 14px;
  }
  .training-steps { max-width: 100%; margin-bottom: 16px; }
  .landing-desc { font-size: .92rem; }

  /* Settings: header no longer lets the title collide with the buttons */
  #screen-settings {
    padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
    border-radius: 14px;
  }
  .settings-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 8px 10px;
    margin-bottom: 16px;
  }
  .settings-home { position: static; grid-area: 1 / 1; }
  .settings-header .lang-btn { position: static; grid-area: 1 / 3; justify-self: end; }
  .settings-header h1 {
    grid-area: 2 / 1 / 3 / 4;
    font-size: 1.15rem;
    text-align: center;
  }

  .setting-group { margin-bottom: 12px; }
  .setting-group label { font-size: .9rem; margin-bottom: 7px; }
  .settings-2col { column-gap: 12px; max-width: none; }
  .settings-2col .setting-group { margin-bottom: 12px; }
  .mode-switch { padding: 8px 12px; }
  .mode-switch-row { gap: 6px; }
  .mode-switch-row .mode-switch { padding: 8px 8px; }
  .mode-switch-row .checkbox-label { font-size: .92rem; gap: 6px; }
  #grp-size { gap: 3px; }
  .sprint-size-hint { font-size: .74rem; }
  .appearance-open { font-size: .92rem; }

  /* Start is the last stop on the page — it must not cover the controls
     above it while they are being read */
  #btn-start {
    width: 100%;
    max-width: 260px;
    font-size: 1.05rem;
    margin-top: 16px;
  }

  /* Game: three compact rows instead of one overflowing line */
  #screen-game {
    --game-w: min(var(--grid-max-px), 100%, calc(100dvh - 232px));
  }
  .game-header {
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    margin-bottom: 8px;
  }
  .header-left {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    width: 100%;
  }
  #btn-back, #btn-run {
    flex: 1 1 calc(50% - 3px);
    min-height: 40px;
    padding: 7px 6px;
    font-size: .88rem;
    min-width: 0;
  }
  .hdr-toggle {
    flex: 1 1 0;
    min-width: 0;
    min-height: 38px;
    padding: 0;
    font-size: 1rem;
  }
  #game-size-selector {
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
  }
  #game-size-selector .gs-btn {
    min-height: 36px;
    padding: 3px 0;
    font-size: .7rem;
  }

  /* Two compact rows of stats: three counters + two records */
  .game-stats {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    margin-bottom: 8px;
  }
  .game-stats .stat-card {
    grid-column: span 2;
    padding: 5px 6px;
    gap: 4px;
  }
  .game-stats .stat-card-rec { grid-column: span 3; }
  .stat-label { font-size: .56rem; letter-spacing: .03em; }
  .stat-value, #timer { font-size: .86rem; }
  #target-value { font-size: 1rem; }

  /* Modals */
  .overlay-box {
    width: calc(100% - 20px);
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
    padding: 22px 16px;
    border-radius: 14px;
  }
  .overlay-box h2 { font-size: 1.35rem; margin-bottom: 12px; }
  .overlay-box .result-time { font-size: 1.9rem; margin: 10px 0 14px; }
  .training-box { max-height: calc(100dvh - 20px); }
  .training-box h2 { margin-bottom: 14px; }
  .appearance-box {
    width: calc(100% - 20px);
    padding: 18px 16px 16px;
  }
  .appearance-box h2 { margin-bottom: 14px; }
  #overlay-size-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 16px;
  }
  #overlay-size-selector .gs-btn {
    min-height: 36px;
    padding: 6px 0;
    font-size: .8rem;
  }
  #btn-play-again, #btn-to-settings { min-height: 44px; }
}

/* Very narrow phones: keep all eight sizes on one line */
@media (max-width: 360px) {
  #grp-size { gap: 2px; }
}

/* ─── Short landscape phones: keep the whole table visible ─── */
@media (max-height: 500px) and (orientation: landscape) {
  body { padding: 6px 10px; }
  body.on-landing { padding: 6px; }
  body.on-settings { padding: 6px; }
  /* Notched phones in landscape: keep controls clear of the rounded edges */
  body {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  body.on-landing,
  body.on-settings {
    padding-left: max(6px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
  }

  #screen-game {
    --game-w: min(var(--grid-max-px), 100%, calc(100dvh - 164px));
  }
  .game-header {
    flex-direction: column;
    gap: 5px;
    margin-bottom: 5px;
  }
  .header-left {
    flex-wrap: nowrap;
    width: 100%;
  }
  #btn-back, #btn-run { flex: 0 1 auto; }
  .hdr-toggle { flex: 0 0 38px; }
  .game-stats { margin-bottom: 6px; }
  .game-stats .stat-card { padding: 3px 6px; }

  #screen-landing { padding: 10px 12px; }
  .landing-title { font-size: 1.15rem; margin-bottom: 2px; }
  .landing-tagline { font-size: .82rem; margin-bottom: 6px; }
  .demo-wrap.landing-demo { width: min(100%, calc(100dvh - 160px)); }
  #screen-landing .btn-train { margin-top: 6px; min-height: 40px; }
  .landing-secondary { margin-top: 4px; }
  .landing-link { min-height: 36px; padding: 6px 8px; font-size: .82rem; }

  .overlay-box {
    max-height: calc(100dvh - 12px);
    padding: 16px 18px;
  }
  .overlay-box h2 { font-size: 1.2rem; margin-bottom: 10px; }
  .overlay-box .result-time { font-size: 1.5rem; margin: 6px 0 10px; }
  .training-box .demo-wrap { display: none; }
  .training-steps { gap: 6px; margin-bottom: 12px; }
}

/* Wide, short screens (phone landscape): the controls fit on one line,
   which leaves enough height for a noticeably bigger table */
@media (min-width: 741px) and (max-height: 500px) and (orientation: landscape) {
  #screen-game {
    --game-w: min(var(--grid-max-px), 100%, calc(100dvh - 112px));
  }
  .game-header,
  .game-stats {
    width: 100%;
    max-width: 100%;
  }
  .game-header {
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }
  .header-left {
    width: auto;
    flex: 0 0 auto;
  }
  #game-size-selector {
    flex: 1 1 auto;
    width: auto;
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
}
