/* Police chargée localement : Exo-2 + Sawer */

@font-face {
    font-family: "Exo-2";
    src: url("/fonts/Exo-2/Exo2-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Exo-2";
    src: url("/fonts/Exo-2/Exo2-SemiBold.woff2") format("woff2");
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Exo-2";
    src: url("/fonts/Exo-2/Exo2-Bold.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Sawer";
    src: url("/fonts/Sawer.woff2")
        format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

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

:root {
    --bg:       #080B14;
    --surface:  #0f1220;
    --surface2: #171b2e;
    --border:   #252840;
    --accent:   #7027CF;
    --accent2:  #A368FF;
    --indigo:   #2D4FCC;
    --text:     #DDE8FF;
    --muted:    #5a6080;
    --danger:   #e05050;
    --btn24:    #2D4FCC;
    --btn30:    #7027CF;
    --border2:  #353A60;
    --accent-h: #8B3FF5;

    --font-ui: "Exo-2", sans-serif;
    --font-heading: "Sawer", cursive;
    --font-display: "Jolly Lodger", cursive;

    --radius: 24px;
    --transition: 0.12s;


    --btn-height: 28px;
    --btn-sm-height: 24px;
    --input-radius: 3px;

    /* ── TYPOGRAPHIC SCALE ── */
    --text-3xs: 0.625rem;    /* 10px  — tags, badge, logo-sub               */
    --text-2xs: 0.6875rem;   /* 11px  — subtitles, meta, lang               */
    --text-xs:   0.75rem;    /* 12px  — labels mono, .section-label        */
    --text-sm:   0.875rem;   /* 14px  — secondaire, captions, boutons       */
    --text-base: 1rem;       /* 16px  — corps de texte <p>                  */
    --text-lg:   1.125rem;   /* 18px  — lead, intro                         */
    --text-h3:   1.375rem;   /* 22px  — h3 mobile                           */
    --text-h2:   1.75rem;    /* 28px  — h2 mobile                           */
    --text-h1:   clamp(32px, 5vw, 40px);       /* 32-40px  — h1 responsive          */
}

html, body {
    height: 100%; overflow: hidden;
    background: var(--bg); color: var(--text);
    font-family: var(--font-ui); font-size: var(--text-base);
}

/* ────────────────────────────────────────────
   APP SHELL
─────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ────────────────────────────────────────────
   TOP NAV — tab bar + toolbar (SF6 style)
─────────────────────────────────────────────── */
.topnav {
    height: 44px;
    background: var(--surface);
    border-bottom: 2px solid var(--accent);
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
    position: relative;
    z-index: 300;
}

/* Tabs */
.tabs { display: flex; align-items: stretch; }
.tab {
    padding: 0 20px;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    color: var(--muted);
    font-family: var(--font-heading);
    font-size: var(--text-h3); font-weight: 400;
    letter-spacing: 2px; text-transform: uppercase;
    cursor: pointer;
    transition: color .12s, background .12s;
    display: flex; align-items: center; gap: 6px;
    white-space: nowrap;
    user-select: none;
}
.tab .tab-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor; opacity: 0.4;
    transition: opacity .12s;
}
.tab:hover { color: var(--accent2); background: rgba(109,40,217,.07); }
.tab:hover .tab-dot { opacity: 0.7; }
.tab.is-active { background: var(--accent); color: #fff; }
.tab.is-active .tab-dot { opacity: 1; background: rgba(255,255,255,.8); }

/* Toolbar (floating HUD in canvas) */
.toolbar {
    position: absolute;
    bottom: 36px; right: 12px;
    display: flex; align-items: center;
    gap: 3px;
    padding: 6px 10px;
    background: transparent;
    border-radius: var(--radius);
    z-index: 100;
}
.toolbar__sep { width: 1px; height: 14px; background: var(--border2); margin: 0 4px; }

/* ────────────────────────────────────────────
   TAB PANELS — absolute overlay below nav
─────────────────────────────────────────────── */
.panels-host {
    position: relative;
    flex-shrink: 0;
    z-index: 250;
}

.tab-panel {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    border-bottom: 2px solid var(--border2);
    padding: 10px 16px;
    z-index: 250;
    flex-wrap: wrap;
    gap: 6px 14px;
    align-items: center;
}
.tab-panel.is-open { display: flex; }

.panel-sect { display: flex; flex-direction: column; gap: 4px; }
.label {
    font-size: var(--text-3xs); color: var(--muted);
    letter-spacing: .5px; text-transform: uppercase;
    margin-bottom: 2px;
}
.row { display: flex; gap: 4px; align-items: center; }
.panel-vsep {
    width: 1px; background: var(--border2);
    align-self: stretch; margin: 0 4px;
}

/* ────────────────────────────────────────────
   CANVAS AREA
─────────────────────────────────────────────── */
.canvas-area { flex: 1; position: relative; overflow: hidden; }

.canvas-wrap {
    width: 100%; height: 100%;
    position: relative; overflow: hidden;
    background: var(--bg); cursor: default;
    touch-action: none;
    background-image: radial-gradient(circle at 1px 1px, #1c1540 1px, transparent 0);
    background-size: 20px 20px;
}
.grid-active .canvas-wrap {
    background-image:
        linear-gradient(to right, #1a1438 1px, transparent 1px),
        linear-gradient(to bottom, #1a1438 1px, transparent 1px);
    background-size: 20px 20px;
}

#canvas-bg {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%; pointer-events: none;
}
#canvas-bg img { position: absolute; opacity: 0.9; }
#canvas-buttons { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

/* ────────────────────────────────────────────
   BOTTOM BAR = props row + status bar
─────────────────────────────────────────────── */
.bottom-bar {
    flex-shrink: 0;
    background: var(--surface);
    border-top: 2px solid var(--accent);
    display: none;
}
.bottom-bar.is-visible { display: block; }

/* PROPS ROW */
.bbar-top {
    height: 54px;
    display: flex;
    align-items: center;
    overflow: hidden;
}
@media (max-width: 900px) {
    .bbar-top {
        height: auto;
        overflow: visible;
    }
}

/* Hint shown when nothing is selected */
.bbar-hint {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%;
    color: var(--muted); font-size: var(--text-2xs);
    letter-spacing: 2px; text-transform: uppercase;
}

/* PROPS POPOVER → repurposed as the bottom props bar.
   All JS class-toggling (is-visible) drives what's shown. */
#props-popover {
    position: static !important;
    display: none !important;
    background: none !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    min-width: 0 !important;
    z-index: auto !important;
}
#props-popover.is-visible {
    display: flex !important;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    width: 100%;
    height: 100%;
}
@media (max-width: 900px) {
    #props-popover.is-visible {
        flex-wrap: wrap;
    }
}
#props-popover.is-visible ~ .bbar-hint { display: none !important; }

.props-popover__title { display: none !important; }

/* Prop sections inside bottom bar */
.prop-sect {
    height: 100%;
    display: flex; flex-direction: column;
    justify-content: center; gap: 4px;
    padding: 0 13px;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
}
.prop-sect:last-child { border-right: none; }
.prop-sect.spacer { flex: 1; border-right: none; }

.prop-unit { font-size: var(--text-3xs); color: var(--muted); }

/* ── Bottom bar : contrôles unifiés ── */
.bbar-top input[type="text"] {
    width: 40px;
    text-align: center;
    font-family: var(--font-ui);
    font-size: var(--text-2xs);
}
.bbar-top #prop-name { width: 72px; }
.bbar-top #prop-x,
.bbar-top #prop-y   { width: 44px; }
.bbar-top #prop-size-label { width: 30px; }
.bbar-top #prop-outer-label { width: 44px; }
.bbar-top #prop-outer-width { width: 44px; }
.bbar-top #prop-outer-size { width: 44px; }
.bbar-top .btn--sm {
    padding: 0 6px;
    height: 24px;
    min-width: 26px;
}
.bbar-top .dot--24 { width: 7px; height: 7px; }
.bbar-top .dot--30 { width: 9px; height: 9px; }

/* ── Groupes visuels (bouton / cercle / actions) ── */
.prop-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 100%;
    flex-shrink: 0;
}
.prop-group__label {
    writing-mode: sideways-lr;
    text-orientation: mixed;
    font-size: var(--text-3xs);
    color: var(--accent2);
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 600;
    width: 18px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--accent2) 6%, transparent);
    border-right: 1px solid var(--border);
    user-select: none;
    flex-shrink: 0;
    opacity: 0.85;
}
.prop-group--cercle .prop-group__label {
    background: color-mix(in srgb, var(--accent) 6%, transparent);
    color: var(--accent);
}

