/* ══════════════════════════════════════════════════════════════
   ЗОНА НОЛЬ — Styles
   Target: iPhone 14/15 (390×844 pt) via Edge DevTools
   Safe areas, touch targets 44pt+, no zoom on inputs
════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    /* Remove 300ms tap delay everywhere */
    touch-action: manipulation;
}

:root {
    /* ── DARK THEME "БУНКЕР" (default) ───────────────────────── */
    --bg:           #080808;
    --surface:      #111111;
    --card:         #1a1a1a;
    --border:       #262626;
    --text:         #e0e0e0;
    --muted:        #555555;
    --accent:       #b8ff00;
    --danger:       #ff3b3b;

    /* Text on appbar/bars */
    --header-text:  #ffffff;

    /* Warn / tip box text */
    --warn-text:    #ff9898;
    --tip-text:     rgba(184,255,0,.85);
    --tip-bg:       rgba(184,255,0,.06);
    --warn-bg:      rgba(255,59,59,.09);

    /* Splash glow animation colors */
    --glow-lo:      rgba(184,255,0,.75);
    --glow-hi:      rgba(184,255,0,1);

    /* Logo img filter: invert black→white for dark bg */
    --logo-filter:  invert(1) brightness(.9);

    /* Safe area shorthands */
    --sat: env(safe-area-inset-top,    0px);
    --sar: env(safe-area-inset-right,  0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left,   0px);

    /* Bar height without safe area — content rows are 52pt */
    --bar-content-h: 52px;
    --radius: 12px;
}

/* ── LIGHT THEME "УСТАВ" (field manual / military paper) ─────── */
[data-theme="light"] {
    --bg:           #f0ead8;
    --surface:      #e5dfc8;
    --card:         #d8d0bb;
    --border:       #b8b099;
    --text:         #1a1610;
    --muted:        #7a7060;
    --accent:       #4a7400;
    --danger:       #b82222;

    --header-text:  #1a1610;
    --warn-text:    #7a1010;
    --tip-text:     #2d5000;
    --tip-bg:       rgba(74,116,0,.08);
    --warn-bg:      rgba(184,28,28,.07);

    --glow-lo:      rgba(74,116,0,.5);
    --glow-hi:      rgba(74,116,0,.9);

    --logo-filter:  none;
}

html {
    height: 100%;
    /* Prevent elastic bounce on iOS */
    overscroll-behavior: none;
}

body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    /* Prevent iOS text size adjustment */
    -webkit-text-size-adjust: 100%;
    /* Prevent rubber-band on body */
    overscroll-behavior: none;
}

/* ── SCREEN SYSTEM ────────────────────────────────────────────── */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    background: var(--bg);
    /* Prevent entire screen from scrolling on iOS */
    overflow: hidden;
}
.screen.active {
    opacity: 1;
    pointer-events: all;
}

/* ── SPLASH ───────────────────────────────────────────────────── */
#splash { background: #000; }

.splash-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
}

.splash-vignette {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0,0,0,.2)  0%,
        rgba(0,0,0,.05) 30%,
        rgba(0,0,0,.72) 65%,
        rgba(0,0,0,.97) 100%
    );
}

.splash-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    /* Top: below Dynamic Island / notch */
    padding-top: max(30vh, calc(var(--sat) + 28vh));
    padding-left: max(28px, calc(var(--sal) + 20px));
    padding-right: max(28px, calc(var(--sar) + 20px));
    /* Bottom: above home indicator */
    padding-bottom: max(56px, calc(var(--sab) + 32px));
}

.splash-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.splash-icon {
    font-size: 60px;
    line-height: 1;
    color: var(--accent);
    filter: drop-shadow(0 0 28px rgba(184,255,0,.75));
    animation: nuclearGlow 2.5s ease-in-out infinite;
}

@keyframes nuclearGlow {
    0%, 100% { filter: drop-shadow(0 0 28px var(--glow-lo)); }
    50%       { filter: drop-shadow(0 0 56px var(--glow-hi)); }
}

.splash-title {
    font-size: 38px;
    font-weight: 900;
    letter-spacing: 10px;
    color: #fff;
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 48px rgba(184,255,0,.25);
}

.splash-sub {
    font-size: 9px;
    letter-spacing: 5px;
    color: var(--muted);
    font-family: 'Courier New', monospace;
    margin-top: 4px;
}

.splash-loader {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.loader-track {
    width: 100%;
    height: 1px;
    background: rgba(255,255,255,.1);
    overflow: hidden;
}

.loader-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    transition: width 2.4s cubic-bezier(.4,0,.2,1);
}

.loader-text {
    font-size: 9px;
    letter-spacing: 4px;
    color: var(--muted);
    font-family: 'Courier New', monospace;
}

