/* Magic DropBot — общий стиль Mini App.
   Мобильный первый экран: Telegram Mini App почти всегда открывается на телефоне,
   поэтому базовые правила — под узкий экран, @media только РАСШИРЯЕТ (min-width). */

:root {
    --bg-deep: #0f0b1a;
    --bg-mid: #1a1330;
    --bg-glow: #2d1f4a;
    --panel: rgba(255,255,255,0.06);
    --panel-strong: rgba(255,255,255,0.1);
    --panel-border: rgba(255,255,255,0.12);
    --text: #f3eefb;
    --text-dim: rgba(243,238,251,0.68);
    --accent-gold: #e8b923;
    --accent-red: #ff6b6b;
    --accent-blue: #4ecdc4;
    --radius: 16px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Тема рыбалки (Stardew-мотив) переопределяет палитру на своей странице —
   остальная вёрстка (шапка/нав/кнопки) остаётся общей */
body.theme-fishing {
    --bg-deep: #16240f;
    --bg-mid: #2d4420;
    --bg-glow: #4a6a35;
    --panel: rgba(255,248,224,0.08);
    --panel-strong: rgba(255,248,224,0.14);
    --panel-border: rgba(255,236,180,0.18);
    --text: #fdf6e3;
    --text-dim: rgba(253,246,227,0.72);
    --accent-gold: #ffcf5c;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at 20% 0%, var(--bg-glow) 0%, transparent 45%),
        linear-gradient(150deg, var(--bg-deep) 0%, var(--bg-mid) 55%, var(--bg-deep) 100%);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    /* Отступы под чёлку/жесты Telegram-клиента (iOS/Android) */
    padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
}

.container { max-width: 720px; margin: 0 auto; }

a { color: inherit; }
button { font: inherit; }

/* ---------- Шапка и навигация ---------- */
.header { text-align: center; margin-bottom: 18px; }

.header h1 {
    font-size: clamp(1.4em, 6vw, 2.2em);
    margin-bottom: 14px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    line-height: 1.2;
}

.header .tagline {
    color: var(--text-dim);
    font-size: 0.95em;
    margin-top: -8px;
    margin-bottom: 14px;
}

.nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}
.nav::-webkit-scrollbar { display: none; }

.nav-link {
    /* На узком экране три вкладки делят ширину поровну и не заставляют скроллить —
       у самого длинного лейбла текст красиво обрежется, а не вытолкнет соседей.
       min-width:0 обязателен — иначе flex-item не сжимается меньше своего контента. */
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 12px 10px;
    min-height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 14px;
    background: var(--panel);
    border: 1px solid transparent;
    font-size: 0.92em;
    font-weight: 500;
    transition: background .2s, border-color .2s, transform .1s;
}
.nav-link:active { transform: scale(0.97); }
.nav-link.active {
    background: var(--panel-strong);
    border-color: var(--accent-gold);
    font-weight: 700;
}

/* ---------- Универсальные панели/карточки ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}

.btn-primary {
    display: block;
    width: 100%;
    text-align: center;
    text-decoration: none;
    padding: 16px 20px;
    min-height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent-gold), #c9911a);
    color: #241a02;
    font-weight: 800;
    font-size: 1.05em;
    border: none;
    box-shadow: 0 6px 20px rgba(232,185,35,0.28);
    transition: transform .1s, box-shadow .2s;
}
.btn-primary:active { transform: scale(0.98); box-shadow: 0 3px 10px rgba(232,185,35,0.25); }

.btn-back {
    display: inline-block;
    margin-top: 4px;
    padding: 10px 16px;
    min-height: 40px;
    border-radius: 12px;
    background: var(--panel);
    text-decoration: none;
    color: var(--text-dim);
    font-size: 0.9em;
}

/* ---------- Battle Info ---------- */
.battle-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    padding: 14px 16px;
    border-radius: 14px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.battle-status, .battle-timer { font-size: 1.05em; }
.battle-timer { font-weight: 700; }

.demo-banner {
    background: linear-gradient(135deg, rgba(232,185,35,0.18), rgba(232,185,35,0.06));
    border: 1px dashed var(--accent-gold);
    border-radius: 14px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.92em;
    color: var(--text-dim);
    text-align: center;
}

/* ---------- Score Board ---------- */
.score-board {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: rgba(0,0,0,0.28);
    border: 1px solid var(--panel-border);
    padding: 22px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    gap: 10px;
}