.prop-group--actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    height: 100%;
    flex-shrink: 0;
}

/* STATUS BAR (overlay en bas du canvas) */
.statusbar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    display: flex; align-items: center;
    gap: 14px;
    height: 26px; padding: 0 12px;
    background: color-mix(in srgb, var(--surface) 30%, transparent);
    border-top: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: var(--text-sm); color: var(--muted);
    z-index: 10;
}
.statusbar span { color: var(--accent2); }
.statusbar__spacer { flex: 1; }

/* ────────────────────────────────────────────
   CANVAS BUTTONS
─────────────────────────────────────────────── */
.cbutton {
    position: absolute; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: grab; font-family: var(--font-ui); font-weight: 700;
    font-size: var(--text-2xs); color: #fff;
    border: 2px solid rgba(255,255,255,.25);
    user-select: none;
    transition: box-shadow .12s, border-color .12s;
    text-align: center; line-height: 1.1;
}
.cbutton.is-selected {
    border-color: var(--text);
    /*box-shadow: 0 0 0 2px var(--accent2), 0 0 18px var(--accent);*/
    z-index: 100; cursor: grabbing;
}
.cbutton:hover { border-color: rgba(255,255,255,.6); z-index: 50; }
.cbutton.is-dragging { cursor: grabbing; z-index: 200; transition: none; }
.cbutton__label { pointer-events: none; }

