body {
    background-color: #1a1a1a;
    color: white;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

.header-title { 
    text-align: center; 
    margin-bottom: 20px; 
}

.header-title h2 { 
    margin: 0; 
    font-size: 26px; 
}

.main-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 20px;
    position: relative;
}

/* PANNELLO ARCHIVIO SUL LATO SINISTRO */
.archive-panel-left {
    width: 260px;
    height: 798px;
    background-color: #2b2825;
    border: 2px solid #2563eb;
    border-radius: 8px;
    padding: 10px;
    display: none;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    gap: 8px;
}

.archive-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #444;
    padding-bottom: 6px;
}

.archive-title { 
    font-size: 13px; 
    font-weight: bold; 
    color: #60a5fa; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
}

.btn-close-archive { 
    background: transparent; 
    border: none; 
    color: #888; 
    cursor: pointer; 
    font-size: 16px; 
    font-weight: bold; 
}

.btn-close-archive:hover { 
    color: #fff; 
}

.archive-tabs { 
    display: flex; 
    gap: 4px; 
}

.archive-tab {
    flex: 1;
    padding: 6px 2px;
    font-size: 11px;
    font-weight: bold;
    background: #383431;
    color: #ccc;
    border: 1px solid #555;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    text-transform: uppercase;
}

.archive-tab-active { 
    background: #2563eb; 
    color: #fff; 
    border-color: #3b82f6; 
}

.archive-items-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 4px;
}

.archive-item-card {
    background-color: #332f2c;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 8px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.archive-item-card:hover { 
    background-color: #3c3734; 
    border-color: #60a5fa; 
}

.archive-item-title { 
    font-size: 12px; 
    font-weight: bold; 
    color: #facc15; 
}

.archive-item-desc { 
    font-size: 11px; 
    color: #bbb; 
    margin-top: 4px; 
    line-height: 1.3; 
}

.archive-item-actions { 
    display: flex; 
    gap: 4px; 
    margin-top: 6px; 
}

.archive-btn-action {
    flex: 1;
    padding: 5px 0;
    font-size: 11px;
    font-weight: bold;
    border-radius: 3px;
    border: 1px solid #666;
    background: #2b2825;
    color: #fff;
    cursor: pointer;
}

.archive-btn-action:hover { 
    background: #2563eb; 
    border-color: #60a5fa; 
}

.archive-user-box { 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
    border-top: 1px solid #444; 
    padding-top: 8px; 
}

.archive-input-name { 
    background: #1a1a1a; 
    border: 1px solid #555; 
    color: #fff; 
    padding: 6px; 
    font-size: 12px; 
    border-radius: 4px; 
}

.archive-btn-group { 
    display: flex; 
    gap: 4px; 
}

/* PANNELLO EDITOR SUL LATO SINISTRO */
.editor-side-panel {
    width: 150px;
    height: 798px;
    background-color: #2b2825;
    border: 2px solid #ca8a04;
    border-radius: 8px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 12px 6px;
    gap: 8px;
    box-sizing: border-box;
    overflow-y: auto;
}

.editor-subgroup-title {
    font-size: 11px;
    color: #facc15;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: bold;
    width: 100%;
    text-align: center;
    border-bottom: 1px solid #444;
    padding-bottom: 4px;
}

/* PANCHINA PEZZI CATTURATI A DESTRA */
.bench-dual-container {
    width: 150px;
    height: 798px;
    background-color: #2b2825;
    border: 2px dashed #555;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
}

.bench-half {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 10px 4px;
    gap: 6px;
    overflow-y: auto;
    box-sizing: border-box;
}

.bench-divider {
    height: 2px;
    background-color: #444;
    width: 90%;
    margin: 0 auto;
}

.bench-header { 
    width: 100%; 
    text-align: center; 
    margin-bottom: 4px; 
}

.bench-title { 
    font-size: 11px; 
    color: #aaa; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
    line-height: 1.2; 
}

.advantage-badge { 
    font-size: 20px; 
    font-weight: bold; 
    color: #7b9652; 
    min-height: 22px; 
}

.bench-items { 
    display: flex; 
    flex-wrap: wrap; 
    justify-content: center; 
    gap: 6px; 
    width: 100%; 
}

.bench-item { 
    width: 48px; 
    height: 48px; 
    font-size: 38px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    border-radius: 6px; 
    background-color: #383431; 
    user-select: none; 
    cursor: default; 
}

.bench-item-selectable { 
    cursor: pointer; 
    transition: transform 0.1s, border-color 0.2s; 
    border: 2px solid transparent; 
}

.bench-item-selectable:hover { 
    background-color: #4a4541; 
    transform: scale(1.08); 
}

.bench-item-selected { 
    border-color: #facc15 !important; 
    background-color: #44403c !important; 
}

.btn-editor-active { 
    background-color: #ca8a04 !important; 
    border-color: #facc15 !important; 
    color: white !important; 
}