/* ── APPBAR ───────────────────────────────────────────────────── */
/*
 * padding-top = safe-area-inset-top pushes content below Dynamic Island.
 * align-items:center then centers items in the remaining content row (52px).
 */
.appbar {
    flex-shrink: 0;
    padding-top: var(--sat);
    padding-left: max(16px, var(--sal));
    padding-right: max(16px, var(--sar));
    padding-bottom: 0;
    min-height: calc(var(--bar-content-h) + var(--sat));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.appbar-icon  { font-size: 18px; color: var(--accent); }
.appbar-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 5px;
    color: var(--header-text);
    font-family: 'Courier New', monospace;
}

.theme-btn {
    margin-left: auto;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-size: 15px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color .15s, border-color .15s;
    -webkit-user-select: none;
    user-select: none;
}
.theme-btn:active { opacity: .6; }

/* ── HOME / BLOCKS GRID ───────────────────────────────────────── */
.home-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 12px max(12px, var(--sal)) max(16px, calc(var(--sab) + 8px)) max(12px, var(--sar));
}

.blocks-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.block-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 4 / 5;
    cursor: pointer;
    background: var(--card);
    border: 1px solid var(--border);
    transition: transform .12s ease, opacity .12s ease;
    /* Minimum touch target covered by aspect-ratio — OK at 2 cols */
    -webkit-user-select: none;
    user-select: none;
}
.block-card:active { transform: scale(.95); opacity: .82; }

.block-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    /* Crisp on Retina */
    image-rendering: auto;
}

.block-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent 25%, rgba(0,0,0,.9) 100%);
}

.block-card-body {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 10px 14px;
}

.block-card-num {
    font-size: 9px;
    color: var(--accent);
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
    margin-bottom: 3px;
}

.block-card-name {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 2px;
    color: #fff;
    text-transform: uppercase;
    line-height: 1.1;
    font-family: 'Courier New', monospace;
}

.block-card-desc {
    font-size: 10px;
    color: rgba(255,255,255,.5);
    margin-top: 4px;
    line-height: 1.4;
}

/* ── BLOCK SCREEN ─────────────────────────────────────────────── */
.hero-wrap {
    flex-shrink: 0;
    position: relative;
    /* Hero height: adapt to iPhone — status bar + 180px visual image */
    height: calc(var(--sat) + 220px);
}

.hero-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.hero-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,.35) 0%, rgba(0,0,0,.88) 100%);
}

/* Back button: always below status bar */
.hero-back-btn {
    position: absolute;
    /* Top = status bar height + 10px gap */
    top: calc(var(--sat) + 10px);
    left: max(12px, var(--sal));
    background: rgba(0,0,0,.6);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 8px;
    color: #fff;
    font-size: 11px;
    font-family: 'Courier New', monospace;
    /* Minimum Apple touch target: 44×44pt */
    min-width: 44px;
    min-height: 44px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    letter-spacing: 1px;
    -webkit-user-select: none;
    user-select: none;
}

.hero-meta {
    position: absolute;
    bottom: 14px;
    left: max(16px, var(--sal));
}

.hero-num {
    font-size: 10px;
    color: var(--accent);
    font-family: 'Courier New', monospace;
    letter-spacing: 3px;
    margin-bottom: 2px;
}

.hero-name {
    font-size: 26px;
    font-weight: 900;
    letter-spacing: 4px;
    color: #fff;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
}

.block-articles {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-bottom: max(16px, calc(var(--sab) + 8px));
}

.article-row {
    display: flex;
    align-items: center;
    gap: 12px;
    /* Minimum 44pt touch target height */
    min-height: 64px;
    padding: 12px max(16px, var(--sar)) 12px max(16px, var(--sal));
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .12s;
    -webkit-user-select: none;
    user-select: none;
}
.article-row:active { background: var(--card); }

.article-row-num {
    font-size: 10px;
    color: var(--accent);
    font-family: 'Courier New', monospace;
    width: 22px;
    flex-shrink: 0;
}

.article-row-text { flex: 1; min-width: 0; }

.article-row-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 3px;
}

.article-row-preview {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.article-row-arrow {
    color: var(--muted);
    font-size: 18px;
    flex-shrink: 0;
}

/* ── SIMPLE BAR (article / custom) ───────────────────────────── */
.simple-bar {
    flex-shrink: 0;
    padding-top: var(--sat);
    padding-left: max(16px, var(--sal));
    padding-right: max(16px, var(--sar));
    padding-bottom: 0;
    min-height: calc(var(--bar-content-h) + var(--sat));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.simple-back {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 12px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    min-height: 44px;
    padding: 0 4px 0 0;
    display: flex;
    align-items: center;
    white-space: nowrap;
    letter-spacing: 1px;
    flex-shrink: 0;
    -webkit-user-select: none;
    user-select: none;
}

.simple-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Courier New', monospace;
}

/* ── ARTICLE CONTENT ──────────────────────────────────────────── */
.article-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 20px max(16px, var(--sar)) max(48px, calc(var(--sab) + 32px)) max(16px, var(--sal));
}