.cbutton__delete {
    position: absolute; top: -6px; left: -6px;
    width: 16px; height: 16px; border-radius: 50%;
    background: var(--danger); border: 1.5px solid #ff9090;
    color: #fff; font-size: 8px; font-weight: 700; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; opacity: 0; transform: scale(.6);
    transition: opacity .15s, transform .15s;
    z-index: 300; padding: 0; font-family: sans-serif;
    box-shadow: 0 1px 4px rgba(0,0,0,.5); pointer-events: none;
}
.cbutton.is-selected .cbutton__delete { opacity: 1; transform: scale(1); pointer-events: auto; }
.cbutton.is-selected .cbutton__delete:hover { background: #ff2020; border-color: #fff; transform: scale(1.15); }

.cbutton__outer {
    position: absolute; border-radius: 50%;
    border: 1.5px solid rgba(180,160,255,.45);
    pointer-events: none; z-index: 3; box-sizing: border-box;
    transition: border-color .12s;
}
.cbutton__outer.is-selected { border-color: rgba(163,104,255,.9); }

/* ────────────────────────────────────────────
   FORM ELEMENTS
─────────────────────────────────────────────── */
select, input[type="text"] {
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); font-family: var(--font-ui);
    font-size: var(--text-xs); padding: 4px 7px; border-radius: var(--input-radius); outline: none;
}
select:focus, input[type="text"]:focus { border-color: var(--accent); }
select { cursor: pointer; }

input[type="color"] {
    width: 28px; height: 28px;
    border: 1px solid var(--border); border-radius: var(--input-radius);
    cursor: pointer; padding: 2px; background: var(--surface2);
}

/* ── PICKR COLOR PICKER ── */
.pickr-container {
    width: 28px; height: 28px;
    flex-shrink: 0;
}

.pickr-container .pcr-button {
    width: 28px !important; height: 28px !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--input-radius) !important;
}

/* ── BUTTONS ── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    height: var(--btn-height); padding: 0 9px;
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); font-family: var(--font-ui);
    font-size: var(--text-xs); font-weight: 600; letter-spacing: .5px;
    cursor: pointer; transition: border-color .12s, color .12s, background .12s;
    border-radius: var(--radius); white-space: nowrap;
}
.btn:hover { border-color: var(--accent2); color: var(--accent2); }
.btn.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.is-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.is-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn.is-danger { color: var(--danger); }
.btn.is-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.is-disabled { opacity: .3; pointer-events: none; }
.btn--sm { height: var(--btn-sm-height); padding: 0 7px; font-size: var(--text-2xs); }

/* SIZE BUTTONS (extends btn--sm) */
.size-selector { display: flex; gap: 3px; }
.size-btn .dot { border-radius: 50%; background: currentColor; flex-shrink: 0; }

/* ────────────────────────────────────────────
   RESPONSIVE COMPACT
─────────────────────────────────────────────── */
@media (max-width: 900px) {
    .tab { padding: 0 12px; font-size: var(--text-sm); letter-spacing: 1px; }
    .toolbar .btn { font-size: 10px; padding: 0 6px; }
}
@media (max-width: 650px) {
    .tab { padding: 0 9px; font-size: var(--text-xs); }
    .tab-dot { display: none; }
}

