[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
:root {
  color-scheme: light dark;
  --paper: #EEF0F7; --surface: #FFFFFF; --ink: #1F1D47; --on-ink: #FFFFFF; --muted: #5F5E80; --line: #D9DBEA; --field-line: #8688A8;
  --accent: #0078BF; --pink: #FF48B0; --ok: #00784A; --warn: #7F4A00; --warn-soft: #FFF2D6; --flag-ink: #5C3A00; --bad: #B4233B; --bad-soft: #FBE3E7;
  --r: 14px; --tabbar: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16152F; --surface: #222146; --ink: #F1EFFA; --on-ink: #1F1D47; --muted: #A9A6CF; --line: #3D3A7C; --field-line: #716EA8;
    --accent: #5EC8E5; --ok: #5BE38F; --warn: #FFC766; --warn-soft: #3F3213; --flag-ink: #FFE2AE; --bad: #FF8E9B; --bad-soft: #4A2850;
  }
  /* Рисунки сделаны под светлый фон: кладём их на светлую подложку, тёмные детали не исчезают. */
  .brand svg, .game .thumb, .themes button svg, .login .art, .wait .art svg { background: #EEF0F7; border-radius: 10px; }
}
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: 'Jost', 'Futura', 'Century Gothic', system-ui, sans-serif; font-size: 1.125rem; line-height: 1.45; }
#app { max-width: 720px; margin: 0 auto; padding: 16px 18px 80px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
h1 { font-size: 2.1em; }
h2 { font-size: 1.45em; }
h3 { font-size: 1.05em; letter-spacing: 0; }
p { margin: 0; }
svg { display: block; flex: none; }

button, .btn {
  font: inherit; color: inherit; cursor: pointer; border: 0; background: none; border-radius: var(--r);
  min-height: 48px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button:focus-visible, .btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--ink); color: var(--on-ink); font-weight: 500; min-height: 56px; }
.secondary { border: 2px solid var(--line); background: var(--surface); font-weight: 500; }
.quiet { color: var(--muted); font-weight: 500; }
.danger { color: var(--bad); font-weight: 500; }
.small { min-height: 44px; padding: 6px 12px; font-size: .9em; }
.wide { width: 100%; }

.top { display: flex; align-items: center; gap: 10px; margin: 0 -6px 26px; min-height: 48px; }
.top .spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; padding: 0 6px; }

