/* =============================================
   LeafNet — compact PWA layout
   Fixed viewport: header + main + tab bar
   ============================================= */

:root {
    --cocoa: #4a7c59;
    --cocoa-l: #7eb89c;
    --cocoa-xl: #a8d4ba;
    --t1: #f0ece6;
    --t2: #a89f97;
    --t3: #555;
    --border: #1a1a1a;
    --surface: #0a0a0a;
    --surface-2: #050505;
    --accent-green: #33ff99;
    --header-h: 60px;
    --tabbar-h: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
    background: #000;
}

body {
    font-family: 'Montserrat', sans-serif;
    color: var(--t1);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
}

button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

/* ---- Header ---- */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    background: #000;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    z-index: 100;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: #000;
}

.brand-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--t1);
}

/* ---- Main scroll area ---- */
.app-main {
    position: fixed;
    top: calc(var(--header-h) + var(--safe-top));
    left: 0;
    right: 0;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom));
    overflow: hidden;
}

.tab-panel {
    display: none;
    height: 100%;
    width: 100%;
    flex-direction: column;
}

.tab-panel.active {
    display: flex;
}

/* =============================================
   DETECT TAB
   ============================================= */

#tab-detect {
    padding: 12px;
    gap: 12px;
}

.stage {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

.stage-empty {
    text-align: center;
    cursor: pointer;
    padding: 24px;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: background 0.2s;
}

.stage-empty:active {
    background: rgba(200, 154, 108, 0.04);
}

.stage-empty.dragover {
    background: rgba(200, 154, 108, 0.06);
}

.stage-empty i {
    font-size: 48px;
    color: var(--cocoa-l);
    opacity: 0.6;
}

.stage-empty p {
    font-size: 14px;
    font-weight: 600;
    color: var(--t1);
}

.stage-empty span {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--t3);
}

.stage-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* ---- Stats bar ---- */
.stats-bar {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    gap: 8px;
}

.stat {
    flex: 1;
    text-align: center;
    padding: 4px;
}

.stat + .stat {
    border-left: 1px solid var(--border);
}

.stat-label {
    display: block;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--t2);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--cocoa-l);
}

/* ---- Action row ---- */
.action-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--t2);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover:not(:disabled),
.btn-icon:active:not(:disabled) {
    border-color: var(--cocoa);
    color: var(--cocoa-l);
}

.btn-icon:disabled {
    opacity: 0.35;
}

.btn-detect {
    flex: 1;
    height: 48px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--cocoa);
    color: var(--cocoa-l);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-detect:hover:not(:disabled),
.btn-detect:active:not(:disabled) {
    background: var(--cocoa);
    color: var(--t1);
}

.btn-detect:disabled {
    opacity: 0.4;
    border-color: var(--border);
    color: var(--t3);
}

.btn-detect.loading {
    pointer-events: none;
}

.btn-detect.loading i {
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* =============================================
   SETTINGS TAB
   ============================================= */

#tab-settings {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 14px 8px;
    scrollbar-width: none;
}
#tab-settings::-webkit-scrollbar { display: none; }

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.section-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--t2);
    margin-bottom: 4px;
}

.setting-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    margin: 0;
}

.block-title {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--t2);
    margin-bottom: 14px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.setting-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--t1);
}

.setting-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--cocoa-l);
}

.setting-hint {
    font-size: 10px;
    font-weight: 500;
    color: var(--t3);
    margin-top: 8px;
    line-height: 1.5;
}

/* Slider */
input[type="range"] {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: #1a1a1a;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--cocoa-l);
    cursor: pointer;
    border: 2px solid #000;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--cocoa-l);
    cursor: pointer;
    border: 2px solid #000;
}

/* Color palette */
.color-palette {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.color-swatch {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--c);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.06);
}

.color-swatch[aria-checked="true"] {
    border-color: var(--t1);
    box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--c);
}