.btn-archive-active { 
    background-color: #2563eb !important; 
    border-color: #60a5fa !important; 
    color: white !important; 
}

/* ANIMAZIONE PULSANTE AVANTI PER STUDI */
.btn-pulse-attention {
    background-color: #ca8a04 !important;
    border-color: #facc15 !important;
    color: #ffffff !important;
    box-shadow: 0 0 12px rgba(250, 204, 21, 0.8) !important;
    animation: pulse-btn 1.2s infinite ease-in-out;
}

@keyframes pulse-btn {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* SCACCHIERA */
.board-container {
    display: grid;
    grid-template-columns: 35px repeat(8, 88px) 35px;
    grid-template-rows: 35px repeat(8, 88px) 35px;
    background-color: #262421;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    user-select: none;
}

.coord { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-weight: bold; 
    font-size: 24px; 
    color: #ffffff; 
}

.square { 
    width: 88px; 
    height: 88px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 64px; 
    cursor: pointer; 
    position: relative; 
    box-sizing: border-box; 
}

.light { background-color: #f0d9b5; }
.dark { background-color: #b58863; }
.selected { background-color: #7b9652 !important; }
.in-check { background-color: #cc3333 !important; }
.hint-source { background-color: #3b82f6 !important; }
.hint-target { background-color: #60a5fa !important; }

.last-move-highlight {
    box-shadow: inset 0 0 0 4px #facc15 !important;
}

.legal-dot { 
    width: 26px; 
    height: 26px; 
    background-color: rgba(0, 0, 0, 0.25); 
    border-radius: 50%; 
    position: absolute; 
    pointer-events: none; 
}

.legal-capture { 
    width: 78px; 
    height: 78px; 
    border: 5px solid rgba(0, 0, 0, 0.25); 
    border-radius: 50%; 
    position: absolute; 
    pointer-events: none; 
}

.piece-white { 
    color: #ffffff; 
    text-shadow: 0 0 3px #000, 0 0 5px #000; 
    z-index: 2; 
}

.piece-black { 
    color: #111111; 
    text-shadow: 0 0 2px #fff; 
    z-index: 2; 
}

/* RENDERING IMMAGINI PNG PEZZI PERSONALIZZATI */
.piece-img {
    width: 82%;
    height: 82%;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    display: block;
    margin: auto;
}

.bench-item .piece-img {
    width: 85%;
    height: 85%;
}

/* PANNELLO COMANDI LATERALE DESTRO */
.side-panel { 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
    width: 260px; 
    height: 798px; 
    position: relative; 
}

.time-picker-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.digits-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.digit-btn {
    width: 40px;
    height: 46px;
    background-color: #383431;
    border: 2px solid #7b9652;
    color: #7b9652;
    font-size: 24px;
    font-weight: bold;
    font-family: monospace;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s, background-color 0.2s;
}

/* Riquadro per il livello (più largo per ospitare numeri a due cifre) */
.digit-btn-wide {
    width: 58px;
    border-color: #ca8a04;
    color: #facc15;
}

.digit-btn:hover { 
    background-color: #4a4541; 
    transform: scale(1.05); 
}

.digit-btn:active { 
    transform: scale(0.95); 
}

.unit-label { 
    font-size: 12px; 
    font-weight: bold; 
    color: #aaa; 
    margin-left: 2px; 
}

.category-badge {
    font-size: 11px;
    font-weight: bold;
    color: #facc15;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.clocks-container { 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
}

.clocks-row { 
    display: flex; 
    gap: 10px; 
    justify-content: space-between; 
}

.clock-box {
    flex: 1;
    background-color: #2b2825;
    border: 2px solid #444;
    border-radius: 6px;
    padding: 8px 4px;
    text-align: center;
    transition: border-color 0.2s, background-color 0.2s;
}

.clock-title { 
    font-size: 11px; 
    color: #aaa; 
    text-transform: uppercase; 
    margin-bottom: 2px; 
}

.clock-time { 
    font-size: 24px; 
    font-weight: bold; 
    font-family: monospace; 
    color: #fff; 
}

.clock-active { 
    border-color: #7b9652 !important; 
    background-color: #383431; 
}

.clock-active .clock-time { 
    color: #7b9652; 
}

.clock-danger .clock-time { 
    color: #ef4444 !important; 
}

.btn-start-game {
    background-color: #15803d;
    color: white;
    border: 2px solid #22c55e;
    padding: 10px 0;
    font-size: 14px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: background-color 0.2s, border-color 0.2s;
}

.btn-start-game:hover { 
    background-color: #16a34a; 
}

.btn-pause-active { 
    background-color: #b45309 !important; 
    border-color: #f59e0b !important; 
}

.btn-game-ended {
    background-color: #2563eb !important;
    border-color: #3b82f6 !important;
}

.btn-game-ended:hover {
    background-color: #1d4ed8 !important;
}

/* GRIGLIA PULSANTI LATERALE (LARGHEZZA PIENA) */
.controls-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.controls-row {
    display: flex;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.btn { 
    flex: 1 1 0; 
    min-width: 0; 
    background-color: #383431; 
    color: white; 
    border: 2px solid #555; 
    padding: 10px 0; 
    font-size: 20px; 
    font-weight: bold; 
    border-radius: 6px; 
    cursor: pointer; 
    transition: background-color 0.2s, border-color 0.2s, transform 0.05s; 
    user-select: none; 
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px; 
    box-sizing: border-box;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.btn:hover:not(:disabled) { 
    background-color: #7b9652; 
    border-color: #7b9652; 
}

.btn:disabled { 
    opacity: 0.4; 
    cursor: not-allowed; 
}

.btn-resign { 
    background-color: #4a2222; 
    border-color: #663333; 
}

.btn-resign:hover:not(:disabled) { 
    background-color: #8b0000; 
    border-color: #aa0000; 
}

.btn-hint-active { 
    background-color: #15803d !important; 
    border-color: #22c55e !important; 
}

.moves-panel { 
    flex: 1; 
    background-color: #2b2825; 
    border: 2px dashed #555; 
    border-radius: 8px; 
    padding: 10px; 
    display: flex; 
    flex-direction: column; 
    box-sizing: border-box; 
    overflow: hidden; 
}

.moves-title { 
    font-size: 11px; 
    color: #aaa; 
    text-transform: uppercase; 
    letter-spacing: 0.5px; 
    text-align: center; 
    margin-bottom: 8px; 
    border-bottom: 1px solid #444; 
    padding-bottom: 4px; 
}

.moves-list { 
    flex: 1; 
    overflow-y: auto; 
    font-family: monospace; 
    font-size: 13px; 
    line-height: 1.5; 
    color: #ddd; 
    padding-right: 5px; 
}

.move-row { 
    display: flex; 
    justify-content: space-between; 
    padding: 2px 4px; 
    border-radius: 3px; 
}

.move-row:nth-child(even) { 
    background-color: #332f2c; 
}

.move-num { 
    color: #888; 
    width: 28px; 
}

.move-white, .move-black { 
    flex: 1; 
    cursor: pointer; 
}

.active-move { 
    color: #7b9652; 
    font-weight: bold; 
}

.game-result-banner { 
    margin-top: 8px; 
    padding: 6px; 
    background-color: #383431; 
    border-radius: 4px; 
    text-align: center; 
    font-weight: bold; 
    font-size: 12px; 
    color: #facc15; 
    border: 1px solid #666; 
}

.engine-box { 
    background-color: #2b2825; 
    border: 1px solid #444; 
    border-radius: 6px; 
    padding: 10px; 
    display: flex; 
    flex-direction: column; 
    gap: 6px; 
    font-size: 12px; 
}

.engine-box select { 
    background: #383431; 
    color: white; 
    border: 1px solid #555; 
    padding: 4px; 
    border-radius: 4px; 
}

.footer-credits { 
    margin-top: 20px; 
    font-size: 12px; 
    color: #777; 
    text-align: center; 
    letter-spacing: 0.5px; 
}

/* RESPONSIVE */
@media (max-width: 1450px) {
    .main-layout { flex-wrap: wrap; }
    .side-panel { width: 520px; height: auto; }
    .bench-dual-container, .editor-side-panel, .archive-panel-left { height: 798px; }
}

@media (max-width: 950px) {
    body { padding: 10px; justify-content: flex-start; }
    .header-title h2 { font-size: 22px; }
    .main-layout { width: 100%; gap: 10px; }
    .board-container {
        grid-template-columns: 24px repeat(8, minmax(36px, 8.5vw)) 24px;
        grid-template-rows: 24px repeat(8, minmax(36px, 8.5vw)) 24px;
        padding: 6px;
    }
    .square { width: min(8.5vw, 70px); height: min(8.5vw, 70px); font-size: min(6.5vw, 50px); }
    .coord { font-size: min(3vw, 18px); }
    .bench-dual-container, .editor-side-panel, .archive-panel-left { width: 110px; height: 340px; }
    .side-panel { width: min(100%, 520px); }
}

@media (max-width: 600px) {
    .bench-dual-container { width: 100%; height: auto; min-height: 120px; order: 2; flex-direction: row; }
    .bench-half { width: 50%; height: auto; }
    .bench-divider { width: 2px; height: 90%; }
    .editor-side-panel, .archive-panel-left { width: 100%; height: auto; order: 2; }
    #board { order: 1; }
    .side-panel { order: 3; }
    .main-layout { flex-direction: column; align-items: center; }
    .board-container {
        grid-template-columns: 20px repeat(8, minmax(30px, 10vw)) 20px;
        grid-template-rows: 20px repeat(8, minmax(30px, 10vw)) 20px;
    }
    .square { width: min(10vw, 58px); height: min(10vw, 58px); font-size: min(8vw, 42px); }
}