input[type=text], input[type=password], input[type=email], input[type=search], input[type=tel], input[type=url], input[type=number], textarea, select {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%;
  border: 2px solid var(--field-line); border-radius: var(--r); padding: 11px 14px; min-height: 52px;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
input:focus, textarea:focus, select:focus { border-color: var(--ink); outline: none; }
::placeholder { color: var(--muted); opacity: 1; }
.field { display: grid; gap: 8px; }
.label { font-weight: 500; font-size: .9em; color: var(--muted); }
.hint { color: var(--muted); font-size: .85em; }
.error { color: var(--bad); font-size: .9em; font-weight: 500; }

/* Вход */
.login { display: grid; gap: 22px; padding-top: 10vh; max-width: 420px; }
.login .art { width: 120px; height: 120px; }

/* Список игр */
.hero-new { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 16px; margin-bottom: 26px; }
.hero-new .art { width: 96px; height: 96px; }
.games { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.game { background: var(--surface); border-radius: var(--r); padding: 14px 14px 10px; display: grid; gap: 10px; }
.game .row { display: flex; gap: 14px; align-items: flex-start; }
.game .thumb { width: 52px; height: 52px; flex: none; }
.game .t { font-weight: 600; font-size: 1.05em; line-height: 1.2; }
.game .m { color: var(--muted); font-size: .85em; }
.game .actions { display: flex; gap: 2px; flex-wrap: wrap; margin: 0 -6px; }
.game .actions button { min-height: 44px; padding: 6px 10px; font-size: .9em; color: var(--muted); font-weight: 500; }
.game .confirm { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border-radius: 10px; background: var(--bad-soft); }
.empty { padding: 30px 0; color: var(--muted); }

/* Анкета */
.form { display: grid; gap: 26px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { background: var(--surface); border: 2px solid transparent; min-width: 52px; font-weight: 500; padding: 8px 14px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
details.more { border-top: 2px solid var(--line); padding-top: 16px; }
details.more summary { cursor: pointer; font-weight: 500; list-style: none; display: flex; align-items: center; gap: 8px; min-height: 44px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: '+'; margin-left: auto; font-size: 1.4em; color: var(--muted); }
details.more[open] summary::after { content: '−'; }
details.more .inner { display: grid; gap: 22px; padding-top: 14px; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.themes button { background: var(--surface); border: 2px solid transparent; flex-direction: column; align-items: flex-start; text-align: left; padding: 10px; gap: 6px; font-size: .9em; font-weight: 500; line-height: 1.2; }
.themes button svg { width: 40px; height: 40px; }
.themes button[aria-pressed="true"] { border-color: var(--ink); }
.photo { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.photo img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }
.limit { color: var(--muted); font-size: .85em; text-align: center; }

/* Ожидание */
.wait { display: grid; gap: 22px; padding-top: 8vh; }
.wait .art svg { width: 120px; height: 120px; }
.wait .art .piece { transform-box: fill-box; transform-origin: center; animation: breathe 1.6s ease-in-out infinite; animation-delay: calc(var(--i) * .2s); }
.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.stages li { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.stages li.now { color: var(--ink); font-weight: 500; }
.stages li.done { color: var(--ok); }
.stages .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; flex: none; }
.stages li.now .dot { background: var(--accent); border-color: var(--accent); animation: blink 1s infinite; }
.stages li.done .dot { background: var(--ok); border-color: var(--ok); }

/* Редактор */
.ed-head { display: grid; gap: 12px; margin-bottom: 18px; }
.ed-head input.ed-title { font-size: 1.6em; font-weight: 600; letter-spacing: -0.02em; border: 0; border-bottom: 2px solid var(--line); border-radius: 0; background: transparent; padding: 4px 0; min-height: 0; }
.ed-head input.ed-title:focus { border-color: var(--ink); }
.summary { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface); font-size: .85em; font-weight: 500; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.ok { color: var(--ok); }
.level { margin-top: 30px; display: grid; gap: 10px; }
.level-h { display: grid; grid-template-columns: 1fr; gap: 6px; }
.level-h input { font-weight: 600; font-size: 1.1em; }
.level-h .skill-in { font-size: .9em; min-height: 44px; }
.task-card { background: var(--surface); border-radius: var(--r); padding: 14px; display: grid; gap: 12px; border: 2px solid transparent; }
.task-card.flagged { border-color: #F2C35B; }
.task-card.broken { border-color: var(--bad); }
.tc-head { display: flex; align-items: center; gap: 8px; }
.tc-head .num { font-weight: 700; font-size: 1.3em; letter-spacing: -0.03em; width: 1.6em; }
.tc-head .type { color: var(--muted); font-size: .85em; font-weight: 500; }
.tc-head .spacer { flex: 1; }
.tc-head button { min-height: 44px; padding: 6px 8px; color: var(--muted); }
.flag { display: grid; gap: 6px; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--flag-ink); font-size: .92em; }
.flag .row { display: flex; gap: 8px; align-items: flex-start; }
.flag button { justify-self: start; min-height: 44px; padding: 4px 12px; font-size: .9em; background: var(--surface); color: var(--flag-ink); }
.broken-msg { padding: 10px 12px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); font-size: .9em; }
.task-card textarea { min-height: 64px; }
.task-card .twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt-row { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; }
.opt-row input[type=radio] { width: 22px; height: 22px; accent-color: var(--ok); margin: 0 4px; }
.pair-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sticky { position: sticky; bottom: var(--tabbar); background: linear-gradient(transparent, var(--paper) 30%); padding: 22px 0 14px; display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-top: 26px; }

/* Ссылка */
.ready { display: grid; gap: 20px; padding-top: 6vh; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-weight: 500; }
.share { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Просмотр */
.preview { position: fixed; inset: 0; background: rgba(20, 18, 50, .6); z-index: 30; display: grid; grid-template-rows: auto 1fr; }
.preview .bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--ink); color: var(--on-ink); }
.preview .bar .spacer { flex: 1; }
.preview iframe { border: 0; width: 100%; height: 100%; max-width: 480px; margin: 0 auto; background: #fff; }

.toast { position: fixed; left: 50%; bottom: calc(22px + var(--tabbar)); transform: translateX(-50%); background: var(--ink); color: var(--on-ink); padding: 12px 18px; border-radius: 12px; font-weight: 500; z-index: 50; max-width: calc(100% - 32px); }
.banner { padding: 12px 14px; border-radius: var(--r); background: var(--bad-soft); color: var(--bad); font-weight: 500; }

@keyframes breathe { 50% { transform: scale(.82) rotate(12deg); } }
@keyframes blink { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (max-width: 420px) {
  body { font-size: 1.0625rem; }
  .task-card .twocol { grid-template-columns: 1fr; }
}

/* Планшет и компьютер */
@media (min-width: 760px) {
  #app { max-width: 880px; padding: 28px 32px 90px; }
  .games { grid-template-columns: 1fr 1fr; }
  .form { grid-template-columns: 1fr 1fr; column-gap: 28px; }
  .form > h1, .form > details, .form > .primary, .form > .error, .form > .limit, .form > .field:nth-of-type(3) { grid-column: 1 / -1; }
  .form > .primary { max-width: 360px; }
  .themes { grid-template-columns: repeat(4, 1fr); }
  .task-card { padding: 18px 20px; }
  .sticky { grid-template-columns: 240px 320px; justify-content: end; }
  .ready { max-width: 560px; }
  .login { margin: 0 auto; }
}
@media (hover: hover) {
  .seg button:hover, .themes button:hover { border-color: var(--ink); }
  .game .actions button:hover, .quiet:hover { color: var(--ink); }
}

/* Навигация и ученики */
.tabs { display: flex; gap: 2px; background: var(--surface); border-radius: 12px; padding: 3px; }
.tab { min-height: 44px; padding: 6px 14px; border-radius: 10px; font-weight: 500; color: var(--muted); }
.tab.on { background: var(--ink); color: var(--on-ink); }
.brand { padding: 0 6px; min-width: 44px; }
.page-head { display: grid; gap: 10px; margin-bottom: 20px; }
.back { margin: -10px 0 8px -10px; }
.students { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.student { width: 100%; background: var(--surface); justify-content: flex-start; text-align: left; gap: 14px; padding: 12px 14px; }
.student .avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; font-weight: 600; flex: none; }
.student .txt, .attempt .txt { display: grid; gap: 2px; flex: 1; min-width: 0; }
.student .t, .attempt .t { font-weight: 600; line-height: 1.2; }
.student .m, .attempt .m { color: var(--muted); font-size: .85em; }
.pct { font-weight: 700; font-size: 1.2em; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pct.muted { color: var(--muted); font-weight: 500; font-size: .95em; }
.attempts { display: grid; gap: 10px; }
.attempt { background: var(--surface); border-radius: var(--r); padding: 14px; display: grid; gap: 10px; }
.attempt .row { display: flex; gap: 12px; align-items: center; }
.attempt .actions { display: flex; gap: 8px; align-items: center; }
.attempt .details { border-top: 2px solid var(--line); padding-top: 10px; }
.skill-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.skill-row:last-child { border-bottom: 0; }
.stars { letter-spacing: 2px; white-space: nowrap; }
.lvl-state { color: var(--muted); white-space: nowrap; }
.mistake { display: grid; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mistake:last-child { border-bottom: 0; }
.mistake .q { font-weight: 500; }
.mistake .a { color: var(--ok); font-weight: 600; }
.mistake .n { color: var(--muted); font-size: .85em; }
@media (min-width: 760px) { .students { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .tab { padding: 6px 10px; } }

/* Аккаунт, админка, личные ссылки */
.account { margin-right: -6px; color: var(--muted); }
.account.on { color: var(--ink); }
.panel { background: var(--surface); border-radius: var(--r); padding: 18px; display: grid; gap: 12px; margin-bottom: 14px; }
.panel select { min-height: 44px; width: auto; }
.meter { display: grid; gap: 8px; }
.meter-bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.meter-bar i { display: block; height: 100%; background: var(--ink); border-radius: 5px; }
.admin-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--line); }
.admin-row .txt { display: grid; gap: 2px; flex: 1; min-width: 180px; }
.admin-row .t { font-weight: 600; }
.admin-row .m { color: var(--muted); font-size: .85em; overflow-wrap: anywhere; }
.admin-row .nums { display: flex; gap: 12px; color: var(--muted); font-size: .85em; flex-wrap: wrap; }
.personal { display: grid; gap: 8px; }
.personal .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.personal select { flex: 1; min-width: 160px; }
.add-student { display: flex; gap: 8px; margin-bottom: 18px; }
.add-student input { flex: 1; min-width: 0; }
.tag { display: inline-block; font-size: .75em; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: middle; }

/* Шапка на узких экранах: вкладки ужимаются, логотип прячется */
.top { flex-wrap: nowrap; }
.tabs { min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; flex: none; }
/* Телефон: разделы в панели внизу, под большим пальцем */
@media (max-width: 759px) {
  :root { --tabbar: calc(62px + env(safe-area-inset-bottom)); }
  #app { padding-bottom: calc(80px + var(--tabbar)); }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; border-radius: 0; padding: 4px 8px env(safe-area-inset-bottom); gap: 0; border-top: 1px solid var(--line); justify-content: space-around; overflow: visible; }
  .tab, .tab.on { flex: 1; flex-direction: column; gap: 1px; min-height: 54px; padding: 4px; font-size: .72em; background: none; }
  .tab.on { color: var(--ink); font-weight: 600; box-shadow: inset 0 2px 0 var(--ink); border-radius: 0; }
}
@media (min-width: 760px) { .tab .ic { display: none; } }

.brand .wordmark { font-weight: 600; letter-spacing: -0.02em; font-size: 1.02em; }

/* Дашборд ученика */
.dash { display: grid; gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { background: var(--surface); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 2px; }
.tile-label { color: var(--muted); font-size: .82em; }
.tile-value { font-size: 1.6em; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.sparkline { width: 100%; height: auto; }
.sl-grid { stroke: var(--line); stroke-width: 1; }
.sl-axis { fill: var(--muted); font-size: 12px; font-family: inherit; }
.sl-line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.sl-dot { fill: var(--ink); stroke: var(--surface); stroke-width: 2; }
.sl-pt:hover .sl-dot { r: 7; }
.sl-label { fill: var(--ink); font-size: 13px; font-weight: 600; font-family: inherit; }
.skill-bar { display: grid; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.sb-head { display: flex; gap: 8px; align-items: center; }
.sb-name { font-weight: 500; flex: 1; min-width: 0; }
.sb-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.sb-track { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.sb-track i { display: block; height: 100%; border-radius: 4px; background: var(--ink); }
.sb-track i.weak { background: var(--bad); }
.sb-note { color: var(--muted); font-size: .8em; }
.flag-weak { display: inline-flex; align-items: center; gap: 4px; color: var(--bad); font-size: .8em; font-weight: 600; }
.flag-up { color: var(--ok); font-size: .8em; font-weight: 600; }
.insights { display: grid; gap: 10px; }
.weak-card { border: 2px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 4px; }
.wc-head { display: flex; gap: 6px; align-items: center; color: var(--bad); }
.wc-head strong { color: var(--ink); }
.wc-k { color: var(--muted); }
.next-game { display: grid; gap: 10px; padding: 12px; border-radius: 12px; background: var(--paper); }
.next-game .primary { justify-self: start; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

/* Фото страниц */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; align-items: stretch; }
.thumb-ph { position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; background: var(--surface); }
.thumb-ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-del { position: absolute; top: 4px; right: 4px; min-width: 36px; min-height: 36px; padding: 0; border-radius: 50%; background: rgba(31, 29, 71, .8); color: #fff; }
.thumb-del::after { content: ''; position: absolute; inset: -4px; }
.add-ph { aspect-ratio: auto; min-height: 84px; flex-direction: column; gap: 4px; font-size: .85em; text-align: center; grid-column: span 2; }
.ph-count { grid-column: 1 / -1; margin: 0; }

/* Safari на iPhone дорисовывает полям свою тень и скругление: убираем, оформление везде одно */
input[type=text], input[type=password], input[type=email], input[type=search], input[type=tel], input[type=url], input[type=number], textarea { -webkit-appearance: none; appearance: none; }

.panel-title { font-size: 1.05em; letter-spacing: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Длинные слова в названиях и именах не вылезают за экран; переносов по слогам в интерфейсе нет */
body { overflow-wrap: anywhere; }
.game .t, .student .t, .attempt .t, .sb-name, .admin-row .t { overflow-wrap: anywhere; }
button, .btn, .chip { -webkit-hyphens: none; hyphens: none; }
.game .row > div, .student .txt, .attempt .txt, .admin-row .txt, .sb-name, .tile, .wc-head, .next-game > div { min-width: 0; }
input, textarea, select { min-width: 0; }

.res-note { color: var(--muted); }
.unsaved { border: 2px solid var(--warn); }

/* Кнопки с одним действием не ломаются по буквам */
.linkbox button, .sticky button, .share .btn { overflow-wrap: normal; }
.linkbox button { white-space: nowrap; }
.linkbox input { flex: 1; min-width: 0; }
/* Карточка игры: главное действие заметнее, удаление отдельно */
.game .actions button:first-child { color: var(--ink); }
.game .actions button:last-child { margin-left: auto; }
/* Редактор на телефоне: панель разделов уступает место кнопкам сохранения */
@media (max-width: 759px) {
  :root:has(.sticky) { --tabbar: 0px; }
  #app:has(.sticky) .tabs { display: none; }
  #app:has(.sticky) { padding-bottom: 24px; }
  .sticky { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .sticky button { font-size: .92em; padding: 8px 10px; }
}