/* ── Bottom bar responsive : empile les groupes ── */
@media (max-width: 900px) {
    .prop-group { width: 100%; height: auto; }
    .prop-group .prop-sect { height: auto; padding: 6px 10px; }
    .prop-group__label {
        writing-mode: horizontal-tb;
        width: auto; height: 26px;
        padding: 0 10px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .prop-group--actions {
        width: 100%; height: auto;
        justify-content: center;
        padding: 6px 10px;
    }
    .prop-sect.spacer { display: none; }
}

/* ════════════════════════════════════════════════════════
   MOBILE APP MODE — Concept A : nav basse + bottom sheets
   app.js et les IDs restent inchangés : on ne fait que
   repositionner/redimensionner les mêmes éléments.
═════════════════════════════════════════════════════════ */
.mobile-backdrop { display: none; }

@media (max-width: 700px) {

    :root { --mobile-navh: 60px; }

    /* Le backdrop assombrit le canvas derrière un sheet ouvert */
    .mobile-backdrop {
        display: block;
        position: fixed; inset: 0;
        background: rgba(4, 6, 14, .6);
        opacity: 0; pointer-events: none;
        transition: opacity .18s ease;
        z-index: 350;
    }
    body:has(.tab-panel.is-open) .mobile-backdrop {
        opacity: 1; pointer-events: auto;
    }
    /* Quand un onglet est ouvert, on masque la bottom-bar (props sheet)
       pour libérer la zone : elle recouvrirait le tab-panel (z-index 390 > 380). */
    body:has(.tab-panel.is-open) .bottom-bar {
        display: none !important;
    }

    /* ── NAV BASSE (ex-topnav) ── */
    .topnav {
        position: fixed; left: 0; right: 0; top: auto; bottom: 0;
        height: var(--mobile-navh);
        border-bottom: none;
        border-top: 2px solid var(--accent);
        z-index: 400;
        box-shadow: 0 -4px 16px rgba(0,0,0,.35);
    }
    .tabs { width: 100%; }
    .tab {
        flex: 1 1 0;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        padding: 6px 2px 8px;
        border-right: none;
        font-size: 9px;
        letter-spacing: .4px;
    }
    /* Le <span> vide devant chaque tab devient un point indicateur */
    .tab > span {
        display: block; width: 5px; height: 5px;
        border-radius: 50%;
        background: currentColor; opacity: .4;
        transition: opacity .12s;
    }
    .tab.is-active > span { opacity: 1; background: #fff; }

    /* ── PANELS = bottom sheets, ancrés au-dessus de la nav ── */
    .panels-host { position: static; z-index: auto; }
    .tab-panel {
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
        position: fixed; left: 0; right: 0; top: auto;
        bottom: var(--mobile-navh);
        max-height: 62vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
        padding: 18px 18px 22px;
        gap: 16px;
        background: var(--surface);
        box-shadow: 0 -10px 28px rgba(0,0,0,.45);
        z-index: 380;
        transform: translateY(12px);
        opacity: 0; visibility: hidden; pointer-events: none;
        transition: transform .2s ease, opacity .2s ease, visibility .2s;
    }
    .tab-panel.is-open {
        transform: translateY(0);
        opacity: 1; visibility: visible; pointer-events: auto;
    }
    .tab-panel::before {
        content: ""; display: block;
        width: 36px; height: 4px; border-radius: 2px;
        background: var(--border2);
        margin: -6px auto 4px;
    }
    .panel-sect { width: 100%; gap: 6px; }
    .panel-vsep { display: none; }
    .tab-panel .row { flex-wrap: wrap; }
    .tab-panel select { width: 100%; min-width: 0; }
    #panel-add .row .btn { flex: 1; }

    /* ── PROPS SHEET (bottom-bar) ── */
    .bottom-bar {
        position: fixed; left: 0; right: 0;
        bottom: var(--mobile-navh);
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
        box-shadow: 0 -10px 28px rgba(0,0,0,.45);
        z-index: 390;
    }
    .bbar-top { padding-top: 4px; }
    .bbar-top::before {
        content: ""; display: block;
        width: 36px; height: 4px; border-radius: 2px;
        background: var(--border2);
        margin: 6px auto 2px;
    }
    .prop-group--actions .btn { flex: 1; height: 40px; font-size: var(--text-sm); }

    /* ── CANVAS : statusbar en haut, toolbar flottante en dessous ── */
    .statusbar { top: 0; bottom: auto; }
    .toolbar {
        top: 30px;
        bottom: auto;
        right: 8px;
        flex-wrap: wrap;
        justify-content: flex-end;
        max-width: calc(100vw - 16px);
    }

    /* ── CIBLES TACTILES AGRANDIES + fix zoom iOS ── */
    select, input[type="text"] { font-size: 16px; }
    .bbar-top input[type="text"] { font-size: 16px; height: 38px; }
    .bbar-top #prop-name { width: 96px; }
    .bbar-top #prop-x, .bbar-top #prop-y { width: 58px; }
    .bbar-top #prop-size-label { width: 42px; }
    .bbar-top #prop-outer-label,
    .bbar-top #prop-outer-width,
    .bbar-top #prop-outer-size { width: 58px; }
    .btn { height: 38px; font-size: var(--text-sm); }
    .btn--sm { height: 34px; font-size: var(--text-xs); }
    .pickr-container, .pickr-container .pcr-button { width: 34px !important; height: 34px !important; }
    input[type="color"] { width: 34px; height: 34px; }
    .cbutton__delete {
        width: 22px; height: 22px; top: -8px; left: -8px; font-size: 11px;
    }
}

/* Très petits écrans : compresse encore un peu la nav */
@media (max-width: 380px) {
    .tab { font-size: 8px; padding: 5px 1px 7px; }
}
