:root {
    --bg-color: #121213; --text-color: #ffffff; --empty-bg: #121213;
    --empty-border: #3a3a3c; --filled-border: #878a8c; --submitted-bg: #3a3a3c; 
    --submitted-border: #3a3a3c; --accent-green: #538d4e; --accent-yellow: #b59f3b;
    --key-bg: #818384; --key-bg-active: #565758; --modal-bg: #1a1a1b;

    --tile-size: clamp(32px, min(12vw, 5vh), 60px);
    --tile-font: clamp(1.4rem, min(6vw, 3vh), 2.5rem);
    --key-height: clamp(40px, min(7vh, 50px), 60px);
    --key-font: clamp(0.9rem, min(3.5vw, 2.5vh), 1.2rem);
}

body {
    background-color: var(--bg-color); color: var(--text-color);
    font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
    display: flex; flex-direction: column; align-items: center;
    margin: 0; 
    padding: clamp(5px, 1vh, 20px) 10px clamp(20px, 4vh, 40px) 10px; 
    min-height: 100vh; height: 100dvh; box-sizing: border-box;
    overflow-y: auto; overflow-x: hidden;
}

@supports not (height: 100dvh) { body { height: 100vh; } }

header {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; max-width: 450px; border-bottom: 1px solid var(--empty-border);
    padding-bottom: clamp(4px, 1vh, 8px); margin-bottom: clamp(5px, 2vh, 15px); flex-shrink: 0;
}

header h1 { 
    margin: 0; letter-spacing: 2px; text-transform: uppercase; 
    font-size: clamp(1.2rem, 3vh, 1.5rem); text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    text-align: center; flex-grow: 1; display: flex; flex-direction: column;
}

#mode-indicator { font-size: 0.7rem; color: #aaa; letter-spacing: 1px; margin-top: 2px;}

.icon-btn {
    background: none; border: none; cursor: pointer; padding: 5px;
    display: flex; align-items: center; justify-content: center; transition: opacity 0.2s;
}
.icon-btn:hover { opacity: 0.7; }
.icon-btn svg { width: clamp(20px, 3vh, 24px); height: clamp(20px, 3vh, 24px); fill: var(--text-color); }

#game-board {
    display: flex; flex-direction: column; gap: clamp(4px, 1vh, 6px); 
    margin-bottom: clamp(5px, 2vh, 15px); align-items: center;
}

.row { display: flex; gap: clamp(4px, 1vh, 6px); align-items: center; position: relative; justify-content: center; }

.tile {
    width: var(--tile-size); height: var(--tile-size); 
    border: 2px solid var(--empty-border); border-radius: clamp(4px, 1vh, 8px); 
    display: flex; justify-content: center; align-items: center;
    font-size: var(--tile-font); font-weight: bold; box-sizing: border-box;
    background-color: var(--empty-bg); transform-style: preserve-3d;
}
.tile.filled { border-color: var(--filled-border); animation: popIn 0.15s ease-in-out; }
.tile.submitted { background-color: var(--submitted-bg); border-color: var(--submitted-border); color: #ffffff; }

.feedback {
    width: auto; 
    font-size: clamp(0.6rem, 1.2vh, 0.75rem);
    position: absolute; left: calc(100% + clamp(4px, 1vw, 8px)); 
    top: 50%; transform: translateY(-50%); display: flex; flex-direction: column;
    gap: clamp(2px, 0.5vh, 4px); opacity: 0; transition: opacity 0.4s ease-in-out;
}
.feedback.visible { opacity: 1; }

.badge {
    padding: clamp(2px, 0.5vh, 4px) clamp(4px, 1vw, 6px); border-radius: 4px;
    font-weight: bold; color: white; text-shadow: 0 1px 1px rgba(0,0,0,0.3);
    display: flex; justify-content: space-between; gap: 5px;
    white-space: nowrap; 
    line-height: 1.2;
}
.badge.green { background-color: var(--accent-green); }
.badge.yellow { background-color: var(--accent-yellow); }

#keyboard { 
    display: flex; flex-direction: column; gap: clamp(4px, 1vh, 6px); 
    align-items: center; width: 100%; max-width: 500px; 
    margin-top: auto; 
    padding-bottom: env(safe-area-inset-bottom, 15px); 
}
.key-row { display: flex; gap: clamp(4px, 1vw, 6px); width: 100%; justify-content: center;}

