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

:root {
  --bg: #0e1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --line: #2a3140;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4f8cff;
  --npc: #232b3a;
  --user: #2f6fed;
  --win: #2ea043;
  --lose: #e5534b;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app { height: 100dvh; position: relative; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- Меню ---------- */
.menu-inner {
  margin: auto; width: 100%; max-width: 480px;
  padding: 24px 20px; display: flex; flex-direction: column; gap: 18px;
}
#menu { overflow-y: auto; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { color: var(--muted); font-size: 15px; line-height: 1.4; }
.levels { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }

.level-card {
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px; text-align: left; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; gap: 4px; transition: transform .08s, border-color .15s;
}
.level-card:active { transform: scale(0.985); }
.level-card:disabled { cursor: default; }
.level-card:disabled:active { transform: none; }
.level-card .lvl-row { display: flex; align-items: center; gap: 10px; }
.level-card .lvl-title { font-size: 18px; font-weight: 650; }
.level-card .lvl-npc { font-size: 14px; }
.level-card .lvl-desc { color: var(--muted); font-size: 13px; }

/* пройденный уровень */
.check { color: var(--win); font-weight: 800; margin-left: 2px; }
.level-card.completed { border-color: rgba(46,160,67,.5); }

/* заблокированный уровень (кулдаун или ещё не открыт) */
.level-card.locked > .lvl-row,
.level-card.locked > .lvl-npc,
.level-card.locked > .lvl-desc { opacity: .28; filter: grayscale(.5); }
.lvl-lock {
  position: absolute; inset: 0; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  text-align: center; padding: 0 14px;
  background: rgba(14, 17, 23, .62);
  font-weight: 600; font-size: 13px; color: var(--muted);
}
.lvl-lock.cooldown { font-size: 21px; font-weight: 750; color: #ff9d7a; }

.badge { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
.badge.easy { background: rgba(46,160,67,.18); color: #5fd07a; }
.badge.medium { background: rgba(210,153,34,.18); color: #e3b341; }
.badge.hard { background: rgba(229,83,75,.18); color: #ff7b72; }

/* ---------- Чат ---------- */
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.icon-btn {
  background: none; border: none; color: var(--text); font-size: 30px;
  line-height: 1; cursor: pointer; width: 32px; height: 32px;
}
.chat-title { display: flex; flex-direction: column; gap: 2px; }
#npc-name { font-weight: 650; font-size: 16px; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px 14px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 82%; padding: 10px 13px; border-radius: 16px;
  font-size: 15px; line-height: 1.42; white-space: pre-wrap; word-wrap: break-word;
}
.msg.npc { align-self: flex-start; background: var(--npc); border-bottom-left-radius: 5px; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 5px; }
.msg .score { font-weight: 700; }
.msg .score.plus { color: #5fd07a; }
.msg .score.minus { color: #ff7b72; }

/* появление пузыря */
.msg.npc { animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* мигающая каретка во время печати */
.caret {
  display: inline-block; width: 7px; height: 1.05em; vertical-align: -2px;
  margin-left: 1px; border-radius: 2px; background: var(--accent);
  animation: caret .9s steps(1) infinite;
}
@keyframes caret { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
.msg.streaming { animation: none; }

.typing { align-self: flex-start; display: flex; gap: 4px; padding: 14px 16px;
  background: var(--npc); border-radius: 16px; border-bottom-left-radius: 5px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.result-banner { display: none; text-align: center; padding: 12px; font-weight: 650;
  font-size: 15px; flex-shrink: 0; }
.result-banner.win { display: block; background: rgba(46,160,67,.15); color: #5fd07a; }
.result-banner.lose { display: block; background: rgba(229,83,75,.15); color: #ff7b72; }
.result-banner .restart { display: inline-block; margin-left: 8px; text-decoration: underline;
  cursor: pointer; }

.composer {
  display: flex; gap: 8px; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line); flex-shrink: 0;
}
.composer textarea {
  flex: 1; resize: none; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 20px; padding: 10px 14px;
  font-size: 16px; font-family: inherit; max-height: 120px; line-height: 1.35;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer textarea::placeholder { color: var(--muted); }
.composer button {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.composer button:disabled { opacity: .4; cursor: default; }
.error-msg { align-self: center; color: var(--lose); font-size: 13px; text-align: center; }

/* ---------- Главная: выбор режима ---------- */
#home { overflow-y: auto; }
.home-inner {
  margin: auto; width: 100%; max-width: 480px;
  padding: 28px 20px; display: flex; flex-direction: column; gap: 12px;
}
.home-title { font-size: 30px; font-weight: 750; letter-spacing: -0.5px; }
.variants { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }

.variant-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 18px; color: var(--text); cursor: pointer;
  transition: transform .08s, border-color .15s;
}
.variant-card:active { transform: scale(0.985); }
.variant-icon {
  flex-shrink: 0; width: 52px; height: 52px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.variant-text { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.variant-name { font-size: 18px; font-weight: 680; }
.variant-desc { color: var(--muted); font-size: 13.5px; line-height: 1.42; }
.variant-arrow { color: var(--muted); font-size: 26px; flex-shrink: 0; }

.variant-roast { border-color: rgba(255,123,80,.35); }
.variant-roast .variant-icon {
  background: linear-gradient(145deg, rgba(255,123,80,.28), rgba(229,83,75,.22));
}
.variant-roast:hover { border-color: rgba(255,123,80,.75); }
.variant-game .variant-icon {
  background: linear-gradient(145deg, rgba(79,140,255,.26), rgba(47,111,237,.2));
}
.variant-game:hover { border-color: var(--accent); }

.text-back {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 4px 0; align-self: flex-start; margin-bottom: -4px;
}
.text-back:hover { color: var(--text); }

/* ---------- Прожарщик ---------- */
.roast-header { background: linear-gradient(180deg, rgba(255,123,80,.16), var(--panel)); }
.roast-name { font-weight: 680; font-size: 16px; }
.docs-badge { color: var(--muted); font-size: 12px; }
.icon-btn.small { font-size: 21px; margin-left: auto; width: 30px; }
#assistant #a-send { background: linear-gradient(145deg, #ff8a5c, #e5534b); }
#assistant #a-input:focus { border-color: #ff8a5c; }
