: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="image"], .nav-image {
    --primary-color: #9C27B0; /* Purple */
    --secondary-color: #CE93D8;
}

[data-theme="time"], .nav-time {
    --primary-color: #009688; /* Teal */
    --secondary-color: #80CBC4;
}

.nav-text {
    --secondary-color: #81D4FA;
}

.nav-image {
    --secondary-color: #CE93D8;
}

* {
    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;
}

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);
}

.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;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 2rem;
}

.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-image { background-color: #9C27B0; }
.tag-time { background-color: #009688; }

.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: 1.5rem;
    font-size: 1.8rem;
    color: var(--secondary-color);
    cursor: pointer;
    z-index: 10;
    transition: transform 0.2s;
}

.favorite-btn:hover {
    transform: scale(1.2);
}

.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 {
    padding: 0.6rem 1rem;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: var(--text-color);
}

.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;
}

.url-input-group input {
    flex-grow: 1;
}

select {
    padding: 0.6rem 1rem;
    border: 1px solid #444;
    border-radius: 8px;
    background-color: #2a2a2a;
    color: var(--text-color);
}

.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;
}

/* 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 --- */
@media (max-width: 600px) {
    header {
        padding: 1.5rem 1rem;
        width: calc(100% - 2rem);
        margin: 1rem auto 1.5rem auto;
    }
    
    .header-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 1.5rem;
    }
    
    nav {
        justify-content: center;
    }
    
    .search-container {
        width: 100%;
    }
    
    #tool-search {
        max-width: 100%;
    }
    
    .container {
        padding: 0 1rem;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
}

.copy-icon-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Styles spécifiques pour le chronomètre */
#stopwatch-display {
    font-size: 5rem;
    font-family: monospace;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.stopwatch-controls {
    justify-content: center;
}

.stopwatch-controls button {
    min-width: 120px;
}

.laps-container {
    margin-top: 2rem;
    max-height: calc(10 * 53px); /* A bit more than 10 laps height */
    overflow-y: auto;
    background-color: #121212;
    border-radius: 8px;
    padding: 0 0.5rem;
}

.laps-header-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-weight: bold;
    color: #aaa;
    position: sticky;
    top: 0;
    background: #121212;
}

#laps-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#laps-list li {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    font-family: monospace;
    font-size: 1.1rem;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid #333;
}

.laps-header-list li {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid #444;
}

#laps-list li span:nth-child(1),
.laps-header-list li span:nth-child(1) {
    text-align: left;
}

#laps-list li span:nth-child(2),
.laps-header-list li span:nth-child(2) {
    text-align: center;
}

#laps-list li span:nth-child(2) {
    color: #aaa;
}

#laps-list li span:nth-child(3),
.laps-header-list li span:nth-child(3) {
    text-align: right;
}

#laps-list li:last-child {
    border-bottom: none;
}

#laps-list li.fastest {
    color: #4CAF50; /* Green */
    font-weight: bold;
}

#laps-list li.slowest {
    color: #F44336; /* Red */
    font-weight: bold;
}

/* Styles spécifiques pour le minuteur */
.timer-inputs {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.timer-inputs .input-group {
    align-items: center;
}

.timer-inputs input {
    width: 100px;
    text-align: center;
    font-size: 1.2rem;
}

#timer-display {
    font-size: 5rem;
    font-family: monospace;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.finished-flashing {
    animation: flash-red 0.7s infinite;
}

@keyframes flash-red {
    0% {
        color: var(--text-color);
        transform: scale(1);
    }
    50% {
        color: #F44336;
        transform: scale(1.05);
    }
    100% {
        color: var(--text-color);
        transform: scale(1);
    }
}