/* =====================================================================
   On Board English — тренажёр диалога бортпроводника
   Мобильный экран — основной; на большом экране всё центрируется.
   ===================================================================== */

:root {
  --bg: #eef3fb;
  --bg-2: #dfe9f7;
  --card: #ffffff;
  --card-2: #f6f9ff;
  --ink: #14213a;
  --ink-2: #4a5a76;
  --ink-3: #8493ad;
  --line: #dbe4f2;
  --accent: #1f63d6;
  --accent-soft: #e5eeff;
  --fa: #1f63d6;
  --fa-soft: #e7efff;
  --pax: #b46a06;
  --pax-soft: #fdf1dc;
  --ok: #16855c;
  --ok-soft: #e2f5ec;
  --err: #c8392f;
  --err-soft: #fdeceb;
  --warn: #a8760b;
  --shadow: 0 2px 10px rgba(20, 40, 80, .07), 0 12px 28px rgba(20, 40, 80, .06);
  --radius: 18px;
  --tab-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1526;
    --bg-2: #101d33;
    --card: #16233c;
    --card-2: #1b2b49;
    --ink: #eaf1ff;
    --ink-2: #b3c3de;
    --ink-3: #7e8fae;
    --line: #26375a;
    --accent: #6fa5ff;
    --accent-soft: #1c2f52;
    --fa: #6fa5ff;
    --fa-soft: #1b2c4d;
    --pax: #f0b45e;
    --pax-soft: #38290f;
    --ok: #56d6a0;
    --ok-soft: #12362a;
    --err: #ff8a7d;
    --err-soft: #3a1b18;
    --warn: #e0b45c;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35), 0 14px 30px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 240px);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  overscroll-behavior-y: none;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 0 14px; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
  max-width: 760px; margin: 0 auto; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--ink-3); letter-spacing: 0; }
.brand .plane { font-size: 19px; }
.spacer { flex: 1; }

.iconbtn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  width: 38px; height: 38px; border-radius: 12px; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform .08s ease, background .15s ease;
}
.iconbtn:active { transform: scale(.94); }
.iconbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Общие блоки ---------- */
.view { display: none; padding: 14px 0 26px; }
.view.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card.tight { padding: 12px; }

h1 { font-size: 22px; margin: 4px 0 2px; letter-spacing: -.2px; }
h2 { font-size: 17px; margin: 0 0 10px; letter-spacing: -.1px; }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--ink-2); font-weight: 600; }
p  { margin: 0 0 10px; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); font-size: 14px; }
.center { text-align: center; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card-2);
  color: var(--ink); font: inherit; font-weight: 600; font-size: 15.5px;
  padding: 12px 16px; border-radius: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  min-height: 46px;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 14px; min-height: 38px; border-radius: 11px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.split > * { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; font-weight: 600; color: var(--ink-2);
  cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }

/* ---------- Главная ---------- */
.hero { display: flex; align-items: center; gap: 16px; }
.ring { position: relative; width: 96px; height: 96px; flex: 0 0 96px; }
.ring svg { transform: rotate(-90deg); }
.ring .val {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; font-weight: 700; font-size: 22px; letter-spacing: -.5px;
}
.ring .val small { font-size: 10.5px; font-weight: 600; color: var(--ink-3); letter-spacing: .3px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 19px; letter-spacing: -.3px; }
.stat span { font-size: 11.5px; color: var(--ink-3); }