.article-content h3 {
    font-size: 10px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin: 24px 0 10px;
    font-family: 'Courier New', monospace;
}
.article-content h3:first-child { margin-top: 0; }

.article-content p {
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
    margin-bottom: 10px;
}

.article-content ul,
.article-content ol {
    padding-left: 20px;
    margin-bottom: 12px;
}

.article-content li {
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
    margin-bottom: 4px;
}

.article-content strong { color: #fff; }

/* Warning box */
.warn-box {
    background: var(--warn-bg);
    border-left: 3px solid var(--danger);
    padding: 12px 14px;
    border-radius: 0 8px 8px 0;
    margin: 14px 0;
}
.warn-box p {
    font-size: 14px;
    color: var(--warn-text);
    margin: 0;
    line-height: 1.65;
}

/* Tip box */
.tip-box {
    background: var(--tip-bg);
    border-left: 3px solid var(--accent);
    padding: 12px 14px;
    border-radius: 0 8px 8px 0;
    margin: 14px 0;
}
.tip-box p {
    font-size: 14px;
    color: var(--tip-text);
    margin: 0;
    line-height: 1.65;
}

/* Tables */
.article-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    font-size: 13px;
}
.article-content th {
    background: var(--card);
    color: var(--accent);
    padding: 10px 8px;
    text-align: left;
    font-family: 'Courier New', monospace;
    font-size: 9px;
    letter-spacing: 2px;
    border-bottom: 2px solid var(--border);
}
.article-content td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: top;
    line-height: 1.5;
}
.article-content td:first-child { color: #fff; font-weight: 600; }

/* Image placeholder */
.img-placeholder {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
    gap: 8px;
}
.img-placeholder-icon  { font-size: 32px; opacity: .2; }
.img-placeholder-label {
    font-size: 9px;
    letter-spacing: 3px;
    color: var(--muted);
    font-family: 'Courier New', monospace;
}

/* Real images in articles */
.article-img {
    width: 100%;
    border-radius: var(--radius);
    margin: 16px 0;
    display: block;
}

/* ── CUSTOM (ПРОЧЕЕ) SCREEN ───────────────────────────────────── */
.custom-scroll {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-bottom: max(48px, calc(var(--sab) + 32px));
}

.custom-hero-wrap {
    position: relative;
    height: 160px;
    flex-shrink: 0;
}
.custom-hero-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.custom-hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent 10%, rgba(0,0,0,.88) 100%);
    display: flex;
    align-items: flex-end;
    padding: 14px max(16px, var(--sar)) 14px max(16px, var(--sal));
}
.custom-hero-desc {
    font-size: 12px;
    color: rgba(255,255,255,.55);
    line-height: 1.5;
}

.custom-form-block {
    padding: 20px max(16px, var(--sar)) 0 max(16px, var(--sal));
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-label {
    font-size: 9px;
    letter-spacing: 3px;
    color: var(--accent);
    font-family: 'Courier New', monospace;
    margin-bottom: 2px;
}

/* iOS: font-size ≥ 16px prevents auto-zoom on focus */
.custom-field {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s;
    /* Minimum 44pt touch target */
    min-height: 44px;
    -webkit-appearance: none;
    appearance: none;
}
.custom-field:focus { border-color: var(--accent); }

.custom-textarea {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    resize: none;
    min-height: 120px;
    transition: border-color .15s;
    -webkit-appearance: none;
    appearance: none;
}
.custom-textarea:focus { border-color: var(--accent); }

.custom-save-btn {
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 10px;
    /* 44pt minimum */
    min-height: 50px;
    padding: 0 16px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 3px;
    font-family: 'Courier New', monospace;
    cursor: pointer;
    transition: opacity .12s;
    -webkit-user-select: none;
    user-select: none;
}
.custom-save-btn:active { opacity: .82; }

#customEntriesWrap {
    padding: 24px max(16px, var(--sar)) 0 max(16px, var(--sal));
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.custom-list { display: flex; flex-direction: column; gap: 10px; }

.custom-entry {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}
.custom-entry-title { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 6px; }
.custom-entry-body  { font-size: 14px; color: var(--text); line-height: 1.6; white-space: pre-wrap; }
.custom-entry-date  {
    font-size: 9px;
    color: var(--muted);
    margin-top: 10px;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}

.custom-empty {
    padding: 32px 16px;
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
}

/* ── SCROLLBAR (desktop only) ─────────────────────────────────── */
@media (hover: hover) {
    ::-webkit-scrollbar { width: 3px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
}
