:root {
    --primary: #4CAF50;
    --primary-hover: #43A047;
    --danger: #ef5350;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --border-radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    padding: 15px;
    padding-top: env(safe-area-inset-top, 15px);
    padding-bottom: env(safe-area-inset-bottom, 15px);
    overscroll-behavior-y: none;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--card-bg);
    padding: 10px 15px;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    position: relative;
    z-index: 100;
}

header h1 {
    font-size: 20px;
    color: var(--text);
    font-weight: 800;
}

.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: #e0e6ed;
    color: #4a5568;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s;
}

.icon-btn:active {
    transform: scale(0.9);
}

#add-student-btn {
    background-color: var(--primary);
    color: white;
}

.menu-container {
    position: relative;
}

#dropdown-menu {
    position: absolute;
    top: 50px;
    right: 0;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    width: 250px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#dropdown-menu.hidden {
    display: none;
}

#dropdown-menu button {
    padding: 15px 20px;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid #f0f0f0;
    font-size: 16px;
    width: 100%;
    cursor: pointer;
    color: var(--text);
}

#dropdown-menu button:last-child {
    border-bottom: none;
}

#dropdown-menu button.danger {
    color: var(--danger);
    font-weight: bold;
}

.grid {
    display: grid;
    /* Grid compact pour afficher plein d'élèves */
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    padding-bottom: 50px;
}

.card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: rgba(239, 83, 80, 0.1);
    color: var(--danger);
    border: none;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
}

/* Zone Photo */
.photo-container {
    width: 70px;
    height: 70px;
    margin-top: 15px;
    border-radius: 50%;
    background-color: #ecf0f1;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    border: 3px solid #fff;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.photo-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    font-size: 12px;
    text-align: center;
    padding: 2px 0;
    opacity: 0.8;
}

.photo-container:active {
    transform: scale(0.95);
}

/* Zone Nom */
.name-container {
    width: 100%;
    padding: 10px 5px;
    text-align: center;
}

.name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    -webkit-user-select: auto;
    user-select: auto;
    cursor: text;
    border-bottom: 1px dashed transparent;
    outline: none;
    padding: 2px 5px;
    word-break: break-word;
    display: inline-block;
    max-width: 100%;
}

.name:focus {
    border-bottom: 1px dashed #3498db;
    background-color: #f8f9fa;
    border-radius: 4px;
}

.name:empty:before {
    content: "Nom";
    color: #bdc3c7;
}

/* Zone Tours (Bouton géant +1) */
.add-lap-area {
    width: 100%;
    flex: 1;
    background-color: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
    margin-top: auto;
    transition: background-color 0.1s;
    touch-action: manipulation;
}

.add-lap-area:active {
    background-color: var(--primary-hover);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

.laps-count {
    font-size: 40px;
    font-weight: 900;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.laps-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    opacity: 0.8;
    margin-top: 5px;
}

/* Retrait d'un tour */
.remove-lap-btn {
    width: 100%;
    background-color: #ecf0f1;
    color: #7f8c8d;
    border: none;
    padding: 8px 0;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-top: 1px solid #e0e6ed;
}

.remove-lap-btn:active {
    background-color: #bdc3c7;
    color: #34495e;
}

/* --- Modal Mode d'emploi --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 15px;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 25px;
    max-width: 500px;
    width: 100%;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-content h2 {
    color: var(--text);
    margin-bottom: 20px;
    font-size: 24px;
    font-weight: 800;
    text-align: center;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 32px;
    background: none;
    border: none;
    color: #95a5a6;
    cursor: pointer;
    line-height: 0.8;
}

.close-btn:active {
    color: var(--danger);
}

.help-text h3 {
    color: var(--primary);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 16px;
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 5px;
}

.help-text ul {
    padding-left: 20px;
    color: var(--text);
    margin-bottom: 10px;
}

.help-text li {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 8px;
}

.help-text p {
    font-size: 14px;
    line-height: 1.5;
    background-color: #f8f9fa;
    padding: 10px;
    border-radius: 8px;
    border-left: 4px solid #3498db;
}