/* Toggle row */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

/* Wrap pattern: control border/padding via the wrapper, not the row */
.toggle-wrap:last-child .toggle-row {
    border-bottom: none;
    padding-bottom: 0;
}

.toggle-wrap:first-of-type .toggle-row {
    padding-top: 0;
}

.toggle-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toggle-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--t1);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.toggle-desc {
    font-size: 10px;
    color: var(--t3);
    line-height: 1.4;
}

/* Info icon button next to toggle name */
.info-btn {
    background: #1a1a1a;
    border: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    padding: 0;
    color: var(--t2);
    font-size: 9px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s;
    flex-shrink: 0;
    font-weight: 700;
    font-family: 'Montserrat', sans-serif;
    font-style: normal;
}
.info-btn::before {
    content: 'i';
    font-style: normal;
    line-height: 1;
}
.info-btn i {
    display: none;
}
.info-btn:hover, .info-btn.open {
    background: var(--cocoa);
    color: var(--t1);
}

/* Inline tooltip below the toggle row */
.info-tooltip {
    grid-column: 1 / -1;
    background: #050505;
    border: 1px solid var(--cocoa);
    border-radius: 10px;
    padding: 10px 12px;
    margin-top: 8px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.55;
    color: var(--t2);
    animation: tooltipIn 0.18s ease;
}

@keyframes tooltipIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Wrap the toggle row + tooltip together */
.toggle-wrap {
    display: flex;
    flex-direction: column;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #1a1a1a;
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-green);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* =============================================
   ABOUT TAB
   ============================================= */

#tab-about {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px 14px 12px;
    scrollbar-width: none;
}
#tab-about::-webkit-scrollbar { display: none; }

.about-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.about-hero {
    text-align: center;
    padding: 16px 0 8px;
}

.about-logo {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 12px;
    box-shadow: 0 0 0 3px var(--border);
}

.about-hero h2 {
    font-size: 22px;
    font-weight: 800;
    color: var(--t1);
    letter-spacing: -0.02em;
}

.about-tagline {
    font-size: 11px;
    font-weight: 600;
    color: var(--cocoa-l);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    margin-top: 4px;
}

.about-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    margin: 0;
}

.about-block h3 {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--cocoa-l);
    margin-bottom: 8px;
}

.about-block p {
    font-size: 13px;
    line-height: 1.65;
    color: var(--t2);
    font-weight: 500;
}

.about-block ul {
    list-style: none;
    padding: 0;
}

.about-block li {
    font-size: 13px;
    line-height: 1.7;
    color: var(--t2);
    font-weight: 500;
    padding-left: 18px;
    position: relative;
}

.about-block li::before {
    content: '\f105';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: var(--cocoa-l);
    position: absolute;
    left: 0;
    top: 1px;
}

.about-block b {
    color: var(--t1);
    font-weight: 700;
}

.about-footer {
    text-align: center;
    padding: 12px 0 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}

.install-btn {
    background: var(--surface);
    border: 1px solid var(--cocoa);
    color: var(--cocoa-l);
    padding: 12px 24px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.install-btn:hover,
.install-btn:active {
    background: var(--cocoa);
    color: var(--t1);
}

.about-credit {
    font-size: 10px;
    color: var(--t3);
    font-weight: 600;
    letter-spacing: 0.1em;
}

/* =============================================
   BOTTOM TAB BAR
   ============================================= */

.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: #000;
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--t3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    padding: 0;
}

.tab-btn i {
    font-size: 22px;
}

.tab-btn.active {
    color: var(--cocoa-l);
}

.tab-btn:active:not(.active) {
    color: var(--t2);
}

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Tablet/Desktop adjustments ---- */
@media (min-width: 768px) {
    .app-main {
        max-width: 540px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: 100%;
    }

    .app-header,
    .tab-bar {
        max-width: 540px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: 100%;
    }

    body {
        background: #000;
    }
}
