:root {
    --bg: #0b0e14;
    --card-bg: #161b22;
    --text: #f0f6fc;
    --text-dim: #8b949e;
    --border: #30363d;
    
    --key-bg: #30363d;
    --tile-empty: #0b0e14;
    
    --correct: #238636;
    --present: #d29922;
    --absent: #30363d;
    
    --accent: #58a6ff;

    --word-length: 5; /* Default fallback */
}

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

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    touch-action: manipulation;
}

/* Header */
.app-header {
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #58a6ff, #bc8cff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: color 0.2s, transform 0.2s;
}

.icon-btn:hover {
    color: var(--text);
    transform: scale(1.1);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
}

/* Game Board */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 10px;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    overflow: hidden;
}

.board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: clamp(4px, 1vh, 8px);
    width: 100%;
    height: auto;
    aspect-ratio: var(--word-length) / 6;
    max-height: 60vh;
    max-width: min(100%, calc(60vh * (var(--word-length) / 6)));
}

.row {
    display: grid;
    grid-template-columns: repeat(var(--word-length), 1fr);
    gap: clamp(2px, 1vw, 6px);
    width: 100%;
    height: 100%;
}

.tile {
    width: 100%;
    aspect-ratio: 1/1;
    border: 2px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(0.9rem, calc(2.5vw + 0.5rem), 2rem);
    font-weight: 800;
    text-transform: uppercase;
    border-radius: 4px;
    transition: all 0.1s ease;
    user-select: none;
}

.tile[data-state="tbd"] {
    border-color: var(--text-dim);
    transform: scale(1.05);
}

.tile[data-state="correct"] { background-color: var(--correct); border-color: var(--correct); }
.tile[data-state="present"] { background-color: var(--present); border-color: var(--present); }
.tile[data-state="absent"] { background-color: var(--absent); border-color: var(--absent); }

/* Keyboard */
.app-keyboard {
    padding: 8px;
    background-color: var(--bg);
    flex-shrink: 0;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 500px;
    margin: 0 auto;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.key {
    flex: 1;
    height: clamp(45px, 7vh, 58px);
    background-color: var(--key-bg);
    color: var(--text);
    border: none;
    border-radius: 4px;
    font-size: clamp(0.7rem, 2.5vw, 1.1rem);
    font-weight: 600;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    text-transform: uppercase;
    min-width: 0;
}

.key.wide {
    flex: 1.5;
    font-size: 0.85rem;
}

.key:active {
    opacity: 0.6;
}

.key[data-state="correct"] { background-color: var(--correct); }
.key[data-state="present"] { background-color: var(--present); }
.key[data-state="absent"] { background-color: var(--absent); opacity: 0.4; }

/* Modals */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 10px;
}

.card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    position: relative;
    border: 1px solid var(--border);
    text-align: center;
    max-height: 90vh;
    overflow-y: auto;
}

.hidden { display: none !important; }

.close-icon {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
}

/* Stats */
.stats-grid {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-item span { font-size: 1.5rem; font-weight: 800; }
.stat-item label { font-size: 0.75rem; color: var(--text-dim); }

.reveal-box {
    background: #1c2128;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.reveal-box h3 { color: var(--accent); font-size: 1.8rem; margin-top: 5px; }

.definition-box {
    text-align: left;
    background: rgba(88, 166, 255, 0.1);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.definition-box h4 { color: var(--accent); margin-bottom: 5px; font-size: 0.9rem; text-transform: uppercase; }
.definition-box p { font-size: 0.95rem; line-height: 1.4; color: var(--text); }

.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 800;
    z-index: 200;
}

/* Help Modal Specifics */
.help-card {
    text-align: left;
    max-width: 450px;
}

.help-card h2 {
    text-align: center;
    margin-bottom: 20px;
}

.help-card p {
    margin-bottom: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
}

.help-card ul {
    margin-left: 20px;
    margin-bottom: 20px;
}

.help-card li {
    margin-bottom: 8px;
    color: var(--text-dim);
    list-style-position: outside;
}

.example {
    margin: 20px 0;
    padding: 15px 0;
    border-top: 1px solid var(--border);
}

.ex-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.ex-tile {
    width: clamp(30px, 8vw, 45px);
    height: clamp(30px, 8vw, 45px);
    border: 2px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    font-size: clamp(0.8rem, 3vw, 1.3rem);
    border-radius: 4px;
}

.ex-tile.correct { background-color: var(--correct); border-color: var(--correct); }
.ex-tile.present { background-color: var(--present); border-color: var(--present); }
.ex-tile.absent { background-color: var(--absent); border-color: var(--absent); }

.key:hover {
    background-color: #444c56;
}

@media (max-width: 400px) {
    .app-header h1 { font-size: 1.4rem; }
    .app-header { height: 44px; }
    .game-container { padding: 5px; }
    .app-keyboard { padding: 4px; }
    .keyboard { gap: 4px; }
    .kb-row { gap: 2px; }
    .key { height: 46px; border-radius: 3px; }
}

@media (max-height: 700px) {
    .app-header { height: 40px; }
    .app-header h1 { font-size: 1.2rem; }
    .key { height: 42px; }
    .board { gap: 4px; }
    .game-container { padding: 4px; }
}

@media (max-width: 350px) {
    .key { font-size: 0.65rem; height: 40px; }
    .tile { border-width: 1px; }
}
