/* VoiceTrainer — Plata-inspired: graphite/silver neutrals, one premium accent, airy & rounded.
   Page bg/text follow the Telegram theme (light/dark); brand tokens are fixed for consistency. */
:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --surface: var(--tg-theme-secondary-bg-color, #f3f3f6);
    --surface-2: color-mix(in srgb, var(--surface) 60%, var(--bg));
    --text: var(--tg-theme-text-color, #0c0c10);
    --hint: var(--tg-theme-hint-color, #8b8b93);

    --brand: #6e62f0;
    --brand-grad: linear-gradient(135deg, #8b7bff 0%, #5b46e0 100%);
    --on-brand: #ffffff;
    --ok: #18b277;
    --danger: #e3533c;

    --line: rgba(130, 130, 145, 0.18);
    --r-sm: 12px;
    --r: 16px;
    --r-lg: 22px;
    --r-xl: 28px;
    --shadow: 0 8px 28px rgba(25, 22, 50, 0.12);
    --shadow-sm: 0 2px 10px rgba(25, 22, 50, 0.07);
    --gap: 12px;
}

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

body {
    margin: 0;
    touch-action: manipulation; /* kill double-tap-to-zoom (and the tap delay); pinch still works */
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* In Telegram fullscreen the webview starts at y=0, so content slides under the status bar and the
   Telegram header. Pad by the device safe area (env / Telegram's safeAreaInset, whichever is larger,
   to avoid double counting) plus the Telegram header inset (contentSafeAreaInset). Vars set in app.js. */
#app {
    padding: calc(14px + max(env(safe-area-inset-top, 0px), var(--tg-safe-top, 0px)) + var(--tg-content-top, 0px))
             16px
             calc(40px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom, 0px)));
    max-width: 560px;
    margin: 0 auto;
}

.loading, .notice { color: var(--hint); text-align: center; padding: 44px 0; }

h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0 18px; }
h2 {
    font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--hint); margin: 24px 0 10px;
}

.brand {
    display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -0.02em;
    font-size: 17px; color: var(--text); margin: 4px 0 2px;
}
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand-grad); }

.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.hint { color: var(--hint); font-weight: 400; }

/* ---- cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    transition: transform .12s ease, box-shadow .12s ease;
}
.card .title { font-weight: 650; font-size: 16.5px; }
.card .sub { color: var(--hint); font-size: 14px; margin-top: 3px; }
.card.clickable { cursor: pointer; }
.card.clickable:active { transform: scale(0.985); box-shadow: var(--shadow); }

.code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
    padding: 6px 10px; letter-spacing: .12em; font-size: 15px;
}

/* ---- forms ---- */
label { display: block; font-size: 13px; color: var(--hint); margin: 14px 0 6px; font-weight: 600; }
input, textarea, select {
    width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--r);
    background: var(--surface-2); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
textarea { min-height: 64px; resize: vertical; }
input[type="file"] { padding: 11px 12px; }
input[type="checkbox"] { width: 26px; height: 26px; accent-color: var(--brand); padding: 0; }