button.key {
    background-color: var(--key-bg); color: white; border: none;
    border-radius: clamp(4px, 1vh, 6px); padding: 0; height: var(--key-height);
    font-size: var(--key-font); font-weight: bold; cursor: pointer; flex: 1; max-width: 65px;
    box-shadow: 0 4px 0 rgba(0,0,0,0.3); transition: all 0.1s;
}
button.key:active { transform: translateY(4px); box-shadow: 0 0 0 rgba(0,0,0,0.3); background-color: var(--key-bg-active); }
button.wide { max-width: 110px; font-size: calc(var(--key-font) * 0.85);}

button.key.disabled {
    background-color: #222; color: #555; box-shadow: 0 2px 0 rgba(0,0,0,0.3);
    transform: translateY(2px); pointer-events: none;
}

#message {
    height: clamp(25px, 4vh, 35px); font-weight: bold; margin-bottom: clamp(4px, 1vh, 8px);
    color: #ff4a4a; font-size: clamp(0.8rem, 2vh, 0.95rem); text-align: center;
    background: rgba(255, 74, 74, 0.1); padding: 2px 15px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; opacity: 0;
    transition: opacity 0.3s; flex-shrink: 0;
}
#message.show { opacity: 1; }

/* MODALE */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); display: flex; justify-content: center;
    align-items: center; z-index: 100; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal-content {
    background-color: var(--modal-bg); padding: 25px 20px 20px 20px;
    border-radius: 8px; width: 90%; max-width: 320px; text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5); border: 1px solid var(--empty-border); position: relative;
}
.close-btn {
    position: absolute; top: 10px; right: 15px; background: none; border: none;
    color: #878a8c; font-size: 1.5rem; font-weight: bold; cursor: pointer; padding: 0; line-height: 1;
}
.close-btn:hover { color: white; }

.setting-group { margin-bottom: 20px; text-align: left; }
.setting-group label { display: block; font-weight: bold; margin-bottom: 8px; font-size: 0.9rem; color: #ccc;}
.setting-options { display: flex; gap: 10px; }
.setting-btn {
    flex: 1; padding: 10px; background: var(--empty-bg); border: 2px solid var(--empty-border);
    color: white; border-radius: 6px; cursor: pointer; font-weight: bold;
}
.setting-btn.active { background: var(--accent-green); border-color: var(--accent-green); }
.setting-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.action-btn {
    background-color: var(--accent-green); color: white; border: none; padding: 12px 20px;
    border-radius: 6px; font-size: 1.1rem; font-weight: bold; cursor: pointer; width: 100%; margin-top: 10px;
}
.action-btn:hover { background-color: #43703e; }

.stats-tabs { display: flex; margin-bottom: 15px; border-bottom: 1px solid var(--empty-border); }
.tab-btn { flex: 1; background: none; border: none; color: #878a8c; padding: 10px; cursor: pointer; font-weight: bold; font-size: 0.9rem; }
.tab-btn.active { color: white; border-bottom: 2px solid var(--accent-green); }

.stats-summary { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 15px; }
.stats-summary div { display: flex; flex-direction: column; font-size: 0.75rem; min-width: 60px; text-align: center;}
.stats-summary span { font-size: 1.8rem; font-weight: bold; }

.dist-row { display: flex; align-items: center; margin-bottom: 5px; font-size: 0.9rem; }
.dist-row .attempt-num { width: 20px; text-align: right; padding-right: 5px;}
.dist-row .bar-container { flex-grow: 1; background-color: var(--empty-bg); height: 20px; border-radius: 3px; overflow: hidden; display: flex; justify-content: flex-end;}
.dist-row .bar { background-color: var(--empty-border); height: 100%; display: flex; align-items: center; justify-content: flex-end; padding-right: 5px; font-weight: bold; font-size: 0.8rem; min-width: 15px;}
.dist-row.current .bar { background-color: var(--accent-green); }

@keyframes popIn { 0% { transform: scale(0.8); } 40% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.shake { animation: shake 0.4s; }
@keyframes flipIn { 0% { transform: rotateX(0); } 50% { transform: rotateX(-90deg); } 100% { transform: rotateX(0); } }
.flip { animation: flipIn 0.5s ease-in; }