/* ============================================================
   nsi42.nsi.xyz — terminal responsive
   Layout et composants. Les palettes/effets sont dans themes.css.
   ============================================================ */

* { box-sizing: border-box; }

html {
    height: 100%;
    background: var(--bg);
    color-scheme: dark;
}

body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--ui-font);
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

/* ---------- application plein écran ---------- */
.app {
    height: var(--app-height, 100dvh);
    min-height: 0;
    max-width: 1500px;
    margin: 0 auto;
    padding: clamp(8px, 1.6vw, 20px);
    padding-top: max(clamp(8px, 1.6vw, 20px), env(safe-area-inset-top));
    padding-bottom: max(clamp(8px, 1.6vw, 20px), env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1.2vh, 14px);
    color: var(--fg);
}

/* ---------- barre supérieure ---------- */
.barre {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
    color: var(--ui-fg);
    font-family: var(--ui-font);
    font-size: clamp(.78rem, 1.5vw, .95rem);
}

.marque {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.marque-42 {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.05em;
    height: 2.05em;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-fg);
    font-family: var(--ui-font);
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 0 12px var(--accent-glow);
}

.marque-txt {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-family: var(--font);
    font-weight: 700;
    letter-spacing: .03em;
    color: var(--ui-fg);
}

.actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.lien-plan {
    color: var(--ui-muted);
    text-decoration: none;
    white-space: nowrap;
    font-size: .9em;
}
.lien-plan:hover { color: var(--ui-fg); text-decoration: underline; }

/* ---------- sélecteur de style ---------- */
.palette { position: relative; }

.btn-palette {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.35em;
    height: 2.35em;
    padding: 0;
    border: 1px solid var(--btn-border);
    border-radius: 10px;
    background: var(--btn-bg);
    color: var(--btn-fg);
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .15s;
}
.btn-palette:hover { background: var(--btn-hover); border-color: var(--accent); }
.btn-palette:active { transform: scale(.96); }
.btn-palette svg { width: 1.2em; height: 1.2em; }

.menu-themes {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 50;
    display: none;
    min-width: 230px;
    padding: 6px;
    border: 1px solid var(--menu-border);
    border-radius: 14px;
    background: var(--menu-bg);
    box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.menu-themes.ouvert { display: block; }

.menu-themes button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--btn-fg);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.menu-themes button:hover { background: var(--btn-hover); }
.menu-themes button[aria-checked="true"] {
    background: var(--btn-hover);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}
.menu-themes .ere {
    color: var(--ui-muted);
    font-family: var(--font);
    font-size: .8em;
}

/* ---------- terminal ---------- */
.terminal {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
}

.cadre {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    padding: var(--cadre-pad);
    border: var(--cadre-border);
    border-radius: var(--cadre-radius);
    background: var(--cadre-bg);
    box-shadow: var(--cadre-shadow);
}

.ecran {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: var(--screen-pad);
    border-radius: var(--screen-radius);
    background: var(--screen-bg);
    box-shadow: inset 0 0 30px var(--screen-inset);
}

.ecran-scroll {
    position: relative;
    z-index: 1;
    min-width: 0;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    scrollbar-width: thin;
    scrollbar-color: var(--fg-dim) transparent;
}
.ecran-scroll::-webkit-scrollbar { width: 8px; }
.ecran-scroll::-webkit-scrollbar-track { background: transparent; }
.ecran-scroll::-webkit-scrollbar-thumb {
    background: var(--fg-dim);
    border-radius: 4px;
}

#computer {
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
    white-space: pre;
    overflow: visible;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.15;
    letter-spacing: var(--letter-spacing, 0);
    font-variant-ligatures: none;
    color: inherit;
    text-shadow: var(--glow);
    tab-size: 4;
}

.scanlines {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    border-radius: var(--screen-radius);
    background: var(--scanlines);
    opacity: var(--scan-opacity);
    mix-blend-mode: var(--scan-blend);
}

.led {
    position: absolute;
    right: calc(var(--cadre-pad) + 8px);
    bottom: calc(var(--cadre-pad) + 6px);
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--led);
    box-shadow: 0 0 8px var(--led);
    display: var(--led-display, block);
}

/* ---------- pied ---------- */
.pied {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
    color: var(--ui-muted);
    font-family: var(--ui-font);
    font-size: clamp(.68rem, 1.35vw, .8rem);
}
.pied p { margin: 0; min-width: 0; }
#hint { display: none; color: var(--ui-fg); white-space: nowrap; }
.cmd { color: var(--accent); font-family: var(--font); }
.credits {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: right;
}

@media (pointer: coarse) {
    #hint { display: block; }
}
body.clavier-ouvert #hint { display: none; }

/* ---------- accessibilité ---------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- champ clavier tactile ---------- */
#kbd {
    position: fixed;
    left: 50%;
    top: 0;
    width: 2px;
    height: 2px;
    margin-left: -1px;
    padding: 0;
    border: 0;
    outline: none;
    opacity: 0;
    pointer-events: none;
    font-size: 16px; /* évite le zoom automatique sur iOS */
}

/* ---------- sans JavaScript ---------- */
.plan-noscript {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    color: var(--ui-fg);
    font-family: var(--ui-font);
}
.plan-noscript h2 { font-size: 1.1rem; }
.plan-noscript ul {
    columns: 2;
    column-gap: 28px;
    padding-left: 18px;
    line-height: 1.6;
}
.plan-noscript a { color: var(--accent); }

/* ---------- petits écrans ---------- */
@media (max-width: 560px) {
    .app { gap: 6px; }
    .barre { font-size: .78rem; }
    .marque-42 { width: 1.9em; height: 1.9em; border-radius: 7px; }
    .credits { text-align: left; white-space: normal; }
    .pied { flex-wrap: wrap; }
}

@media (max-width: 420px) {
    .marque-txt { display: none; }
    .lien-plan { font-size: .8rem; }
}

@media (max-width: 700px) {
    .plan-noscript ul { columns: 1; }
}

/* En paysage très bas (téléphone + clavier), on compresse les barres. */
@media (max-height: 520px) {
    .app { gap: 4px; padding-top: 6px; padding-bottom: 6px; }
    .barre, .pied { font-size: .7rem; }
    .marque-42 { width: 1.8em; height: 1.8em; }
}
