/* RESET & BASICS */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body {
    height: 100dvh;
    width: 100vw;
    background-color: white;
    overflow: hidden;
    font-family: 'Segoe UI', sans-serif;
    position: relative;
    touch-action: none;
    overscroll-behavior: none;
}

/* VIEW SYSTEM */
.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    background-color: white;
    z-index: 10;
}

.view.active {
    display: flex;
}

/* HOME VIEW */
#view-home {
    align-items: center;
    justify-content: flex-end;
    /* Push to bottom */
    padding-bottom: 60px;
    gap: 20px;
}

.logo-visual {
    position: absolute;
    /* Absolute to stay top */
    top: 100px;
    left: 50%;
    transform: translateX(-50%) scale(1.5);
    width: 300px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.logo-visual .glyph {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
}

.logo-visual .q {
    transform: translate(calc(-50% - 45px), -50%);
}

.logo-visual .o {
    transform: translate(-50%, -50%);
}

.logo-visual .p {
    transform: translate(calc(-50% + 45px), -50%);
}

/* EDITOR NAV STYLES */
#step-nav {
    position: absolute;
    top: 60px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 95;
    pointer-events: none;
}

.nav-btn {
    background: white;
    border: 2px solid black;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    pointer-events: auto;
    font-weight: bold;
    font-size: 30px;
    box-shadow: 2px 2px 0px black;
    position: fixed;
    bottom: 170px;
    /* Above ribbon */
    z-index: 1000;
}

.nav-btn.nav-left {
    left: 15px;
}

.nav-btn.nav-right {
    right: 15px;
}

.nav-btn:active {
    transform: translate(1px, 1px);
    box-shadow: none;
}

.nav-label {
    font-size: 60px;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.8);
    background: transparent;
    border: none;
    padding: 0;
}

/* MINI LOGO */
.logo-mini {
    position: absolute;
    top: 10px;
    right: 20px;
    width: 100px;
    height: 30px;
    scale: 0.4;
    transform-origin: top right;
    z-index: 200;
    pointer-events: none;
}

.logo-mini .glyph {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    display: flex !important;
    transform: translate(-50%, -50%) !important;
    width: 30px !important;
    /* LARGEUR CRITIQUE POUR LES TIGES */
}

.logo-mini .q {
    transform: translate(calc(-50% - 38px), -50%) !important;
}

.logo-mini .q .stem {
    right: 0 !important;
    left: auto !important;
}

.logo-mini .o {
    transform: translate(-50%, -50%) !important;
}

.logo-mini .p {
    transform: translate(calc(-50% + 38px), -50%) !important;
}

.logo-mini .p .stem {
    left: 0 !important;
    right: auto !important;
}

.logo-mini .bowl {
    width: 30px !important;
    height: 30px !important;
    border-width: 6px !important;
    position: relative !important;
    z-index: 2 !important;
    border-radius: 50%;
    border: 6px solid black;
}

.logo-mini .stem {
    height: 60px !important;
    top: 15px !important;
    width: 6px !important;
    display: block !important;
    position: absolute !important;
    z-index: 1 !important;
    visibility: visible !important;
    background: black;
}

.logo-mini .mark {
    display: none !important;
}

.version-tag {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: #999;
}

/* LIBRARY DELETE BTN (Polished B&W) */
.lib-delete-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: white;
    border: 2px solid black;
    border-radius: 10px;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 2px 2px 0px black;
    cursor: pointer;
    z-index: 10;
    font-size: 20px;
    filter: grayscale(1);
    /* Ensure B&W */
}

.lib-delete-btn:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0px black;
}

.app-btn {
    pointer-events: auto;
    background: white;
    border: 2px solid black;
    border-radius: 12px;
    padding: 8px 12px;
    /* Smaller for mobile */
    font-size: 16px;
    font-weight: bold;
    color: black;
    text-align: center;
    cursor: pointer;
    box-shadow: 2px 2px 0px black;
    transition: transform 0.1s, box-shadow 0.1s;
}

.app-btn:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

.home-btn {
    width: 220px;
    padding: 15px;
}

/* COMMON HEADER */
.app-header {
    padding: 15px 20px;
    border-bottom: 1px solid #ccc;
    display: flex;
    align-items: center;
    background: white;
    flex-shrink: 0;
}

.header-title {
    font-size: 20px;
    font-weight: bold;
    flex-grow: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 10px;
}

.icon-btn {
    font-size: 24px;
    cursor: pointer;
    padding: 5px 10px;
    background: none;
    border: none;
}

/* LIBRARY VIEW */
#view-library {
    background-color: #f9f9f9;
}

.lib-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 100px;
    /* Space for footer */
    display: flex;
    flex-direction: column;
    gap: 20px;
    touch-action: pan-y;
}

.lib-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #ccc;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.lib-item {
    background: white;
    padding: 15px;
    border-radius: 15px;
    border: 2px solid black;
    box-shadow: 2px 2px 0px black;
    display: flex;
    flex-direction: column;
    gap: 10px;
    cursor: pointer;
    position: relative;
    /* For delete button */
}

.lib-item:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0px black;
}

.lib-info {
    font-size: 18px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}

.lib-meta {
    font-size: 14px;
    color: #666;
}

.lib-preview {
    display: flex;
    gap: 5px;
    overflow-x: auto;
    padding-bottom: 5px;
    height: 60px;
    align-items: center;
    scrollbar-width: none;
    touch-action: pan-x;
    pointer-events: none;
    /* Scroll fix: let touch through to parent */
}

