:root {
  --bg: var(--tg-theme-bg-color, #1c1c1e);
  --text: var(--tg-theme-text-color, #f2f2f7);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --btn: var(--tg-theme-button-color, #2ea6ff);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --sec: var(--tg-theme-secondary-bg-color, #2c2c2e);
  --danger: #ff453a;
  --ok: #30d158;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif; }
body { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }

.app { max-width: 480px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 8px; font-weight: 650; }
h2 { font-size: 18px; margin: 0 0 12px; font-weight: 650; }
p { margin: 0 0 12px; color: var(--hint); line-height: 1.4; }

.row { display: flex; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.stat { background: var(--sec); border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 11px; color: var(--hint); }

.card, .list button, .opt, .key {
  background: var(--sec); border: 0; color: var(--text); border-radius: 12px;
  width: 100%; text-align: left; padding: 14px 16px; font-size: 16px;
}
.list { display: flex; flex-direction: column; gap: 8px; }
.list button { display: flex; justify-content: space-between; align-items: center; }
.list button:active, .opt:active, .key:active { opacity: 0.75; }
.muted { color: var(--hint); font-size: 13px; }

.primary, .tg-main {
  background: var(--btn); color: var(--btn-text); border: 0; border-radius: 12px;
  width: 100%; padding: 14px; font-size: 16px; font-weight: 600; margin-top: 8px;
}
.ghost { background: transparent; color: var(--btn); border: 0; padding: 12px; width: 100%; font-size: 15px; }

.morse {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 28px; letter-spacing: 0.08em; text-align: center;
  background: var(--sec); border-radius: 16px; padding: 28px 12px; margin: 16px 0;
  word-break: break-word;
}
.prompt { font-size: 26px; text-align: center; font-weight: 650; margin: 16px 0 8px; }
.bar { font-size: 13px; color: var(--hint); text-align: center; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt { text-align: center; font-weight: 600; }
.opt.picked-bad { outline: 2px solid var(--danger); }

.pads { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 10px; }
.pad {
  background: var(--sec); border: 0; color: var(--text); border-radius: 16px;
  min-height: 88px; font-size: 40px; font-weight: 700;
  outline: none; -webkit-tap-highlight-color: transparent;
}
.pad:focus, .pad:focus-visible { outline: none; }
.pad:active { transform: scale(0.97); }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.ctrl {
  background: var(--sec); border: 0; color: var(--hint); border-radius: 12px;
  padding: 12px; font-size: 14px;
  outline: none; -webkit-tap-highlight-color: transparent;
}
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.feedback { min-height: 22px; text-align: center; font-size: 14px; margin: 0 0 8px; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--danger); }
.buf { min-height: 52px; text-align: center; font-family: ui-monospace, Menlo, monospace;
  font-size: 28px; margin: 8px 0; letter-spacing: 0.1em; }
.buf-box { background: var(--sec); border-radius: 16px; padding: 16px 12px; }

.flash-ok { outline: 2px solid var(--ok); }
.flash-bad { outline: 2px solid var(--danger); }
.stars { letter-spacing: 2px; color: #ffd60a; }
.sample { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.chip { background: var(--sec); border-radius: 8px; padding: 6px 10px; font-size: 14px; }
.err { color: var(--danger); margin: 12px 0; }
