/* Испытания («Все флаги», «Соедини»). Рамка страницы, кнопки и палитра — из gallery.css (body.is-gallery); здесь только игры.
   Классы начинаются с ch-. Оформление взято из согласованного прототипа. */

/* ширина рамки страницы — как у «Галереи» и «Бонусов» (задаётся .gallery-page), своей не задаём */
.ch-view[hidden], #ch-content[hidden], .ch-message[hidden] { display: none; }

.ch-lead { margin: 0 0 18px; color: var(--home-text-muted); font-size: 0.95rem; line-height: 1.5; }
.ch-lead--center { text-align: center; max-width: 60ch; margin-left: auto; margin-right: auto; }
.ch-h2 { margin: 0 0 18px; font-family: var(--font-display); font-weight: 400; font-size: clamp(1.2rem, 2.4vw, 1.6rem); line-height: 1.25; color: var(--home-text); }
.ch-label { margin: 0 0 10px; color: var(--home-text-muted); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.ch-static { margin: 0; color: var(--home-text); font-family: var(--font-display); font-size: 1.1rem; }
.ch-page :focus-visible { outline: 2px solid var(--g-focus); outline-offset: 3px; }

/* сообщение (вход, загрузка, ошибка) */
.ch-message { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin: 0 0 18px; padding: 16px 18px; border: 1px solid var(--home-border); border-radius: 16px; background: #101a2c; }
.ch-message__text { margin: 0; color: var(--home-text); }

/* ----- список испытаний ----- */
.ch-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.ch-card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; width: 100%; height: 100%; padding: 18px; border: 1px solid var(--home-border); border-radius: 20px; background: #101a2c; color: var(--home-text); text-align: left; font-family: var(--font-body); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.ch-card:hover:not(:disabled) { border-color: rgba(74, 150, 255, 0.7); background: #13203a; }
.ch-card:disabled { cursor: default; opacity: 0.62; }
.ch-card__icon { display: grid; place-items: center; width: 56px; height: 56px; border: 1px solid var(--home-border); border-radius: 16px; background: var(--home-primary-soft); color: #5b9bff; }
.ch-card__icon svg { width: 60%; height: 60%; }
.ch-card__name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 1.15rem; line-height: 1.25; }
.ch-card__desc { color: var(--home-text-muted); font-size: 0.9rem; line-height: 1.45; }
.ch-soon { padding: 2px 9px; border: 1px dashed rgba(243, 201, 77, 0.55); border-radius: 999px; color: var(--home-amber); font-family: var(--font-body); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }

.ch-resume { margin: 0 0 22px; }
.ch-resume__list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.ch-resume__btn { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px; border: 1px solid rgba(74, 150, 255, 0.55); border-radius: 999px; background: var(--home-primary-soft); color: var(--home-text); font: 600 0.88rem var(--font-body); cursor: pointer; }
.ch-resume__btn:hover { background: rgba(47, 125, 253, 0.28); }
.ch-resume__btn b { color: #8fc0ff; font-weight: 700; }

/* ----- настройка ----- */
.ch-block { margin: 0 0 22px; }
.ch-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ch-chips--sub { margin-top: 10px; }
.ch-chips--sub:empty { display: none; }
.ch-chip { min-height: 44px; padding: 0 22px; border: 1px solid var(--home-border); border-radius: 12px; background: #101a2c; color: var(--home-text-muted); font: 600 0.95rem var(--font-body); cursor: pointer; }
.ch-chip:hover { color: var(--home-text); border-color: rgba(74, 150, 255, 0.6); }
.ch-chip[aria-pressed="true"] { background: var(--home-primary); border-color: #6aa8ff; color: #fff; }
.ch-chips--sub .ch-chip { min-height: 38px; padding: 0 16px; font-size: 0.88rem; }

.ch-rules { padding: 16px 18px; border: 1px solid var(--home-border-soft); border-radius: 16px; background: rgba(255, 255, 255, 0.02); }
.ch-rules .ch-label { color: var(--home-amber); font-size: 0.85rem; }
.ch-rules .ch-label:not(:first-child) { margin-top: 18px; }
.ch-rules ul { margin: 0; padding: 0; list-style: none; }
.ch-rules li { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-top: 1px solid var(--home-border-soft); color: #c3cbd9; font-size: 0.93rem; }
.ch-rules li:first-child { border-top: 0; }
.ch-rules b { color: #5b9bff; white-space: nowrap; }
.ch-rules .ch-howto li { display: block; padding: 0 0 6px; border-top: 0; line-height: 1.5; }
.ch-rules .ch-howto li:last-child { padding-bottom: 0; }

.ch-continue { margin: 0 0 18px; padding: 16px 18px; border: 1px solid rgba(74, 150, 255, 0.45); border-radius: 16px; background: rgba(47, 125, 253, 0.07); }
.ch-continue__text { margin: 0 0 12px; color: var(--home-text); }
.ch-continue__btns { display: flex; flex-wrap: wrap; gap: 10px; }
.ch-continue[hidden] { display: none; }

/* ----- шапка игры ----- */
.ch-hud { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 10px; margin: 0 0 16px; }
.ch-pill { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border: 1px solid var(--home-border); border-radius: 999px; background: #101a2c; color: var(--home-text); font-size: 0.88rem; font-weight: 600; white-space: nowrap; }
.ch-pill b { color: #fff; font-family: var(--font-display); font-weight: 400; }
.ch-pill--timer { border-color: rgba(52, 211, 153, 0.5); color: #8fe3c1; }
.ch-pill--timer b { color: #34d399; }
.ch-pill--timer.is-off { border-color: var(--home-border); color: var(--home-text-muted); }
.ch-pill--timer.is-off b { color: var(--home-text-muted); }
.ch-pill--err b { color: #f9a8a8; }
.ch-short { display: none; }

/* ----- панель задания «Все флаги» ----- */
.ch-task { display: grid; grid-template-columns: 130px minmax(0, 1fr) 130px; align-items: center; gap: 8px; max-width: 620px; margin: 0 auto 10px; padding: 10px; border: 1px solid var(--home-border); border-radius: 16px; background: #0a1120; }
.ch-task__body { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; min-width: 0; }
.ch-task__label { color: var(--home-text-muted); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.ch-task__name { font-family: var(--font-display); font-size: clamp(1.2rem, 2.6vw, 1.6rem); color: var(--home-text); overflow-wrap: anywhere; }
.ch-task__tries { min-height: 1.1em; color: var(--home-text-muted); font-size: 0.8rem; }
.ch-skip { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 12px; border: 1px solid var(--home-border); border-radius: 999px; background: #101a2c; color: var(--home-text); font: 600 0.82rem var(--font-body); cursor: pointer; }
.ch-skip:hover:not(:disabled) { background: var(--home-primary-soft); }
.ch-skip:disabled { opacity: 0.4; cursor: default; }
.ch-flash { min-height: 1.6em; margin: 0 0 8px; text-align: center; color: var(--home-text-muted); font-size: 0.95rem; }
.ch-flash.is-ok { color: #34d399; font-weight: 700; }
.ch-flash.is-bad { color: #f9a8a8; }

/* флаги */
.ch-flag { display: block; width: 100%; aspect-ratio: 3 / 2; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 8px; background: var(--g-flag-bg, #101c33); }
.ch-flag img { display: block; width: 100%; height: 100%; object-fit: contain; }

/* ----- сетка «Все флаги» ----- */
.ch-flaggrid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: clamp(6px, 1.1vw, 10px); max-width: 860px; margin: 0 auto; padding: 0; list-style: none; }
.ch-flaggrid button { display: block; width: 100%; padding: 6px; border: 1px solid var(--home-border); border-radius: 10px; background: #101a2c; cursor: pointer; transition: border-color 0.12s, background 0.12s; }
.ch-flaggrid button:hover:not(:disabled) { border-color: rgba(74, 150, 255, 0.7); background: #13203a; }
.ch-flaggrid button:disabled { cursor: default; }
.ch-flaggrid .is-wrong button { border-color: #f87171; background: rgba(248, 113, 113, 0.1); }
.ch-flaggrid .is-wrong .ch-flag { opacity: 0.3; filter: grayscale(0.7); }
.ch-flaggrid .is-right button { border-color: #34d399; box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.55); background: rgba(52, 211, 153, 0.12); }
.ch-flaggrid .is-reveal button { border-color: #f3c94d; box-shadow: 0 0 0 2px rgba(243, 201, 77, 0.6); background: rgba(243, 201, 77, 0.1); }

/* ----- «Соедини» ----- */
.ch-match { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(56px, 24%) minmax(0, 1fr); max-width: 720px; margin: 0 auto; touch-action: manipulation; }
.ch-match__col { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; position: relative; z-index: 2; }
#ch-m-left { grid-column: 1; }
#ch-m-right { grid-column: 3; }
.ch-match__lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 1; }
.ch-slot { display: flex; align-items: center; position: relative; min-height: 68px; padding: 8px; border: 1px solid var(--home-border); border-radius: 14px; background: #101a2c; color: var(--home-text); font-family: var(--font-display); font-size: clamp(0.9rem, 1.8vw, 1.1rem); cursor: pointer; user-select: none; -webkit-user-select: none; transition: border-color 0.12s, background 0.12s; }
.ch-slot:hover:not(.ch-slot--done) { border-color: rgba(74, 150, 255, 0.6); }
.ch-slot .ch-flag { width: 76px; flex: none; pointer-events: none; }
.ch-slot span { padding: 0 8px; overflow-wrap: anywhere; pointer-events: none; }
.ch-slot--flag { touch-action: none; }
.ch-slot--name { justify-content: center; text-align: center; }
.ch-slot--done { cursor: default; }
.ch-slot--ok { border-color: #34d399; box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.5); background: rgba(52, 211, 153, 0.07); }
.ch-slot--miss { border-color: #f3c94d; box-shadow: 0 0 0 1px rgba(243, 201, 77, 0.5); background: rgba(243, 201, 77, 0.07); }
.ch-slot--pick { border-color: #4a96ff; box-shadow: 0 0 0 1px rgba(74, 150, 255, 0.55); background: rgba(47, 125, 253, 0.1); }
.ch-slot--bad { border-color: #f87171; box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.55); background: rgba(248, 113, 113, 0.1); }
.ch-slot__dots { position: absolute; right: 8px; top: 6px; display: flex; gap: 3px; pointer-events: none; }
.ch-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #f87171; }
.ch-slot__gain { position: absolute; right: 8px; bottom: 5px; color: #34d399; font: 700 0.75rem var(--font-body); pointer-events: none; }
.ch-line { fill: none; stroke-width: 3; stroke-linecap: round; }
.ch-line--ok { stroke: #34d399; }
.ch-line--miss { stroke: #f3c94d; stroke-dasharray: 5 6; }
.ch-line--drag { stroke: #4a96ff; stroke-dasharray: 2 6; }

.ch-banner { max-width: 720px; margin: 16px auto 0; padding: 12px 16px; border: 1px solid rgba(52, 211, 153, 0.55); border-radius: 14px; background: rgba(52, 211, 153, 0.1); color: #8fe3c1; font-family: var(--font-display); font-size: 1rem; text-align: center; }
.ch-banner[hidden] { display: none; }

/* ----- итог ----- */
.ch-result { display: grid; justify-items: center; max-width: 480px; margin: 0 auto; text-align: center; }
.ch-result__sub { margin: -8px 0 18px; color: var(--home-text-muted); }
.ch-result__rows { width: 100%; margin: 0 0 20px; padding: 0; list-style: none; border: 1px solid var(--home-border-soft); border-radius: 16px; background: #101a2c; }
.ch-result__rows li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--home-border-soft); color: #c3cbd9; }
.ch-result__rows li:first-child { border-top: 0; }
.ch-result__rows b { color: var(--home-text); font-family: var(--font-display); font-weight: 400; }
.ch-result__rows .ch-ok { color: #34d399; }
.ch-result__rows .ch-result__total { background: rgba(47, 125, 253, 0.1); border-radius: 0 0 16px 16px; }
.ch-result__total b { color: #5b9bff; }
.ch-result__btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.ch-toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; max-width: min(92vw, 420px); margin: 0; padding: 10px 18px; transform: translateX(-50%); border: 1px solid var(--home-border); border-radius: 999px; background: #0b1220; color: var(--home-text); font-size: 0.9rem; text-align: center; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45); }
.ch-toast[hidden] { display: none; }

/* ----- телефон ----- */
@media (max-width: 640px) {
  .ch-hud { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; margin-bottom: 8px; }
  .ch-hud .ch-pill { justify-content: center; padding: 6px 4px; font-size: 0.7rem; }
  .ch-hud .ch-full { display: none; }
  .ch-hud .ch-short { display: inline; }

  .ch-cards { gap: 10px; }
  .ch-card { display: grid; grid-template-columns: 48px minmax(0, 1fr); column-gap: 14px; row-gap: 3px; align-items: center; padding: 14px; border-radius: 18px; }
  .ch-card__icon { grid-row: 1 / span 2; width: 48px; height: 48px; border-radius: 14px; align-self: start; }
  .ch-card__name { font-size: 1.05rem; }
  .ch-card__desc { font-size: 0.84rem; }

  .ch-chip { min-height: 44px; padding: 0 18px; }
  /* части света и страны: все плашки в одну линию (на самых узких экранах линия листается в сторону) */
  .ch-chips--sub { flex-wrap: nowrap; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .ch-chips--sub::-webkit-scrollbar { display: none; }
  .ch-chips--sub .ch-chip { flex: 1 1 auto; min-height: 40px; padding: 0 4px; font-size: 0.72rem; white-space: nowrap; }
  .ch-view[data-view="setup"] .g-btn, .ch-continue__btns .g-btn, .ch-result__btns .g-btn { width: 100%; }
  .ch-rules li { font-size: 0.88rem; }

  /* игровой экран: рамка компактнее, чтобы всё помещалось на экране телефона */
  .ch-page[data-current="flags"], .ch-page[data-current="match"] { padding-top: 10px; padding-bottom: 14px; }
  .ch-page[data-current="flags"] .back-btn, .ch-page[data-current="match"] .back-btn { margin: 0 0 2px; font-size: 0.8rem; }
  .ch-page[data-current="flags"] .gallery-page__head, .ch-page[data-current="match"] .gallery-page__head { margin: 0 0 8px; }
  .ch-page[data-current="flags"] .gallery-page__title, .ch-page[data-current="match"] .gallery-page__title { font-size: 1.25rem; }

  .ch-task { grid-template-columns: 44px minmax(0, 1fr) 44px; margin-bottom: 4px; padding: 6px; }
  .ch-task__label { font-size: 0.62rem; }
  .ch-task__name { font-size: 1.05rem; }
  .ch-task__tries { font-size: 0.7rem; }
  .ch-skip { width: 40px; min-height: 40px; padding: 0; border-radius: 50%; }
  .ch-skip span { display: none; }
  .ch-flash { min-height: 1.3em; margin-bottom: 4px; font-size: 0.82rem; }
  .ch-flaggrid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .ch-flaggrid button { padding: 4px; border-radius: 8px; }

  .ch-view[data-view="match"] .ch-lead { display: none; }
  .ch-match { grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr); }
  .ch-match__col { gap: 8px; }
  .ch-slot { min-height: 56px; padding: 6px; }
  .ch-slot .ch-flag { width: 76px; }
  .ch-slot span { padding: 0 4px; font-size: 0.85rem; }
}
