:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #111111);
    --hint: var(--tg-theme-hint-color, #8a8a8a);
    --link: var(--tg-theme-link-color, #2481cc);
    --button: var(--tg-theme-button-color, #2481cc);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
    --border: rgba(127, 127, 127, 0.18);
    --shadow: 0 1px 0 rgba(0,0,0,0.04);
    --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 640px;
    margin: 0 auto;
    padding: 14px 18px calc(28px + env(safe-area-inset-bottom));
    padding-top: calc(8px + env(safe-area-inset-top));
}

/* -------------------- TOPBAR -------------------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0 14px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
    margin-bottom: 8px;
}
.topbar .back {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
}
.topbar .back:hover { background: var(--secondary-bg); }
.topbar .title {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.topbar .step {
    font-size: 13px;
    color: var(--hint);
    padding: 4px 10px;
    background: var(--secondary-bg);
    border-radius: 100px;
    min-width: 1px;
}

/* -------------------- HOME -------------------- */

.hero { padding: 16px 4px 26px; }
.hero .brand {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg,#6D28D9,#EC4899 60%,#F59E0B);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.hero .sub { color: var(--hint); margin-top: 6px; font-size: 15px; line-height: 1.4; }

.tiles {
    display: grid;
    gap: 12px;
    margin-bottom: 22px;
}
.tile {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--secondary-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    text-align: left;
    transition: transform 0.06s, border-color 0.15s;
    font: inherit;
    color: inherit;
}
.tile:active { transform: scale(0.99); }
.tile:hover { border-color: color-mix(in srgb, var(--button) 50%, var(--border)); }
.tile-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    color: #fff;
    flex-shrink: 0;
}
.tile-body { flex: 1; min-width: 0; }
.tile-title { font-weight: 600; font-size: 16px; }
.tile-sub { color: var(--hint); font-size: 13px; margin-top: 3px; line-height: 1.4; }

.row-actions { display: grid; gap: 8px; }
.row-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 12px;
    padding: 13px 16px;
    font-size: 15px;
    cursor: pointer;
    font: inherit;
    color: inherit;
}
.row-btn:hover { background: var(--secondary-bg); }
.row-btn .chev { color: var(--hint); font-size: 18px; }

/* -------------------- STEPS / FORM -------------------- */

.step-wrap h1 {
    font-size: 26px;
    font-weight: 700;
    margin: 4px 0 6px;
    letter-spacing: -0.02em;
}
.step-wrap .hint {
    color: var(--hint);
    margin: 0 0 18px;
    font-size: 15px;
    line-height: 1.4;
}

.text {
    width: 100%;
    background: var(--secondary-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 17px;
    color: var(--text);
    outline: none;
    font: inherit;
    font-size: 17px;
    transition: border-color 0.15s;
    margin-bottom: 12px;
}
.text:focus { border-color: var(--button); }
.textarea {
    resize: vertical;
    min-height: 160px;
    line-height: 1.5;
}

.counter {
    font-size: 13px;
    color: var(--hint);
    text-align: right;
    margin: -6px 4px 12px;
}

.cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 16px;
}
.cards.count-cards {
    grid-template-columns: 1fr 1fr;
}
@media (min-width: 480px) {
    .cards.count-cards { grid-template-columns: repeat(4, 1fr); }
}
.card {
    appearance: none;
    background: var(--secondary-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 18px;
    font-size: 17px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: transform 0.06s, background 0.15s, border-color 0.15s;
}
.card:active { transform: scale(0.985); }
.card.selected {
    border-color: var(--button);
    background: color-mix(in srgb, var(--button) 12%, var(--bg));
}
.card span { margin-right: 8px; }

.seg {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}
.seg-btn {
    flex: 1;
    appearance: none;
    background: var(--secondary-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}
.seg-btn.active {
    background: var(--button);
    color: var(--button-text);
    border-color: var(--button);
}

.row-buttons {
    display: flex;
    gap: 10px;
}

/* -------------------- TEMPLATES -------------------- */

.templates {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 18px;
}
@media (min-width: 520px) {
    .templates { grid-template-columns: 1fr 1fr; }
}
.tpl {
    border: 1px solid var(--border);
    background: var(--secondary-bg);
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.06s, box-shadow 0.15s;
}
.tpl:active { transform: scale(0.99); }
.tpl.selected {
    border-color: var(--button);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--button) 30%, transparent);
}
.tpl img {
    width: 100%;
    display: block;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}
.tpl .meta {
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.tpl .meta .name { font-weight: 600; font-size: 15px; }
.tpl .meta .sub { color: var(--hint); font-size: 13px; text-align: right; }

/* -------------------- BUTTONS -------------------- */

.primary {
    width: 100%;
    background: var(--button);
    color: var(--button-text);
    border: none;
    border-radius: 14px;
    padding: 15px 18px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
    transition: opacity 0.15s, transform 0.05s;
}
.primary:active:not(:disabled) { transform: scale(0.99); }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.secondary {
    flex: 1;
    background: var(--secondary-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
}

/* -------------------- PROGRESS -------------------- */

.progress-card {
    text-align: center;
    padding: 50px 24px;
}
.progress-card h2 {
    font-size: 22px;
    margin: 18px 0 6px;
    letter-spacing: -0.01em;
}
.progress-card p {
    color: var(--hint);
    margin: 0 0 28px;
    font-size: 15px;
    min-height: 1.4em;
}

.spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid var(--secondary-bg);
    border-top-color: var(--button);
    margin: 0 auto;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar {
    background: var(--secondary-bg);
    border: 1px solid var(--border);
    height: 10px;
    border-radius: 100px;
    overflow: hidden;
    margin: 0 0 8px;
}
.bar-fill {
    height: 100%;
    background: var(--button);
    border-radius: 100px;
    transition: width 0.4s ease;
}
.bar-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text);
}
.bar-meta #prog-pct { font-weight: 700; }

/* -------------------- DONE -------------------- */

.done-card {
    text-align: center;
    padding: 60px 24px;
}
.done-card .check {
    width: 64px;
    height: 64px;
    background: color-mix(in srgb, var(--button) 18%, var(--bg));
    color: var(--button);
    border-radius: 50%;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: 700;
}
.done-card h2 { font-size: 24px; margin: 0 0 8px; letter-spacing: -0.01em; }
.done-card p { color: var(--hint); margin: 0 0 28px; }
.done-card .check.err {
    background: color-mix(in srgb, #EF4444 18%, var(--bg));
    color: #EF4444;
}

/* -------------------- DROP ZONE -------------------- */

.drop {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px 18px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: var(--secondary-bg);
    margin-bottom: 14px;
}
.drop:hover, .drop.drag {
    border-color: var(--button);
    background: color-mix(in srgb, var(--button) 6%, var(--secondary-bg));
}
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.drop-icon { font-size: 28px; }
.drop-title { font-weight: 600; font-size: 15px; }
.drop-sub { color: var(--hint); font-size: 13px; }
.drop.uploaded .drop-title { color: var(--button); }

.divider {
    text-align: center;
    color: var(--hint);
    font-size: 12px;
    margin: 14px 0 10px;
    position: relative;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.divider span { padding: 0 10px; background: var(--bg); position: relative; z-index: 1; }
.divider::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0; right: 0;
    height: 1px;
    background: var(--border);
    z-index: 0;
}

/* -------------------- LIST (MY WORK, MANUAL REVIEW) -------------------- */

.slide-list {
    list-style: none;
    padding: 0;
    margin: 0 0 16px;
    display: grid;
    gap: 8px;
}
.slide-list li, .work-item {
    background: var(--secondary-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.4;
}
.slide-list .stitle { font-weight: 600; margin-bottom: 4px; font-size: 15px; }
.slide-list .sbody { color: var(--hint); font-size: 13px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}
.work-item .wmeta { color: var(--hint); font-size: 12px; margin-top: 3px; }

/* -------------------- TOAST -------------------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(28px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    background: rgba(0,0,0,0.86);
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    z-index: 50;
    max-width: 92vw;
    text-align: center;
}