.lib-thumb-small {
    width: 40px;
    height: 50px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}

.thumb-scaler {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    transform: scale(0.12);
}


/* EDITOR VIEW */
.editor-area {
    flex: 1;
    position: relative;
    background-color: white;
    overflow: hidden;
    border-bottom: 1px solid #ccc;
}

.menu-btn {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 24px;
    cursor: pointer;
    z-index: 100;
    padding: 5px;
}

.choreo-name-container {
    position: absolute;
    top: 15px;
    left: 60px;
    right: 60px;
    z-index: 90;
    text-align: center;
}

.back-btn {
    position: absolute;
    top: 15px;
    left: 15px;
    font-size: 24px;
    cursor: pointer;
    z-index: 100;
    padding: 5px;
    background: none;
    border: none;
    font-weight: bold;
}

#choreo-name {
    width: 100%;
    max-width: 200px;
    padding: 5px;
    font-size: 18px;
    text-align: center;
    border: none;
    border-bottom: 1px solid #ccc;
    outline: none;
    font-family: inherit;
}

.controls-layer {
    position: absolute;
    bottom: 90px;
    /* RAISED to avoid nav arrows at 170px */
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 10px;
    pointer-events: none;
    padding: 0 5px;
    z-index: 50;
    flex-wrap: wrap;
}

.ribbon {
    height: 150px;
    /* Fixed height for V3.8 */
    flex-shrink: 0;
    background: #f8f8f8;
    border-top: 1px solid #ddd;
    display: flex;
    align-items: center;
    overflow-x: auto;
    padding: 0 10px;
    gap: 10px;
    z-index: 60;
    cursor: grab;
}

.ribbon.active {
    cursor: grabbing;
}

.step-thumb {
    min-width: 95px;
    height: 120px;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
}

.step-thumb.active {
    border-color: black;
    box-shadow: 0 0 0 2px black;
}

.step-number-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.1);
    padding: 1px 4px;
    border-radius: 4px;
    color: #333;
    z-index: 5;
}

.step-thumb .thumb-scaler {
    transform: scale(0.25);
}

/* GLOBAL GLYPH STYLES (Restored Stability) */
:root {
    --stroke-width: 8px;
    --bowl-size: 40px;
    --stem-long-height: 120px;
    --mark-width: 72px;
    --mark-height: 8px;
}

/* The Critical Global Rule */
.glyph {
    display: flex;
    position: absolute;
    width: 40px;
    justify-content: center;
    top: calc(50% - 50px);
    /* LOWERED by 150px from -200px */
    left: 50%;
    transform: translate(-50%, -50%);
    touch-action: none;
    z-index: 10;
}

.editor-area .glyph::before {
    content: '';
    position: absolute;
    background-color: transparent;
    z-index: -1;
    pointer-events: auto;
}

.editor-area .glyph.q::before,
.editor-area .glyph.p::before {
    width: 120px;
    height: 300px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -33%);
}

/* Aligner le 'o' avec q/p (au niveau des trucks) */
.editor-area .glyph.o {
    top: calc(50% - 50px);
}

.editor-area .glyph.o::before {
    width: 100px;
    height: 100px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.bowl {
    width: var(--bowl-size);
    height: var(--bowl-size);
    border: var(--stroke-width) solid black;
    border-radius: 50%;
    z-index: 2;
    position: relative;
    background-color: transparent;
}

.stem {
    width: var(--stroke-width);
    height: var(--stem-long-height);
    background-color: black;
    position: absolute;
    top: 20px;
    z-index: 1;
}

/* Orientation Fixes */
.glyph.q .stem {
    right: 0;
    left: auto;
}

.glyph.p .stem {
    left: 0;
    right: auto;
}

.mark {
    position: absolute;
    width: var(--mark-width);
    height: var(--mark-height);
    background-color: black;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 999px;
    pointer-events: auto;
}

.mark.upper {
    top: 50px;
}

.mark.lower {
    bottom: 0;
}

.mark.is-cross {
    background-color: transparent;
}

.mark.is-cross::before,
.mark.is-cross::after {
    content: '';
    position: absolute;
    width: 40px;
    height: var(--mark-height);
    background-color: black;
    border-radius: 999px;
    left: 50%;
    top: 50%;
}

.mark.is-cross::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.mark.is-cross::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

/* Arrow styles */
.arrow-container {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 1;
    pointer-events: none;
    display: none;
}

.arrow-line {
    position: absolute;
    left: 20px;
    top: -1px;
    height: 2px;
    background-color: black;
    transform-origin: 0% 50%;
    width: 40px;
}

.arrow-line::after {
    content: '';
    position: absolute;
    right: -10px;
    top: -5px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid black;
}

.editor-area .glyph.q,
.editor-area .glyph.p {
    z-index: 10;
    cursor: move;
}

/* Menu */
#menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.98);
    z-index: 200;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
}

.menu-link {
    font-size: 28px;
    font-weight: bold;
    text-decoration: none;
    color: black;
    padding: 10px 20px;
    border-bottom: 3px solid transparent;
    cursor: pointer;
}

.menu-link:hover {
    border-bottom-color: black;
}


.menu-close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 40px;
    cursor: pointer;
    padding: 10px;
}

/* AUTH & ACCESS */
body.not-logged .view:not(#view-auth) {
    display: none !important;
}

body.not-logged .back-btn,
body.not-logged .menu-btn {
    display: none !important;
}