:root {
    --primary-color: #6c63ff;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-color: #2c3e50;
    --success: #2ecc71;
    --danger: #e74c3c;
    --warning: #f39c12;
    --circle-color: #6c63ff;
    
    /* Variables LCD */
    --lcd-bg: #74877a;
    --lcd-text-on: #1c2420;
    --lcd-text-off: rgba(28, 36, 32, 0.05);
    --bezel-color: #f4f4f4;
}

html {
    background: transparent;
    color-scheme: normal;
}

/* --- MODE SOMBRE ET RETROÉCLAIRAGE --- */
body.backlight-mode {
    --card-bg: transparent;
    --lcd-bg: #1e3a31;
    --lcd-text-on: #5bf5bd;
    --lcd-text-off: rgba(91, 245, 189, 0.04);
    background-color: #111;
}

body {
    margin: 0; padding: 0;
    font-family: 'Segoe UI', sans-serif;
    background-image: url('https://mathsmorant.fr/wp-content/uploads/2021/04/d.jpg');
    background-size: cover; background-position: center; background-attachment: fixed;
    display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch;
    min-height: 100vh; transition: background 0.3s ease;
    overflow-x: hidden;
    padding: 0;
    position: relative;
    box-sizing: border-box;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0);
    pointer-events: none;
    transition: background 0.3s ease;
    z-index: -1;
}
body.backlight-mode::before {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: contrast(110%);
}

@keyframes flashEnd {
    0% { background-color: var(--danger); }
    50% { background-color: white; }
    100% { background-color: var(--danger); }
}
.timer-expired { animation: flashEnd 0.8s infinite !important; background-image: none !important; }

.main-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 20px 40px;
    box-sizing: border-box;
}

.layout-container {
    display: grid;
    grid-template-columns: 1fr auto 1fr; 
    align-items: start;
    gap: 40px;
    width: 100%;
    max-width: 1400px;
    box-sizing: border-box;
}

#bubbles-left, #bubbles-right {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-top: 50px;
    z-index: 1;
}

#bubbles-left { align-items: flex-end; }
#bubbles-right { align-items: flex-start; }

.bubble-wrapper { position: relative; animation: popIn 0.3s ease-out; }

.bubble {
    background: white;
    border-radius: 18px;
    padding: 15px 20px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    font-weight: 700;
    color: var(--text-color);
    border: 2px solid var(--primary-color);
    width: fit-content;
    max-width: 250px;
    text-align: center;
    outline: none;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 1rem;
    position: relative;
}

.left-b .bubble::after { content: ''; position: absolute; right: -12px; top: 20px; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-left: 12px solid var(--primary-color); }
.right-b .bubble::after { content: ''; position: absolute; left: -12px; top: 20px; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-right: 12px solid var(--primary-color); }

.bubble-close { position: absolute; top: -10px; background: var(--danger); color: white; border-radius: 50%; width: 22px; height: 22px; display: flex; justify-content: center; align-items: center; font-size: 12px; cursor: pointer; border: 2px solid white; z-index: 5; }
.left-b .bubble-close { left: -10px; }
.right-b .bubble-close { right: -10px; }