/* ---- buttons ---- */
button {
    font: inherit; font-weight: 650; border: none; border-radius: var(--r);
    padding: 13px 18px; background: var(--brand-grad); color: var(--on-brand);
    cursor: pointer; transition: transform .1s ease, filter .15s ease; box-shadow: var(--shadow-sm);
}
button:active { transform: scale(0.97); }
button:disabled { opacity: .5; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
button.link { background: none; color: var(--brand); padding: 8px 2px; box-shadow: none; font-weight: 600; }
button.danger { background: none; color: var(--danger); box-shadow: none; font-weight: 600; }
button.icon { background: var(--surface); color: var(--text); border: 1px solid var(--line); padding: 8px 12px; box-shadow: none; }

.toolbar { display: flex; gap: 10px; margin: 14px 0; }
.toolbar button { flex: 1; }

.error { color: var(--danger); padding: 12px 0; }
.empty { color: var(--hint); padding: 24px 4px; text-align: center; }
.back { color: var(--brand); cursor: pointer; margin-bottom: 8px; display: inline-block; font-weight: 600; }
.hidden { display: none !important; }

/* ---- import (tabs / separators / preview) ---- */
.tabs { display: flex; gap: 8px; margin: 10px 0; background: var(--surface); padding: 4px; border-radius: var(--r); }
.tabs .tab { flex: 1; background: none; color: var(--hint); box-shadow: none; padding: 10px; }
.tabs .tab.active { background: var(--bg); color: var(--text); box-shadow: var(--shadow-sm); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 6px; }
.seg-btn { background: var(--surface); color: var(--hint); padding: 9px 14px; font-size: 14px; box-shadow: none; border: 1px solid var(--line); }
.seg-btn.active { background: var(--brand-grad); color: var(--on-brand); border-color: transparent; }
.preview { margin-top: 14px; }
.parsed-count { color: var(--hint); font-size: 13px; margin-bottom: 8px; font-weight: 600; }
.pair { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; margin-bottom: 6px; }
.pair .q { font-weight: 600; }
.pair .a { color: var(--hint); font-size: 14px; }

/* ---- home fork ---- */
.home { display: flex; flex-direction: column; gap: 14px; padding: 8px 0 24px; min-height: 76vh; }
.home .brand { margin-bottom: auto; }
.home-btn {
    position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start;
    gap: 6px; text-align: left; border-radius: var(--r-xl); line-height: 1.15; box-shadow: var(--shadow);
}
.home-study {
    background: var(--brand-grad); color: var(--on-brand); padding: 30px 24px 28px;
}
/* metallic sheen — a nod to "Plata" (silver) */
.home-study::after {
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(120% 90% at 85% -10%, rgba(255,255,255,.35), transparent 55%);
    pointer-events: none;
}
.home-study .home-label { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.home-teach { background: var(--surface); color: var(--text); border: 1px solid var(--line); padding: 22px 24px; box-shadow: var(--shadow-sm); }
.home-teach .home-label { font-size: 21px; font-weight: 700; }
.home-hint { font-size: 14px; opacity: .82; }

/* ---- swipe study ---- */
.swipe-progress { text-align: center; color: var(--text); font-weight: 700; font-size: 14px; margin: 2px 0 2px; letter-spacing: -0.01em; }
.swipe-hint { text-align: center; color: var(--hint); font-size: 13px; margin: 4px 0 14px; }
.swipe-card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
    padding: 26px 22px; min-height: 48vh; display: flex; perspective: 1100px;
    box-shadow: var(--shadow); touch-action: pan-y; cursor: pointer; will-change: transform;
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.swipe-card * { user-select: none; -webkit-user-select: none; }
.swipe-inner {
    flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; gap: 14px; transition: transform .14s ease; backface-visibility: hidden;
}
.swipe-q { font-size: 23px; font-weight: 700; letter-spacing: -0.01em; }
.swipe-a { font-size: 17px; white-space: pre-wrap; color: var(--text); }
.join-box { display: flex; gap: 8px; margin-top: 10px; }
.join-box input { flex: 1; }
.join-box button { flex: 0 0 auto; }

.swipe-done { text-align: center; padding: 64px 0; }
.swipe-done .big { font-size: 26px; font-weight: 800; margin-bottom: 8px; letter-spacing: -0.02em; }
#know { background: linear-gradient(135deg, #2fd089, #18b277); }
#dont { background: var(--surface); color: var(--danger); border: 1px solid var(--line); box-shadow: none; }

/* Gamification: level/XP card, mastery bar, green/yellow/red counts. */
.level-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; margin-top: 12px; box-shadow: var(--shadow-sm); }
.level-name { font-weight: 800; letter-spacing: -0.01em; }
.mbar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.mbar-fill { height: 100%; background: var(--brand-grad); border-radius: 999px; transition: width .35s ease; }
.counts { display: inline-flex; gap: 14px; font-size: 13px; font-weight: 700; }
.counts .c-green { color: var(--ok); }
.counts .c-yellow { color: #d59f00; }
.counts .c-red { color: var(--danger); }
