:root {
    --primary-color: #FF9800; /* Orange */
    --primary-hover: #F57C00;
    --secondary-color: #FFEB3B; /* Jaune */
    --bg-color: #121212; /* Noir */
    --text-color: #E0E0E0;
    --card-bg: #1E1E1E;
    --radius: 25px; /* Design très arrondi */
    --gradient-primary: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    --gradient-bg: linear-gradient(135deg, #0f0f13 0%, #1a1a1a 100%); /* Noir et gris */
    --gradient-card: linear-gradient(135deg, #1E1E1E 0%, #252525 100%);
}

/* Theme Colors */
[data-theme="text"], .nav-text {
    --primary-color: #03A9F4; /* Blue */
    --secondary-color: #81D4FA;
}

[data-theme="media"], .nav-media {
    --primary-color: #9C27B0; /* Purple */
    --secondary-color: #CE93D8;
}

[data-theme="time"], .nav-time {
    --primary-color: #009688; /* Teal */
    --secondary-color: #80CBC4;
}

[data-theme="web"], .nav-web {
    --primary-color: #3F51B5; /* Indigo */
    --secondary-color: #7986CB;
}

[data-theme="maths"], .nav-maths {
    --primary-color: #FF5722; /* Deep Orange */
    --secondary-color: #FF8A65;
}

[data-theme="misc"], .nav-misc {
    --primary-color: #E91E63; /* Pink */
    --secondary-color: #F48FB1;
}

.nav-text {
    --secondary-color: #81D4FA;
}

.nav-media {
    --secondary-color: #CE93D8;
}

.nav-web {
    --secondary-color: #7986CB;
}

.nav-maths {
    --secondary-color: #FF8A65;
}

.nav-misc {
    --secondary-color: #F48FB1;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

body {
    background: var(--gradient-bg);
    background-attachment: fixed;
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    background: var(--gradient-card);
    padding: 2rem;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    max-width: 1280px;
    width: calc(100% - 4rem);
    margin: 1rem auto 2rem auto;
    border-radius: var(--radius);
        position: relative;
}

    /* --- Language Switcher --- */
    .lang-switch { position: absolute; right: 2rem; top: 2rem; display: flex; gap: 0.5rem; z-index: 10; }
    .lang-btn { background: #2a2a2a; color: #888; border: 1px solid #444; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 0.8rem; font-weight: bold; transition: 0.2s; }
    .lang-btn.active { background: var(--primary-color); color: #121212; border-color: var(--primary-color); }
    .lang-btn:hover:not(.active) { background: #333; color: #fff; }
    @media (max-width: 600px) { .lang-switch { position: relative; right: 0; top: 0; justify-content: center; margin-bottom: 1rem; } }

.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.search-container {
    display: flex;
    justify-content: flex-end;
    flex-grow: 1;
}

#tool-search {
    width: 100%;
    max-width: 200px; /* Taille réduite de moitié */
    padding: 0.6rem 1rem;
    border-radius: 8px;
    border: 1px solid #444;
    background-color: #2a2a2a;
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
}

#tool-search:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.3);
}

nav {
    display: flex;
    justify-content: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

nav a {
    color: var(--secondary-color);
    text-decoration: none;
    font-weight: 600;
    padding: 0.5rem 1.2rem;
    border-radius: var(--radius);
    border: 1px solid var(--secondary-color);
    transition: all 0.3s ease;
}

nav a:hover, nav a.active {
    background-color: var(--secondary-color);
    color: var(--bg-color);
}

.logo, .logo a {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
    background: linear-gradient(135deg, #FF9800 0%, #FFEB3B 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header h1 {
    color: var(--text-color);
    margin: 1rem 0 0.5rem 0;
}

.container {
    max-width: 1280px;
    width: calc(100% - 4rem);
    margin: 0 auto;
    padding: 0;
}

.tag {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: bold;
    color: #121212;
    position: absolute;
    bottom: 0;
    left: 0;
    border-radius: 0 var(--radius) 0 var(--radius); /* Coin arrondi en haut à droite et en bas à gauche */
    margin: 0;
}

.tag-text { background-color: #03A9F4; }
.tag-media { background-color: #9C27B0; }
.tag-time { background-color: #009688; }
.tag-web { background-color: #3F51B5; }
.tag-maths { background-color: #FF5722; }
.tag-misc { background-color: #E91E63; }

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
    gap: 1.5rem;
}

.tool-card {
    display: flex;
    flex-direction: column;
    position: relative; /* Pour positionner l'étoile */
    background: var(--gradient-card);
    padding: 1.5rem;
    padding-bottom: 3.5rem; /* Crée de l'espace pour le tag collé en bas */
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-color);
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
    border: 2px solid transparent;
}

.tool-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
    border-color: var(--primary-color);
}

.tool-card p {
    margin-bottom: 1rem;
}

.tool-card h3 {
    color: var(--text-color);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-right: 3rem; /* Empêche le titre de passer sous l'étoile */
    line-height: 1.3;
}

.favorite-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: var(--secondary-color);
    cursor: pointer;
    z-index: 10;
    transition: transform 0.2s;
    background: none;
    border: none;
    padding: 0.5rem;
    line-height: 0;
}

.favorite-btn:hover {
    transform: scale(1.2);
}

.favorite-btn.favorited svg.feather,
.favorite-btn.favorited i[data-feather] {
    fill: var(--secondary-color);
    color: var(--secondary-color);
}

.tool-interface {
    background: var(--gradient-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.controls {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
}

.input-group input,
.url-input-group input,
.controls input[type="number"],
.controls input[type="url"] {
    padding: 0.6rem 1rem;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: var(--text-color);
    width: 100%;
    max-width: 100%;
}

.input-group input[type="color"],
.url-input-group input[type="color"] {
    padding: 2px 4px;
    width: 60px;
    height: 42px;
    cursor: pointer;
}

.custom-file-upload {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.custom-file-label {
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 0.6rem 1rem;
    cursor: pointer;
    color: var(--text-color);
    transition: background 0.2s, border-color 0.2s;
}

.custom-file-label:hover {
    background: #3a3a3a;
    border-color: var(--primary-color);
}

.file-name-text {
    font-size: 0.9rem;
    color: #888;
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.url-input-group {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

select {
    padding: 0.6rem 1rem;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: var(--text-color);
    width: 100%;
    max-width: 100%;
}

.btn-primary {
    background: var(--gradient-primary);
    color: var(--bg-color);
    border: 1px solid transparent;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s, transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: scale(1.02);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.btn-secondary {
    background: transparent;
    color: var(--text-color);
    border: 1px solid #444;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s, transform 0.2s;
}

.btn-secondary:hover {
    background: #2a2a2a;
    transform: scale(1.02);
}

textarea {
    width: 100%;
    padding: 1rem;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: var(--text-color);
    resize: vertical;
}

/* --- Input result custom style (Unit Converter) --- */
.uc-output {
    font-weight: bold;
    color: #FF9800 !important;
    background-color: #2a2a2a !important;
    font-size: 1rem !important;
    text-align: center;
    border: 1px solid #FF9800 !important;
    border-radius: 8px !important;
    padding: 0.6rem 1rem !important;
    box-sizing: border-box;
}

/* --- Iconography (Feather Icons) --- */
/* Taille globale réduite pour toutes les icônes */
svg.feather, i[data-feather] {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    stroke-width: 2; /* Tracé plus fin et élégant */
}

/* Espacement par défaut lorsqu'il y a du texte à côté */
.btn-primary svg.feather, .btn-secondary svg.feather, nav a svg.feather, .tool-card h3 svg.feather,
.btn-primary i[data-feather], .btn-secondary i[data-feather], nav a i[data-feather], .tool-card h3 i[data-feather] {
    margin-right: 0.5rem;
}

/* Grosses icônes sur les boutons principaux */
.btn-primary svg.feather, .btn-secondary svg.feather,
.btn-primary i[data-feather], .btn-secondary i[data-feather] {
    width: 1.25em;
    height: 1.25em;
    stroke-width: 2.5;
    vertical-align: -0.25em;
}

/* Grosses icônes sur les briques (cartes) de la page principale */
.tool-card h3 svg.feather,
.tool-card h3 i[data-feather] {
    width: 1.5em;
    height: 1.5em;
    stroke-width: 2.5;
    vertical-align: -0.25em;
}

/* Taille pour les titres du header */
header h1 svg.feather,
header h1 i[data-feather] {
    width: 0.8em;
    height: 0.8em;
    stroke-width: 3;
    margin-right: 0.5rem;
}

/* Icon-only buttons */
.btn-icon, .copy-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem;
}

.btn-icon svg.feather, .copy-icon-btn svg.feather,
.btn-icon i[data-feather], .copy-icon-btn i[data-feather] {
    margin-right: 0;
    width: 1.2em;
    height: 1.2em;
}

/* Ajustements pour le bouton Favoris */
.favorite-btn svg.feather,
.favorite-btn i[data-feather] { 
    stroke-width: 2; 
    margin-right: 0; 
    width: 1.2em;
    height: 1.2em;
}
/* Styles spécifiques pour l'analyseur d'image */
.analyzer-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
}

@media (max-width: 768px) {
    .analyzer-layout {
        grid-template-columns: 1fr;
    }
}

.canvas-container {
    width: 100%;
    border: 2px dashed #444;
    border-radius: var(--radius);
    position: relative; /* Indispensable pour la loupe absolue */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #222;
    min-height: 300px;
    cursor: crosshair;
}

#image-canvas.locked {
    cursor: not-allowed;
}

#image-canvas {
    max-width: 100%;
    max-height: 600px;
    display: none;
}

#loupe-container {
    display: none;
    position: absolute;
    width: 100px;
    height: 100px;
    border: 3px solid #fff;
    border-radius: 50%;
    overflow: hidden;
    pointer-events: none; /* Empêche la loupe de bloquer les clics de la souris */
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 10;
    background-color: #222;
}

#loupe-canvas {
    width: 100px;
    height: 100px;
    image-rendering: pixelated; /* Empêche le flou du zoom pour voir les pixels nets */
}

.loupe-crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 4px;
    background-color: #ff0000;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    box-shadow: 0 0 0 1px #ffffff;
}

.color-results {
    background: var(--gradient-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.color-preview-box {
    width: 100%;
    height: 100px;
    border-radius: var(--radius);
    border: 2px solid #444;
    background-color: transparent;
    transition: background-color 0.1s;
}

.color-value {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e1e1e;
    padding: 0.8rem;
    border-radius: 15px;
    font-family: monospace;
    font-size: 1.1rem;
    gap: 1rem;
}

.color-value strong {
    flex-grow: 1;
}

.copy-icon-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.6;
    transition: opacity 0.2s, transform 0.2s;
}

/* --- Responsiveness & Mobile Accessibility --- */

/* === Tablet (≤ 900px) === */
@media (max-width: 900px) {
    header {
        width: calc(100% - 2rem);
        padding: 1.5rem;
    }

    .container {
        width: calc(100% - 2rem);
    }

    nav a {
        padding: 0.4rem 0.9rem;
        font-size: 0.9rem;
    }

    #tool-search {
        max-width: 250px;
    }
}

/* === Mobile (≤ 600px) === */
@media (max-width: 600px) {
    header {
        padding: 1.2rem 1rem;
        width: calc(100% - 1.5rem);
        margin: 0.75rem auto 1.25rem auto;
    }

    .logo, .logo a {
        font-size: 1.5rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    header > p {
        font-size: 0.9rem;
    }

    .header-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    nav {
        justify-content: center;
        gap: 0.4rem;
        /* Scroll horizontal si trop d'items */
        overflow-x: auto;
        flex-wrap: wrap;
        padding-bottom: 0.25rem;
    }

    nav a {
        padding: 0.35rem 0.65rem;
        font-size: 0.82rem;
        white-space: nowrap;
    }

    .search-container {
        width: 100%;
    }

    #tool-search {
        max-width: 100%;
    }

    .container {
        width: calc(100% - 1.5rem);
        padding: 0;
    }

    .tool-interface {
        padding: 1.25rem 0.9rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem !important;
    }

    .url-input-group {
        flex-direction: column;
    }

    .custom-file-upload {
        flex-wrap: wrap;
    }

    .file-name-text {
        max-width: none;
        width: 100%;
    }

    /* Taille tactile minimale (WCAG 2.5.5) */
    .btn-primary,
    .btn-secondary {
        min-height: 44px;
        touch-action: manipulation;
    }

    .lang-btn {
        min-height: 36px;
        min-width: 36px;
    }
}

/* === Très petits écrans (≤ 380px) === */
@media (max-width: 380px) {
    header h1 {
        font-size: 1.1rem;
    }

    .logo, .logo a {
        font-size: 1.25rem;
    }

    nav a {
        font-size: 0.78rem;
        padding: 0.3rem 0.55rem;
    }
}

.copy-icon-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* --- Custom Modal Error --- */
.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(3px);
}
.custom-modal-box {
    background: var(--gradient-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid #444;
    text-align: center;
    max-width: 400px;
    width: 90%;
}
.custom-modal-box p {
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
}

footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: auto; /* Pousse le footer tout en bas */
    margin-bottom: 1rem; /* Marge en base de base */
    color: #888;
    font-size: 0.9rem;
}