@keyframes popIn { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.timer-card {
    background: var(--card-bg); 
    padding: 30px; 
    border-radius: 25px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.15);
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 30px;
    position: relative; 
    width: 850px;
    max-width: 100%; 
    backdrop-filter: blur(8px);
    margin-top: 50px; 
    z-index: 10;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

/* --- BARRE DE NAVIGATION SUPÉRIEURE --- */
.top-controls { 
    position: absolute; 
    top: -50px; 
    left: 0; 
    display: flex; 
    gap: 15px; 
    width: 100%; 
    justify-content: space-between; 
    align-items: center;
    flex-wrap: nowrap;
}

.mode-toggle, .util-toggle {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.mode-btn, .util-btn { padding: 8px 15px; border-radius: 12px; border: none; cursor: pointer; font-weight: bold; background: rgba(255,255,255,0.8); color: #666; white-space: nowrap; }
.mode-btn.active { background: var(--primary-color); color: white; }

.circle-container { position: relative; width: 150px; height: 150px; flex-shrink: 0; }
.is-clock-mode .circle-container, .is-dnb-mode .circle-container { display: none; }
svg { transform: rotate(-90deg); }
.circle-bg { fill: none; stroke: #eee; stroke-width: 10; }
.circle-progress { fill: none; stroke: var(--circle-color); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 439.8; stroke-dashoffset: 439.8; transition: stroke-dashoffset 0.3s linear, stroke 0.3s; }

.timer-display { display: flex; align-items: center; font-size: 100px; font-weight: 800; color: var(--text-color); font-variant-numeric: tabular-nums; }
.digit-group { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.nav-btn { background: none; border: none; font-size: 28px; cursor: pointer; color: #ddd; }
.nav-btn:hover { color: var(--primary-color); }
.separator { margin: 0 5px; padding-bottom: 25px; min-width: 20px; text-align: center; }

.actions { display: flex; flex-direction: column; gap: 12px; }
.action-btn { width: 45px; height: 45px; border-radius: 50%; border: 1px solid #eee; background: white; cursor: pointer; display: flex; justify-content: center; align-items: center; }
.btn-play { background: var(--primary-color); color: white; border: none; width: 55px; height: 55px; }

.rules-panel { display: flex; gap: 15px; justify-content: center; align-items: center; }
.rule-btn { padding: 15px 30px; border-radius: 18px; border: none; cursor: pointer; display: flex; align-items: center; gap: 15px; font-weight: 800; color: white; min-width: 300px; font-size: 1.3rem; }
.rule-btn.allowed { background-color: var(--success); }
.rule-btn.forbidden { background-color: var(--danger); }

.presets-panel { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 800px; }
.preset-btn { width: 45px; height: 45px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3); background: rgba(255,255,255,0.1); color: white; cursor: pointer; }

.bottom-tools-wrapper { display: flex; flex-direction: column; align-items: center; gap: 15px; }
.settings-bar { display: flex; gap: 20px; background: rgba(0,0,0,0.15); padding: 10px 25px; border-radius: 40px; align-items: center; }
.color-dot { width: 24px; height: 24px; border-radius: 50%; cursor: pointer; border: 2px solid white; }

.bubble-tools { display: flex; gap: 15px; }
.tool-btn { background: var(--primary-color); width: 50px; height: 50px; border-radius: 50%; border: none; color: white; font-size: 24px; cursor: pointer; display: flex; justify-content: center; align-items: center; box-shadow: 0 5px 10px rgba(0,0,0,0.2); }
.tool-btn.off { background: #cbd5e0; }

.footer { position: fixed; bottom: 10px; right: 20px; font-size: 0.8rem; color: white; font-style: italic; opacity: 0.7; }

.icon-play { width: 0; height: 0; border-top: 10px solid transparent; border-bottom: 10px solid transparent; border-left: 18px solid white; margin-left: 5px; }
.icon-pause { display: flex; gap: 4px; } .icon-pause div { width: 5px; height: 20px; background: white; }
.icon-stop { width: 16px; height: 16px; background: #2c3e50; border-radius: 2px; }

.is-clock-mode .nav-btn, .is-clock-mode .actions { display: none; }

/* --- COMPTEUR LCD DNB --- */
#dnb-container { display: none; width: 100%; flex-direction: column; align-items: center; }

#dnb-header-text {
    width: 100%;
    font-size: clamp(1.1rem, 2.5vw, 1.6rem); 
    font-weight: 700; 
    color: #333;
    text-align: center; 
    text-transform: uppercase; 
    letter-spacing: 0.5px;
    margin-bottom: 20px; 
    text-shadow: 0 2px 4px rgba(255, 255, 255, 0.8);
    transition: color 0.3s ease, text-shadow 0.3s ease;
}

body.backlight-mode #dnb-header-text {
    color: #ffffff;
    text-shadow: 0 0 10px rgba(91, 245, 189, 0.6), 0 2px 4px rgba(0, 0, 0, 0.8);
}

.is-dnb-mode #dnb-container { display: flex; }
.is-dnb-mode .timer-display { display: none; }
.is-dnb-mode .actions { display: none; }
.is-dnb-mode.timer-card { background: transparent; box-shadow: none; padding: 0; backdrop-filter: none; }

.lcd-screen {
    background-color: var(--lcd-bg); 
    border: 4px solid #55665c; 
    border-radius: 4px;
    padding: 20px 25px; 
    display: grid; 
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    box-shadow: inset 0 6px 20px rgba(0, 0, 0, 0.3); 
    position: relative; 
    width: 100%; 
    box-sizing: border-box;
    transition: background-color 0.3s ease;
}

.lcd-screen::after {
    content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(rgba(0,0,0,0.03) 50%, rgba(255,255,255,0.01) 50%);
    background-size: 100% 4px; pointer-events: none; z-index: 10;
}

.lcd-section { display: flex; flex-direction: column; justify-content: space-between; align-items: center; position: relative; padding: 0 15px; }
.lcd-section:not(:last-child)::after { content: ""; position: absolute; right: 0; top: 5%; height: 90%; width: 2px; background-color: rgba(28, 36, 32, 0.25); }
.day-section { align-items: flex-start; justify-content: flex-start; }
.day-top-row { display: flex; width: 100%; justify-content: space-between; align-items: flex-start; }
.day-labels-left, .label { font-weight: bold; color: var(--lcd-text-on); transition: color 0.3s; }
.day-labels-left { display: flex; flex-direction: column; font-size: 1.1rem; line-height: 1.1; margin-top: 5px; min-width: 45px; }
.digits-group { display: flex; gap: 6px; }
.day-section .digits-group { margin-left: 15px; }

.digit-container { position: relative; width: 38px; height: 70px; display: inline-block; transform: skewX(-7deg); }
.segment { position: absolute; background-color: var(--lcd-text-off); border-radius: 4px; transition: background-color 0.12s ease, box-shadow 0.12s ease; }
.seg-a { top: 0; left: 12%; width: 76%; height: 8%; }
.seg-b { top: 6%; right: 0; width: 14%; height: 40%; }
.seg-c { bottom: 6%; right: 0; width: 14%; height: 40%; }
.seg-d { bottom: 0; left: 12%; width: 76%; height: 8%; }
.seg-e { bottom: 6%; left: 0; width: 14%; height: 40%; }
.seg-f { top: 6%; left: 0; width: 14%; height: 40%; }
.seg-g { top: 46%; left: 12%; width: 76%; height: 8%; }

.segment.on { background-color: var(--lcd-text-on) !important; }
body.backlight-mode .segment.on { box-shadow: 0 0 6px rgba(91, 245, 189, 0.8); }

.label { font-size: 1.3rem; margin-top: 15px; letter-spacing: 1px; }
.current-time-subpanel { width: 100%; border-top: 2px solid rgba(28, 36, 32, 0.25); margin-top: 15px; padding-top: 8px; display: flex; align-items: center; font-size: 1rem; font-weight: bold; color: var(--lcd-text-on); transition: color 0.3s; }
.sub-clock-digits { font-size: 1.3rem; margin-left: 8px; letter-spacing: 1px; transform: skewX(-5deg); }

#end-message-panel {
    display: none; background-color: var(--lcd-bg); border: 4px solid #55665c; border-radius: 4px;
    padding: 40px 20px; text-align: center; color: var(--lcd-text-on); font-size: 2rem;
    font-weight: 800; text-transform: uppercase; box-shadow: inset 0 6px 20px rgba(0, 0, 0, 0.3); letter-spacing: 1px; width: 100%; box-sizing: border-box;
}

/* --- MODE IFRAME STRICT --- */
body.iframe-mode,
body.iframe-mode.backlight-mode {
    min-height: auto !important;
    height: auto !important;
    margin: 0 !important;
    padding: 6px 4px 12px !important;
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start !important;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: visible;
}
body.iframe-mode::before,
body.iframe-mode.backlight-mode::before { display: none !important; background: transparent !important; }
body.backlight-mode .lcd-screen { border-color: #2d5a4c; }
body.backlight-mode .lcd-section:not(:last-child)::after { background-color: rgba(91, 245, 189, 0.2); }
body.backlight-mode .current-time-subpanel { border-top-color: rgba(91, 245, 189, 0.2); }

body.iframe-mode .main-wrapper {
    min-width: 100%;
    width: 100%;
    max-width: 100%;
    gap: 0;
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box;
    background: transparent !important;
    background-color: transparent !important;
}
body.iframe-mode .layout-container {
    grid-template-columns: 1fr;
    width: 100%;
    gap: 0;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    background-color: transparent !important;
}
body.iframe-mode #bubbles-left,
body.iframe-mode #bubbles-right,
body.iframe-mode .top-controls,
body.iframe-mode .rules-panel,
body.iframe-mode .presets-panel,
body.iframe-mode .bottom-tools-wrapper,
body.iframe-mode .footer,
body.iframe-mode .modal-overlay {
    display: none !important;
}
body.iframe-mode .timer-card,
body.iframe-mode .timer-card.is-dnb-mode,
.is-dnb-mode.timer-card {
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    margin: 0 auto !important;
    width: 100% !important;
    max-width: 850px !important;
    padding: 0 !important;
}
body.iframe-mode #dnb-container {
    margin: 0 auto !important;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: transparent !important;
    background-color: transparent !important;
}
body.iframe-mode #dnb-header-text {
    width: 100%;
    font-size: clamp(0.95rem, 3.2vw, 1.45rem);
    font-weight: 800;
    color: #1e293b;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0 !important;
    margin-bottom: 14px !important;
    line-height: 1.3 !important;
    text-shadow: 0 1px 3px rgba(255, 255, 255, 0.9);
    transition: color 0.3s ease, text-shadow 0.3s ease;
    word-break: normal;
    overflow-wrap: break-word;
    box-sizing: border-box;
    padding: 2px 8px !important;
}
body.backlight-mode #dnb-header-text,
[data-morant-theme="dark"] #dnb-header-text {
    color: #ffffff !important;
    text-shadow: 0 0 12px rgba(91, 245, 189, 0.7), 0 2px 4px rgba(0, 0, 0, 0.9) !important;
}

/* --- MODALE CONFIGURATION --- */
.feedback-msg { padding: 10px; border-radius: 4px; font-size: 0.9rem; font-weight: 600; margin-bottom: 15px; text-align: center; }
.feedback-msg.error { background-color: #fde8e8; color: #e02424; }
.feedback-msg.success { background-color: #def7ec; color: #03543f; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 200; }
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-content { background: white; padding: 30px; border-radius: 8px; width: 90%; max-width: 420px; box-shadow: 0 10px 30px rgba(0,0,0,0.25); position: relative; }
.modal-content h3 { margin-top: 0; margin-bottom: 20px; color: #222; }
.form-group { margin-bottom: 15px; display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.9rem; font-weight: 600; color: #444; }
.form-group input { padding: 10px; border: 1px solid #bbb; border-radius: 4px; font-size: 1rem; }
.btn-panel { display: flex; gap: 10px; margin-top: 25px; }
.btn { flex: 1; padding: 12px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 0.95rem; }
.btn-primary { background: #222; color: white; }
.btn-primary:hover { background: #000; }
.btn-secondary { background: #e5e5e5; color: #333; }
.btn-secondary:hover { background: #d5d5d5; }
.close-modal { position: absolute; top: 15px; right: 15px; background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #aaa; }


/* ==========================================================================
   AMÉLIORATIONS RESPONSIVES (AJOUTS)
   ========================================================================== */

@media (max-width: 1300px) {
    .layout-container {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 20px;
    }
    #bubbles-left, #bubbles-right {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        padding-top: 0;
        width: 100%;
    }
    #bubbles-left { align-items: center; }
    #bubbles-right { align-items: center; }
    .left-b .bubble::after, .right-b .bubble::after {
        display: none; /* Masque les flèches des bulles quand la mise en page passe en verticale */
    }
}

@media (max-width: 900px) {
    body {
        padding: 20px 10px;
    }
    .timer-card {
        padding: 20px;
        gap: 20px;
        margin-top: 70px;
    }
    .footer {
        position: static;
        text-align: center;
        margin-top: 20px;
        width: 100%;
    }
}

@media (max-width: 768px) {
    .timer-card {
        flex-direction: column;
        align-items: center;
    }
    .top-controls {
        position: absolute;
        top: -65px;
        flex-direction: column;
        gap: 8px;
        align-items: center;
    }
    .mode-toggle, .util-toggle {
        justify-content: center;
        flex-wrap: wrap;
    }
    .mode-btn, .util-btn {
        font-size: 0.85rem;
        padding: 6px 12px;
    }
    .circle-container {
        width: 120px;
        height: 120px;
    }
    .circle-container svg {
        width: 120px;
        height: 120px;
    }
    .circle-bg, .circle-progress {
        cx: 60;
        cy: 60;
        r: 50;
        stroke-width: 8;
    }
    /* Mettre à jour l'animation SVG du cercle */
    .circle-progress {
        stroke-dasharray: 314.16;
        stroke-dashoffset: 314.16;
    }
    
    .timer-display {
        font-size: clamp(3rem, 15vw, 90px);
    }
    .digit-group {
        min-width: 60px;
    }
    .rules-panel {
        flex-direction: column;
        width: 100%;
        max-width: 400px;
    }
    .rule-btn {
        min-width: 100%;
        justify-content: center;
        font-size: 1.1rem;
        padding: 12px 20px;
    }
}

@media (max-width: 768px) {
    .lcd-screen {
        padding: 12px 14px;
        grid-template-columns: 1.35fr 1fr 1fr 1fr;
        gap: 6px;
    }
    .digit-container {
        width: 28px;
        height: 52px;
    }
    .label {
        font-size: 1rem;
        margin-top: 8px;
    }
    .day-labels-left {
        font-size: 0.9rem;
        min-width: 36px;
    }
    .current-time-subpanel {
        font-size: 0.85rem;
        margin-top: 10px;
        padding-top: 6px;
    }
    .sub-clock-digits {
        font-size: 1.05rem;
        margin-left: 6px;
    }
}

@media (max-width: 600px) {
    .lcd-screen {
        padding: 8px 8px;
        grid-template-columns: 1.25fr 1fr 1fr 1fr;
        gap: 4px;
    }
    .lcd-section {
        padding: 0 4px;
    }
    .digit-container {
        width: 20px;
        height: 38px;
    }
    .label {
        font-size: 0.75rem;
        margin-top: 4px;
    }
    .day-labels-left {
        font-size: 0.7rem;
        min-width: 26px;
    }
    .digits-group {
        gap: 3px;
    }
    .day-section .digits-group {
        margin-left: 6px;
    }
    .current-time-subpanel {
        font-size: 0.7rem;
        margin-top: 6px;
        padding-top: 4px;
    }
    .sub-clock-digits {
        font-size: 0.8rem;
        margin-left: 4px;
    }
}

@media (max-width: 480px) {
    .timer-display {
        font-size: clamp(2rem, 12vw, 60px);
    }
    .digit-group {
        min-width: 40px;
    }
    .nav-btn {
        font-size: 20px;
    }
    .separator {
        min-width: 10px;
        padding-bottom: 15px;
    }
    .top-controls {
        position: static;
        margin-bottom: 10px;
    }
    .timer-card {
        margin-top: 10px;
    }
}

@media (max-width: 380px) {
    .lcd-screen {
        padding: 6px 4px;
        gap: 2px;
    }
    .lcd-section {
        padding: 0 2px;
    }
    .digit-container {
        width: 16px;
        height: 30px;
    }
    .day-labels-left {
        font-size: 0.65rem;
        min-width: 20px;
    }
    .day-section .digits-group {
        margin-left: 3px;
    }
    .digits-group {
        gap: 2px;
    }
    .label {
        font-size: 0.65rem;
        margin-top: 2px;
    }
    .current-time-subpanel {
        font-size: 0.65rem;
        margin-top: 4px;
        padding-top: 2px;
    }
    .sub-clock-digits {
        font-size: 0.75rem;
        margin-left: 2px;
    }
}