.menu { display: grid; gap: 10px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 13px 14px; cursor: pointer; color: inherit; font: inherit;
  transition: transform .08s ease, border-color .15s;
}
.menu-item:active { transform: scale(.985); }
.menu-item .ic {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 12px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.menu-item .tx { flex: 1; min-width: 0; }
.menu-item .tx b { display: block; font-size: 15.5px; font-weight: 650; }
.menu-item .tx span { font-size: 13px; color: var(--ink-3); }
.menu-item .go { color: var(--ink-3); font-size: 18px; }

/* ---------- Диалог ---------- */
.line {
  display: flex; gap: 10px; margin-bottom: 12px; align-items: flex-start;
}
.line .who {
  flex: 0 0 42px; height: 42px; border-radius: 13px; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  background: var(--fa-soft); color: var(--fa); border: 1px solid transparent;
}
.line.pax .who { background: var(--pax-soft); color: var(--pax); }
.line .bubble {
  flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; border-top-left-radius: 6px; padding: 11px 13px; box-shadow: var(--shadow);
}
.line.pax .bubble { background: var(--card-2); }
.line.playing .bubble { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chunk { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.chunk:last-child { border-bottom: 0; }
.chunk .en { font-size: 17px; line-height: 1.5; cursor: pointer; }
.chunk .en .key { font-weight: 700; color: var(--accent); border-bottom: 2px solid var(--accent-soft); }
.chunk .ru { font-size: 14.5px; color: var(--ink-2); margin-top: 3px; }
.chunk .note {
  font-size: 13px; color: var(--warn); margin-top: 5px; padding-left: 10px;
  border-left: 3px solid color-mix(in srgb, var(--warn) 40%, transparent);
}
.chunk.playing { background: var(--accent-soft); border-radius: 10px; padding: 5px 8px; margin: 0 -8px; }
.chunk .row { display: flex; align-items: flex-start; gap: 8px; }
.chunk .row .txt { flex: 1; min-width: 0; }
.chunk .say {
  flex: 0 0 32px; height: 32px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--accent); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center; margin-top: 2px;
}
.chunk .say:active { transform: scale(.9); }

.hide-en .chunk .en { filter: blur(5px); opacity: .55; }
.hide-en .chunk.reveal .en { filter: none; opacity: 1; }
.hide-ru .chunk .ru { display: none; }
.hide-notes .chunk .note { display: none; }

.player {
  position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 8px);
  z-index: 30; margin: 14px 0 0;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 10px; display: flex; align-items: center; gap: 8px;
}
.player .btn { flex: 0 0 auto; }
.player .info { flex: 1; min-width: 0; font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Словарь ---------- */
.word {
  display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line);
}
.word:last-child { border-bottom: 0; }
.word .tx { flex: 1; min-width: 0; }
.word .en { font-weight: 650; font-size: 16.5px; }
.word .ipa { font-size: 13.5px; color: var(--ink-3); }
.word .rus { font-size: 13px; color: var(--ink-3); font-style: italic; }
.word .ru { font-size: 14.5px; color: var(--ink-2); }
.word .star { font-size: 19px; cursor: pointer; color: var(--ink-3); background: none; border: 0; padding: 4px; }
.word .star.on { color: #f0a422; }
.word.key .en { color: var(--accent); }
.mastery { display: inline-flex; gap: 2px; vertical-align: middle; margin-left: 6px; }
.mastery i { width: 5px; height: 5px; border-radius: 50%; background: var(--line); display: block; }
.mastery i.on { background: var(--ok); }

/* ---------- Тренажёры ---------- */
.exercise { min-height: 260px; }
.prompt-ru { font-size: 19px; font-weight: 600; line-height: 1.35; margin-bottom: 4px; }
.prompt-en { font-size: 19px; font-weight: 600; line-height: 1.4; }
.hintline { font-size: 13.5px; color: var(--ink-3); margin-top: 6px; }

.answer {
  width: 100%; font: inherit; font-size: 16.5px; padding: 13px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--card-2); color: var(--ink); resize: none;
}
.answer:focus { outline: none; border-color: var(--accent); background: var(--card); }

.tiles { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; min-height: 44px; }
.tile {
  padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2);
  font-size: 16px; cursor: pointer; user-select: none; transition: transform .08s;
}
.tile:active { transform: scale(.94); }
.tile.used { opacity: .3; pointer-events: none; }
.slot {
  min-height: 56px; border: 1.5px dashed var(--line); border-radius: 14px; padding: 8px;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; background: var(--card-2);
}
.slot .tile { background: var(--accent-soft); border-color: transparent; }