.team { text-align: center; flex: 1; min-width: 0; }
.team-name {
    font-size: clamp(1em, 4vw, 1.3em);
    font-weight: 700;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.team.red .team-name { color: var(--accent-red); }
.team.blue .team-name { color: var(--accent-blue); }

.score { font-size: clamp(1.8em, 9vw, 2.6em); font-weight: 800; margin: 6px 0; }
.percent { font-size: 1em; opacity: 0.8; }
.trend { font-size: 1.3em; margin-top: 6px; }
.vs { font-size: 1.3em; font-weight: 800; opacity: 0.6; padding: 0 6px; flex: 0 0 auto; }

/* ---------- Battlefield ---------- */
.battlefield {
    background: rgba(0,0,0,0.35);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 16px;
}
#battle-canvas { width: 100%; height: 220px; border-radius: 10px; display: block; }

/* ---------- Event Log ---------- */
.event-log {
    background: rgba(0,0,0,0.28);
    border: 1px solid var(--panel-border);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    max-height: 280px;
    overflow-y: auto;
}
.event-log h3 { margin-bottom: 12px; font-size: 1em; color: var(--text-dim); }
.event-item {
    background: var(--panel);
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 0.9em;
    line-height: 1.4;
}
.event-item.red { border-left: 3px solid var(--accent-red); }
.event-item.blue { border-left: 3px solid var(--accent-blue); }
.event-item time { color: var(--text-dim); font-weight: 700; margin-right: 6px; }

/* ---------- Teams Info ---------- */
.teams-info { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team-roster {
    background: rgba(0,0,0,0.28);
    border: 1px solid var(--panel-border);
    padding: 14px;
    border-radius: var(--radius);
    min-height: 60px;
}
.team-roster h4 { margin-bottom: 10px; font-size: 1em; }
.team-roster.red h4 { color: var(--accent-red); }
.team-roster.blue h4 { color: var(--accent-blue); }
.fighter {
    background: var(--panel);
    padding: 7px 10px;
    border-radius: 8px;
    margin-bottom: 5px;
    font-size: 0.85em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.roster-empty { color: var(--text-dim); font-size: 0.85em; font-style: italic; }

/* ---------- Dungeon showcase ---------- */
.dungeon-hero { text-align: center; padding: 10px 8px 6px; }
.dungeon-hero .gate {
    font-size: clamp(3.2em, 20vw, 5em);
    display: inline-block;
    animation: torch-flicker 3.2s ease-in-out infinite;
    filter: drop-shadow(0 0 18px rgba(232,185,35,0.35));
}
@keyframes torch-flicker {
    0%, 100% { filter: drop-shadow(0 0 14px rgba(232,185,35,0.30)); transform: scale(1); }
    50% { filter: drop-shadow(0 0 22px rgba(232,185,35,0.5)); transform: scale(1.03); }
}
.dungeon-hero p { color: var(--text-dim); margin-top: 8px; font-size: 0.98em; }

.floor-map {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
    margin: 16px 0;
    font-size: 1.4em;
}
.floor-map span.tag {
    font-size: 0.32em;
    color: var(--text-dim);
    display: block;
    margin-top: 2px;
}

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
.stat-card {
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
}
.stat-card .n { font-size: 1.5em; font-weight: 800; color: var(--accent-gold); }
.stat-card .l { font-size: 0.78em; color: var(--text-dim); margin-top: 2px; }

.loot-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}
.loot-item {
    flex: 0 0 auto;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 10px 14px;
    text-align: center;
    min-width: 84px;
}
.loot-item .ic { font-size: 1.6em; }
.loot-item .t { font-size: 0.72em; color: var(--text-dim); margin-top: 2px; }

/* ---------- Coming Soon ---------- */
.coming-soon { text-align: center; padding: 30px 12px; }
.status-badge {
    display: inline-block;
    background: var(--accent-gold);
    color: #241a02;
    padding: 8px 18px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 0.85em;
    margin-bottom: 22px;
    letter-spacing: 0.03em;
}
.coming-soon h2 { font-size: clamp(1.3em, 6vw, 1.8em); margin-bottom: 14px; }
.coming-soon p { font-size: 1.02em; opacity: 0.85; margin-bottom: 28px; }

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 28px;
    text-align: left;
}
.feature {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    padding: 16px;
    border-radius: 12px;
}
.feature-icon { font-size: 2.2em; margin-bottom: 8px; }
.feature-text { font-size: 0.95em; }

.progress { max-width: 400px; margin: 0 auto; }
.progress-bar {
    background: rgba(255,255,255,0.15);
    height: 16px;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 8px;
}
.progress-fill {
    background: linear-gradient(90deg, var(--accent-gold), #c9911a);
    height: 100%;
    transition: width 0.5s;
}
body.theme-fishing .progress-fill { background: linear-gradient(90deg, #8fbf5c, #5a9145); }
.progress-text { font-size: 1em; color: var(--text-dim); }

.footer-note {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8em;
    margin-top: 22px;
    padding-bottom: 8px;
}

/* ---------- Чуть шире экрана (планшет/десктоп-браузер для отладки) ---------- */
@media (min-width: 480px) {
    .nav-link { flex: 0 1 auto; padding: 12px 22px; }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 720px) {
    body { padding-top: calc(28px + var(--safe-top)); }
    #battle-canvas { height: 320px; }
}
