﻿/* =========================================================
   keyboard timing - Interface moderne de chronometrage
   Responsive portrait + paysage, grands elements tactiles
   ========================================================= */

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%       { transform: scale(1.6); opacity: 0.5; }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%  { transform: translateX(-8px); }
    40%  { transform: translateX(8px); }
    60%  { transform: translateX(-5px); }
    80%  { transform: translateX(5px); }
}
@keyframes flash-success {
    0%   { background: #0f172a; }
    40%  { background: #14532d; }
    100% { background: #0f172a; }
}
@keyframes modal-in {
    from { opacity: 0; transform: scale(0.93) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* == Variables ============================================ */
:root {
    --htk-gap: 10px;
    --htk-num-size: 76px;
    --htk-action-h: 70px;
    --htk-radius: 12px;
    --htk-panel: #0f172a;
    --htk-panel-soft: #1e293b;
    --htk-card-bg: var(--bg-primary);
    --htk-card-border: var(--border-color);
    --htk-shadow: 0 3px 12px rgba(15, 23, 42, 0.12);
}

/* == App root ============================================= */
.htk-app {
    padding: 0.55rem 0.75rem 0.75rem;
    display: grid;
    gap: var(--htk-gap);
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    /* Layout standard modules: colonne principale centree */
    grid-template-columns: 1fr;
    grid-template-areas:
        "header"
        "lane"
        "status"
        "display"
        "position"
        "numpad"
        "actions"
        "log";
    max-width: 620px;
    width: 100%;
    margin: 0 auto;
    height: min(100%, calc(var(--available-height, 100vh) - 0.25rem));
    grid-template-rows: auto auto auto minmax(120px, 1fr) auto auto auto auto;
    box-sizing: border-box;
    overflow: hidden;
}

/* == Header =============================================== */
.htk-header {
    grid-area: header;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid var(--htk-card-border);
}
.htk-module-title {
    font-size: 1.75rem;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1;
}
.htk-module-subtitle {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* == Panneau couloir - GRAND, visible de loin ============ */
.htk-lane-display {
    grid-area: lane;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    background: var(--htk-panel-soft);
    border: 1px solid #243850;
    border-radius: var(--htk-radius);
    padding: 0.65rem 1rem;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    transition: filter 0.15s, transform 0.1s;
    box-shadow: var(--htk-shadow);
}
.htk-lane-display:hover  { filter: brightness(1.12); }
.htk-lane-display:active { filter: brightness(0.88); transform: scale(0.98); }
.htk-lane-lbl {
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 700;
    align-self: flex-end;
    padding-bottom: 0.5rem;
}
.htk-lane-num {
    font-size: clamp(4.2rem, 18vw, 7.2rem);
    font-weight: 900;
    color: #f8fafc;
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    line-height: 1;
}
.htk-lane-arrow {
    font-size: 1.3rem;
    color: var(--text-secondary);
    align-self: flex-end;
    padding-bottom: 0.6rem;
}

/* == Status badge ========================================= */
.htk-status {
    grid-area: status;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.6rem;
    border-radius: var(--htk-radius);
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    transition: all 0.3s;
}
.htk-status.inactive { background: #fef2f2; color: #dc2626; border: 1.5px solid #fecaca; }
.htk-status.active   { background: #f0fdf4; color: #16a34a; border: 1.5px solid #86efac; }
.htk-status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.htk-status.inactive .htk-status-dot { background: #dc2626; }
.htk-status.active   .htk-status-dot { background: #16a34a; animation: pulse-dot 1.5s ease-in-out infinite; }

/* == Display panel ======================================== */
.htk-display {
    grid-area: display;
    background: var(--htk-panel);
    border-radius: var(--htk-radius);
    padding: 1rem 0.9rem;
    display: grid;
    grid-template-rows: minmax(64px, auto) auto auto;
    justify-items: center;
    align-items: center;
    gap: 0.7rem;
    box-shadow: var(--htk-shadow);
    position: relative;
    overflow: hidden;
    z-index: 1;
}
.htk-display.shake        { animation: shake 0.35s ease; }
.htk-display.flash-enter  { animation: flash-success 0.5s ease; }

/* Numero athlete - TRES GRAND */
.htk-athlete-num {
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: clamp(3.6rem, 16vw, 6rem);
    font-weight: 800;
    color: #f1f5f9;
    width: 100%;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    min-height: 1.2em;
    transition: color 0.2s;
    letter-spacing: -0.02em;
    overflow: visible;
}
.htk-athlete-num > span {
    display: inline-block;
    width: 100%;
}
.htk-athlete-num .htk-athlete-value {
    font-size: 1em !important;
    line-height: 1 !important;
    font-weight: 900;
    color: inherit;
}
.htk-athlete-num .htk-athlete-off {
    font-size: 0.9em !important;
    line-height: 1 !important;
    color: #1e293b;
    opacity: 0.45;
}
.htk-athlete-num .htk-athlete-placeholder {
    font-size: 0.6em !important;
    line-height: 1 !important;
    color: #64748b;
    letter-spacing: 0.08em;
    font-weight: 700;
}
.htk-athlete-num .htk-athlete-caret {
    animation: cursor-blink 0.9s step-end infinite;
    opacity: 0.5;
    font-size: 0.6em;
}

@keyframes cursor-blink {
    0%, 49% { opacity: 0.6; }
    50%, 100% { opacity: 0; }
}
.htk-athlete-num.validated {
    color: #4ade80;
    text-shadow: 0 0 30px rgba(74,222,128,0.4);
}

/* Points de tirs */
.htk-shots-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    justify-content: center;
}
.htk-dots {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.htk-dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #1e293b;
    border: 2px solid #334155;
    transition: all 0.3s;
}
.htk-dot.hit {
    background: #4ade80;
    border-color: #22c55e;
    box-shadow: 0 0 8px rgba(74,222,128,0.7);
}
.htk-shot-label {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    min-width: 48px;
}

/* Chrono */
.htk-timer-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 1.2em;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.08);
    position: relative;
    z-index: 2;
}
.htk-timer-icon {
    font-size: 1rem;
    opacity: 0.45;
}
.htk-timer {
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: clamp(1.4rem, 5vw, 2.2rem);
    font-weight: 700;
    color: #cbd5e1;
    letter-spacing: 0.1em;
    line-height: 1;
    white-space: nowrap;
    transition: color 0.3s;
}
.htk-timer.running { color: #4ade80; text-shadow: 0 0 12px rgba(74,222,128,0.4); }
.htk-timer.stopped { color: #cbd5e1; opacity: 0.95; }

.htk-timer-tenth {
    font-size: 0.6em;
    opacity: 0.75;
    letter-spacing: 0;
}

/* Zone bouton position (hors panneau display) */
.htk-position {
    grid-area: position;
    position: relative;
    z-index: 5;
    margin-bottom: 2px;
}

/* Bouton position - GRAND, pleine largeur */
.htk-pos-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    width: 100%;
    min-height: 84px;
    padding: 0.8rem 1.2rem;
    border-radius: var(--htk-radius);
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    border: 2.5px solid transparent;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    position: relative;
    z-index: 6;
}
.htk-pos-btn.standing {
    background: #1e3a5f;
    color: #93c5fd;
    border-color: #2d5a8e;
    box-shadow: 0 3px 0 #0f2040, 0 6px 14px rgba(30,58,95,0.34);
}
.htk-pos-btn.prone {
    background: #3b2f1e;
    color: #fdba74;
    border-color: #6b4220;
    box-shadow: 0 3px 0 #1c1408, 0 6px 14px rgba(59,47,30,0.34);
}
.htk-pos-btn:hover  { filter: brightness(1.15); }
.htk-pos-btn:active { transform: translateY(3px); box-shadow: none; }
.htk-pos-icon { font-size: 4.5rem; line-height: 1; display: flex; align-items: center; }

/* Silhouettes tireur SVG */
.htk-pos-svg   { display: block; }
.htk-pos-svg-v { height: 52px; width: auto; }
.htk-pos-svg-h { height: 34px; width: auto; }

/* == Numpad =============================================== */
.htk-numpad {
    grid-area: numpad;
    display: flex;
    flex-direction: column;
    gap: var(--htk-gap);
    position: relative;
    z-index: 3;
}
.htk-num-row {
    display: flex;
    gap: var(--htk-gap);
    justify-content: stretch;
    width: 100%;
}
.htk-num {
    width: auto;
    height: clamp(74px, 14vw, 98px);
    flex: 1;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: clamp(1.5rem, 6vw, 1.9rem);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 0 var(--border-color), 0 2px 6px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
    font-family: system-ui, sans-serif;
}
.module-content .htk-num {
    font-size: clamp(1.6rem, 5.8vw, 2.2rem) !important;
    font-weight: 800 !important;
}
.htk-num:hover  { background: var(--bg-secondary); border-color: var(--primary-color); transform: translateY(-1px); box-shadow: 0 3px 0 var(--border-color), 0 6px 12px rgba(0,0,0,0.1); }
.htk-num:active { transform: translateY(2px); box-shadow: none; background: var(--bg-secondary); }
.htk-num-zero   { width: 100%; }

/* == Ligne START (haut du numpad) ========================= */
.htk-start-row .htk-btn {
    flex: 1;
    flex-direction: row;
    height: var(--htk-action-h);
    gap: 0.6rem;
    font-size: 0.92rem;
    letter-spacing: 0.06em;
}
.htk-start-row .htk-btn .htk-btn-icon { font-size: 1.6rem; }

/* == Ligne bas : ENTER | 0 | CLEAR ======================== */
.htk-bottom-row .htk-btn {
    flex: 1;
    height: clamp(74px, 14vw, 98px);
}
.htk-bottom-row .htk-num { flex: 1; }

/* == Actions (END SHOOTING pleine largeur) ================ */
.htk-actions {
    grid-area: actions;
    display: flex;
    gap: var(--htk-gap);
}
.htk-actions .htk-btn {
    flex: 1;
    flex-direction: row;
    gap: 0.6rem;
}
.htk-actions .htk-btn .htk-btn-icon { font-size: 1.5rem; }
.htk-btn {
    height: var(--htk-action-h);
    border-radius: 10px;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-weight: 700;
    font-size: 0.74rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #fff;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.htk-btn .htk-btn-icon { font-size: 1.5rem; line-height: 1; }
.htk-btn:active:not(:disabled) { transform: translateY(3px); filter: brightness(0.88); }
.htk-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.htk-btn-start { background: #16a34a; box-shadow: 0 4px 0 #14532d; }
.htk-btn-start:hover:not(:disabled) { background: #22c55e; }
.htk-btn-clear { background: #f59e0b; box-shadow: 0 4px 0 #b45309; }
.htk-btn-clear:hover:not(:disabled) { background: #fbbf24; }
.htk-btn-enter { background: #2563eb; box-shadow: 0 4px 0 #1e40af; }
.htk-btn-enter:hover:not(:disabled) { background: #3b82f6; }
.htk-btn-end   { background: #dc2626; box-shadow: 0 4px 0 #991b1b; }
.htk-btn-end:hover:not(:disabled)   { background: #ef4444; }

/* == Log ================================================== */
.htk-log {
    grid-area: log;
    background: var(--htk-card-bg);
    border: 1px solid var(--htk-card-border);
    border-radius: var(--htk-radius);
    overflow: hidden;
    box-shadow: var(--htk-shadow);
}
.htk-log-hdr {
    padding: 0.5rem 1rem;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--htk-card-border);
}
.htk-log-list {
    max-height: 88px;
    min-height: 88px;
    overflow-y: auto;
    overflow-x: hidden;
}
.htk-log-entry {
    display: flex;
    gap: 0.6rem;
    padding: 0.2rem 0.9rem;
    font-size: 0.68rem;
    line-height: 1.2;
    color: var(--text-primary);
    border-bottom: 1px solid var(--bg-secondary);
}
.htk-log-time {
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
    font-size: 0.65rem;
}

/* == Modale couloir ======================================= */
.htk-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    padding: 1rem;
}
.htk-modal {
    background: var(--bg-primary);
    border-radius: 14px;
    padding: 1.5rem;
    width: 100%;
    max-width: 370px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 18px 42px rgba(0,0,0,0.25);
    animation: modal-in 0.25s ease;
}
.htk-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.htk-modal-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
}
.htk-modal-close {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.htk-modal-close:hover  { background: var(--bg-secondary); }
.htk-modal-close:active { background: var(--border-color); }

.htk-modal-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}
.htk-lane-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}
.htk-lane-tile {
    aspect-ratio: 1;
    border-radius: 10px;
    border: 1px solid var(--htk-card-border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.htk-lane-tile:hover  { background: var(--bg-secondary); border-color: var(--primary-color); color: var(--primary-color); }
.htk-lane-tile:active { background: var(--bg-secondary); transform: scale(0.93); }
.htk-lane-tile.selected {
    background: var(--primary-color);
    border-color: var(--kiwi-primary-dark, #7CB342);
    color: #1a1a1a;
    box-shadow: 0 3px 10px rgba(154,205,50,0.35);
}

/* == Responsive paysage tablette/telephone ======================== */
@media (min-width: 600px) and (max-width: 1366px) and (orientation: landscape) {
    .htk-app {
        padding: 0.45rem;
        gap: 0.45rem;
        max-width: 100%;
        grid-template-columns: minmax(220px, 1.15fr) minmax(320px, 1.35fr);
        grid-template-rows: auto minmax(140px, 1fr) auto auto;
        grid-template-areas:
            "lane     numpad"
            "display  numpad"
            "position actions"
            "log      log";
        height: min(100%, calc(var(--available-height, 100vh) - 0.5rem));
        box-sizing: border-box;
        overflow: hidden;
    }

    /* Version paysage: header/status masques pour gagner de la place */
    .htk-header { display: none; }
    .htk-status {
        display: flex;
        padding: 0.3rem;
        font-size: 0.66rem;
        letter-spacing: 0.07em;
    }

    .htk-log { border-radius: 10px; }
    .htk-log-list { min-height: 88px; max-height: 88px; }

    /* Couloir - compact mais lisible */
    .htk-lane-display {
        padding: 0.3rem 0.8rem;
        border-radius: 12px;
        gap: 0.4rem;
        box-shadow: none;
    }
    .htk-lane-lbl   { font-size: 0.5rem; letter-spacing: 0.15em; padding-bottom: 0.15rem; }
    .htk-lane-num   { font-size: clamp(2rem, 7.2vh, 4.5rem); }
    .htk-lane-arrow { font-size: 0.9rem; padding-bottom: 0.15rem; }

    /* Panneau numero athlete */
    .htk-display { padding: 0.55rem 0.7rem; gap: 0.3rem; overflow: visible; }
    .htk-athlete-num { font-size: clamp(2.2rem, 10vh, 5.2rem); }

    /* Chrono compact */
    .htk-timer      { font-size: clamp(1rem, 4vh, 1.6rem); letter-spacing: 0.05em; }
    .htk-timer-icon { display: none; }

    /* Bouton position */
    .htk-position { display: flex; align-items: stretch; }
    .htk-pos-btn {
        min-height: 0;
        padding: 0.4rem 0.8rem;
        font-size: clamp(0.85rem, 2.5vh, 1.1rem);
        border-radius: 12px;
        gap: 0.5rem;
    }
    .htk-pos-svg-v { height: clamp(24px, 7vh, 38px); }
    .htk-pos-svg-h { height: clamp(14px, 4.2vh, 24px); }

    /* Numpad - colonne flex : START + chiffres + ENTER|0|CLEAR */
    .htk-numpad {
        display: flex;
        flex-direction: column;
        gap: 6px;
        height: 100%;
        min-height: 0;
    }
    .htk-num-row { display: flex; gap: 6px; flex: 1; min-height: 0; }
    .htk-start-row { flex: 0 0 auto; min-height: clamp(44px, 8vh, 58px); }
    .htk-start-row .htk-btn {
        flex: 1;
        flex-direction: row;
        gap: 8px;
        height: 100%;
        font-size: clamp(0.75rem, 2.4vh, 1rem);
        border-radius: 10px;
        padding: 0.3rem 0.8rem;
        box-shadow: 0 2px 0 #14532d;
    }
    .htk-start-row .htk-btn .htk-btn-icon { font-size: clamp(1rem, 3vh, 1.5rem); }
    .htk-num {
        flex: 1;
        height: 100%;
        width: auto;
        min-height: 0;
        font-size: clamp(1.2rem, 4vh, 2rem);
        border-radius: 10px;
    }
    .htk-bottom-row { flex: 0 0 auto; min-height: clamp(44px, 8vh, 58px); }
    .htk-bottom-row .htk-btn {
        flex: 1;
        height: 100%;
        flex-direction: column;
        gap: 1px;
        font-size: clamp(0.52rem, 1.6vh, 0.72rem);
        border-radius: 10px;
        padding: 0.15rem 0.1rem;
    }
    .htk-bottom-row .htk-btn .htk-btn-icon { font-size: clamp(0.9rem, 2.8vh, 1.3rem); }
    .htk-bottom-row .htk-num { flex: 1; height: 100%; min-height: 0; }

    /* Actions - END SHOOTING pleine largeur */
    .htk-actions { display: flex; gap: 7px; }
    .htk-actions .htk-btn {
        flex: 1;
        flex-direction: row;
        gap: 8px;
        height: auto;
        min-height: clamp(44px, 8vh, 58px);
        font-size: clamp(0.75rem, 2.4vh, 1rem);
        border-radius: 10px;
        padding: 0.3rem 0.8rem;
        box-shadow: 0 2px 0 #991b1b;
    }
    .htk-actions .htk-btn .htk-btn-icon { font-size: clamp(1rem, 3vh, 1.5rem); }
    .htk-btn-clear { box-shadow: 0 2px 0 #b45309; }
    .htk-btn-enter { box-shadow: 0 2px 0 #1e40af; }
}

/* == Portrait tablette + mobile =========================== */
@media (max-width: 1366px) and (orientation: portrait) {
    .htk-app {
        max-width: 100%;
        padding: 0.28rem 0.5rem 0.4rem;
        gap: 0.3rem;
        height: min(100%, calc(var(--available-height, 100vh) - 0.2rem));
        overflow: hidden;
        grid-template-areas:
            "lane"
            "status"
            "display"
            "position"
            "numpad"
            "actions"
            "log";
        grid-template-rows: auto auto minmax(0, 1fr) auto minmax(0, 2.2fr) auto auto;
    }

    .htk-header { display: none; }

    .htk-status {
        display: flex;
        padding: 0.3rem;
        font-size: 0.68rem;
        letter-spacing: 0.07em;
    }

    .htk-lane-display { padding: 0.3rem 0.7rem; }
    .htk-lane-num { font-size: clamp(2.8rem, 9vh, 5rem) !important; }

    .htk-display {
        min-height: 0;
        padding: 0.5rem 0.7rem;
        gap: 0.3rem;
        overflow: hidden;
        grid-template-rows: minmax(0, 1fr) auto auto;
        align-content: center;
    }
    .htk-athlete-num {
        font-size: clamp(2rem, 8.5vh, 4rem) !important;
        line-height: 0.9 !important;
        min-height: 0;
    }
    .htk-athlete-num .htk-athlete-value  { font-size: 1em !important; }
    .htk-athlete-num .htk-athlete-placeholder { font-size: 0.65em !important; }
    .htk-timer { font-size: clamp(1rem, 3.5vh, 1.8rem) !important; }
    .htk-dots { gap: 8px; }
    .htk-dot  { width: 12px; height: 12px; }
    .htk-shot-label { font-size: clamp(0.7rem, 2.5vh, 1rem) !important; min-width: 56px; }

    .htk-position { z-index: 5; }
    .htk-pos-btn {
        min-height: 0;
        height: clamp(48px, 6.5vh, 72px);
        font-size: clamp(0.75rem, 2.5vh, 1rem);
        padding: 0.3rem 0.6rem;
    }
    .htk-pos-svg-v { height: clamp(24px, 4vh, 36px); }
    .htk-pos-svg-h { height: clamp(16px, 2.8vh, 26px); }

    /* Numpad flex column - même technique qu'en paysage */
    .htk-numpad {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 0;
        gap: 0.3rem;
    }
    .htk-num-row {
        display: flex;
        gap: 0.3rem;
        flex: 1;
        min-height: 0;
    }
    .htk-num {
        flex: 1;
        height: 100%;
        width: auto;
        min-height: 0;
        font-size: clamp(1.4rem, 5vh, 2.4rem) !important;
        border-radius: 10px;
    }
    .htk-start-row {
        flex: 1;
    }
    .htk-start-row .htk-btn {
        flex: 1;
        flex-direction: row;
        height: 100%;
        gap: 0.5rem;
        font-size: clamp(0.7rem, 2.4vh, 0.95rem);
        border-radius: 10px;
        padding: 0.2rem 0.6rem;
        box-shadow: 0 2px 0 #14532d;
    }
    .htk-start-row .htk-btn .htk-btn-icon { font-size: clamp(1rem, 3.2vh, 1.5rem); }
    .htk-bottom-row {
        flex: 1;
    }
    .htk-bottom-row .htk-btn {
        flex: 1;
        height: 100%;
        flex-direction: column;
        gap: 1px;
        font-size: clamp(0.5rem, 1.8vh, 0.7rem);
        border-radius: 10px;
        padding: 0.1rem;
    }
    .htk-bottom-row .htk-btn .htk-btn-icon { font-size: clamp(0.9rem, 3vh, 1.3rem); }
    .htk-bottom-row .htk-num { flex: 1; height: 100%; min-height: 0; }

    .htk-actions { gap: 0.3rem; }
    .htk-actions .htk-btn {
        flex: 1;
        flex-direction: row;
        gap: 0.4rem;
        height: clamp(40px, 5.5vh, 58px);
        font-size: clamp(0.65rem, 2.2vh, 0.85rem);
        border-radius: 10px;
    }
    .htk-actions .htk-btn .htk-btn-icon { font-size: clamp(1rem, 3vh, 1.4rem); }

    .htk-btn {
        min-height: 0;
        height: auto;
    }

    .htk-log { display: block; overflow: hidden; }
    .htk-log-hdr { padding: 0.22rem 0.6rem; font-size: 0.58rem; }
    .htk-log-list { min-height: 0; max-height: clamp(52px, 7vh, 80px); }
    .htk-log-entry { padding: 0.14rem 0.55rem; font-size: 0.58rem; line-height: 1.2; }
}

/* == Smartphone portrait serré ============================ */
@media (max-width: 600px) and (orientation: portrait) {
    .htk-app {
        padding: 0.2rem 0.4rem 0.35rem;
        gap: 0.25rem;
        grid-template-rows: auto auto minmax(0, 1fr) auto minmax(0, 2fr) auto auto;
    }
    .htk-lane-num { font-size: clamp(2.4rem, 8vh, 3.8rem) !important; }
    .htk-status   { padding: 0.25rem; font-size: 0.62rem; }
    .htk-display  { padding: 0.4rem 0.55rem; gap: 0.22rem; }
    .htk-athlete-num {
        font-size: clamp(1.8rem, 7.5vh, 3.2rem) !important;
        line-height: 0.9 !important;
    }
    .htk-timer { font-size: clamp(0.9rem, 3vh, 1.4rem) !important; }
    .htk-pos-btn   { height: clamp(42px, 5.8vh, 60px); font-size: clamp(0.7rem, 2.2vh, 0.9rem); }
    .htk-pos-svg-v { height: clamp(20px, 3.5vh, 30px); }
    .htk-pos-svg-h { height: clamp(13px, 2.2vh, 20px); }
    .htk-num       { font-size: clamp(1.2rem, 4.5vh, 2rem) !important; }
    .htk-actions .htk-btn { height: clamp(36px, 5vh, 50px); font-size: clamp(0.6rem, 2vh, 0.78rem); }
    .htk-log-list  { max-height: clamp(44px, 6vh, 66px); }
}

/* == Portrait mobile ===================================== */
@media (max-width: 768px) and (orientation: portrait) {
    :root { --htk-action-h: 54px; }
}
@media (max-width: 480px) and (orientation: portrait) {
    :root { --htk-action-h: 46px; }
    .htk-app { padding: 0.15rem 0.35rem 0.3rem; gap: 5px; }
    .htk-num { font-size: clamp(1.1rem, 4vh, 1.8rem) !important; }
}

/* == Desktop large ======================================= */
@media (min-width: 1367px) {
    .htk-app {
        max-width: min(1400px, 100%);
        grid-template-columns: minmax(320px, 1fr) minmax(460px, 1.2fr);
        grid-template-areas:
            "lane     numpad"
            "display  numpad"
            "position actions"
            "status   log";
        grid-template-rows: auto minmax(0, 1fr) auto auto;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        height: min(100%, calc(var(--available-height, 100vh) - 0.5rem));
        overflow: hidden;
        box-sizing: border-box;
    }

    .htk-header { display: none; }
    .htk-status { display: flex; }
    .htk-log { display: block; }
    .htk-log-list { min-height: 96px; max-height: 96px; }

    .htk-display { min-height: 0; overflow: visible; }
    .htk-lane-num { font-size: clamp(4rem, 8vh, 7rem); }
    .htk-athlete-num { font-size: clamp(3.5rem, 12vh, 6.5rem); }
    .htk-timer { font-size: clamp(1.5rem, 4vh, 2.5rem); }

    .htk-pos-btn { min-height: 80px; font-size: 1.1rem; }
    .htk-pos-svg-v { height: clamp(36px, 6vh, 56px); }
    .htk-pos-svg-h { height: clamp(24px, 4vh, 36px); }

    .htk-numpad { display: flex; flex-direction: column; gap: 8px; height: 100%; min-height: 0; }
    .htk-num-row { display: flex; gap: 8px; flex: 1; min-height: 0; }
    .htk-start-row { flex: 0 0 auto; min-height: clamp(54px, 9vh, 76px); }
    .htk-start-row .htk-btn {
        flex: 1; flex-direction: row; gap: 10px;
        height: 100%; font-size: clamp(0.9rem, 2vh, 1.1rem); border-radius: 12px;
        padding: 0.4rem 1rem; box-shadow: 0 3px 0 #14532d;
    }
    .htk-start-row .htk-btn .htk-btn-icon { font-size: clamp(1.4rem, 3vh, 2rem); }
    .htk-num { flex: 1; height: 100%; width: auto; min-height: 0; font-size: clamp(1.6rem, 4.5vh, 2.8rem); }
    .htk-bottom-row { flex: 0 0 auto; min-height: clamp(54px, 9vh, 76px); }
    .htk-bottom-row .htk-btn {
        flex: 1; height: 100%; flex-direction: column;
        gap: 3px; font-size: clamp(0.65rem, 1.5vh, 0.85rem); border-radius: 12px; padding: 0.2rem;
    }
    .htk-bottom-row .htk-btn .htk-btn-icon { font-size: clamp(1.1rem, 2.8vh, 1.6rem); }
    .htk-bottom-row .htk-num { flex: 1; height: 100%; min-height: 0; }
    .htk-actions { display: flex; gap: 8px; }
    .htk-actions .htk-btn {
        flex: 1; flex-direction: row; gap: 10px;
        min-height: clamp(54px, 9vh, 76px); font-size: clamp(0.9rem, 2vh, 1.1rem); border-radius: 12px;
        padding: 0.4rem 1rem; box-shadow: 0 3px 0 #991b1b;
    }
    .htk-actions .htk-btn .htk-btn-icon { font-size: clamp(1.4rem, 3vh, 2rem); }
    .htk-btn-clear { box-shadow: 0 3px 0 #b45309; }
    .htk-btn-enter { box-shadow: 0 3px 0 #1e40af; }
}

/* == Dark mode ============================================ */
body.dark-mode .htk-status.inactive {
    background: rgba(220, 38, 38, 0.15);
    color: #ef4444;
    border-color: rgba(220, 38, 38, 0.4);
}
body.dark-mode .htk-status.active {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.4);
}

body.dark-mode .htk-num {
    background: var(--bg-secondary);
    border-color: var(--border-color);
    box-shadow: none;
    color: var(--text-primary);
}
body.dark-mode .htk-num:hover {
    background: var(--bg-primary);
    border-color: var(--primary-color);
    box-shadow: none;
}
body.dark-mode .htk-num:active {
    background: var(--bg-primary);
    box-shadow: none;
}