.opt {
  display: block; width: 100%; text-align: left; padding: 13px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--card-2); color: inherit; font: inherit;
  font-size: 16px; margin-bottom: 8px; cursor: pointer;
}
.opt:active { transform: scale(.99); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--err); background: var(--err-soft); }

.verdict { border-radius: 14px; padding: 12px 14px; margin-top: 12px; font-size: 15.5px; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.verdict.no { background: var(--err-soft); color: var(--err); border: 1px solid color-mix(in srgb, var(--err) 35%, transparent); }
.verdict b { color: var(--ink); }
.verdict .right-answer { display: block; margin-top: 6px; font-size: 17px; color: var(--ink); font-weight: 600; }
.diff .good { color: var(--ok); }
.diff .bad { color: var(--err); text-decoration: line-through; }
.diff .miss { color: var(--err); font-weight: 700; }

.gapline { font-size: 19px; line-height: 1.6; }
.gap {
  display: inline-block; min-width: 84px; border-bottom: 2px solid var(--accent);
  text-align: center; font-weight: 700; color: var(--accent); padding: 0 4px;
}

.progressbar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-bottom: 12px; }
.progressbar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }

.counter { font-size: 13px; color: var(--ink-3); display: flex; justify-content: space-between; margin-bottom: 8px; }

/* карточка-перевёртыш */
.flip { perspective: 1200px; }
.flip-in {
  position: relative; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.2,.8,.3,1);
  min-height: 190px;
}
.flip.on .flip-in { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 18px; text-align: center;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 16px;
}
.flip-face.back { transform: rotateY(180deg); }
.flip-face .big { font-size: 22px; font-weight: 700; line-height: 1.3; }
.flip-face .sub { font-size: 15px; color: var(--ink-2); }

/* ---------- Ролевая игра ---------- */
.role-line { margin-bottom: 14px; }
.role-line .tag { font-size: 12px; font-weight: 700; color: var(--ink-3); letter-spacing: .4px; }
.role-line.mine .card { border-color: var(--accent); }
.role-hidden { filter: blur(6px); opacity: .5; }

/* ---------- Итоги ---------- */
.score { font-size: 46px; font-weight: 800; letter-spacing: -1px; text-align: center; }
.score small { font-size: 15px; font-weight: 600; color: var(--ink-3); display: block; letter-spacing: 0; }

/* ---------- Нижние вкладки ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: space-around; align-items: stretch;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
}
.tab {
  flex: 1; border: 0; background: none; color: var(--ink-3); font: inherit; font-size: 10.5px;
  font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; cursor: pointer; padding: 0;
}
.tab .ic { font-size: 19px; line-height: 1; }
.tab.on { color: var(--accent); }

/* ---------- Настройки ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 60; display: none;
  background: rgba(10, 20, 40, .45); align-items: flex-end;
}
.sheet.open { display: flex; }
.sheet-in {
  background: var(--card); width: 100%; max-width: 760px; margin: 0 auto;
  border-radius: 22px 22px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 86vh; overflow: auto; animation: up .25s cubic-bezier(.2,.9,.3,1);
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .tx { flex: 1; }
.setting .tx b { display: block; font-size: 15.5px; }
.setting .tx span { font-size: 13px; color: var(--ink-3); }
.switch { width: 50px; height: 30px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; border: 0; flex: 0 0 50px; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }
select.sel { font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); color: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 24px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14.5px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 70; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.warnbox {
  background: var(--err-soft); color: var(--err); border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  border-radius: 14px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px;
}

/* ---------- Печать ---------- */
@media print {
  body { background: #fff; color: #000; padding: 0; font-size: 12pt; }
  .topbar, .tabbar, .player, .sheet, .chunk .say, .btn, .chips, .no-print { display: none !important; }
  .view { display: none !important; }
  .view#view-dialog { display: block !important; }
  .card, .line .bubble { box-shadow: none; border: 1px solid #ccc; }
  .chunk .en .key { color: #000; border: 0; }
  .hide-en .chunk .en, .hide-ru .chunk .ru { filter: none !important; opacity: 1 !important; display: block !important; }
}

@media (min-width: 700px) {
  body { font-size: 17.5px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
