/* ==============================
   TERMO - CSS Principal
   ============================== */

:root {
    --color-bg: #121213;
    --color-surface: #1a1a1b;
    --color-border: #3a3a3c;
    --color-text: #ffffff;
    --color-text-muted: #818384;
    --color-correct: #538d4e;
    --color-present: #b59f3b;
    --color-absent: #3a3a3c;
    --color-key-bg: #818384;
    --color-key-text: #ffffff;
    --color-tile-empty: #121213;
    --color-tile-border: #3a3a3c;
    --color-tile-filled: #121213;
    --color-tile-filled-border: #565758;
    --color-header-bg: #1a1a1b;
    --color-modal-bg: #1a1a1b;
    --color-toast-bg: #ffffff;
    --color-toast-text: #000000;
    --tile-size: 62px;
    --tile-gap: 5px;
    --font-main: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
}

[data-theme="light"] {
    --color-bg: #ffffff;
    --color-surface: #f9f9f9;
    --color-border: #d3d6da;
    --color-text: #1a1a1b;
    --color-text-muted: #787c7e;
    --color-absent: #787c7e;
    --color-key-bg: #d3d6da;
    --color-key-text: #1a1a1b;
    --color-tile-empty: #ffffff;
    --color-tile-border: #d3d6da;
    --color-tile-filled: #ffffff;
    --color-tile-filled-border: #878a8c;
    --color-header-bg: #ffffff;
    --color-modal-bg: #ffffff;
    --color-toast-bg: #000000;
    --color-toast-text: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background-color 0.3s, color 0.3s;
    user-select: none;
}

/* ==============================
   HEADER
   ============================== */
#header {
    width: 100%;
    max-width: 500px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
    padding: 0 16px;
    flex-shrink: 0;
}

.header-left, .header-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-btn {
    background: none;
    border: none;
    color: var(--color-text);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.header-btn:hover {
    background: var(--color-border);
}

#game-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 4px;
    text-transform: uppercase;
    cursor: pointer;
    transition: opacity 0.2s;
}

#game-title:hover {
    opacity: 0.8;
}

/* ==============================
   MODE SELECTOR
   ============================== */
#mode-selector {
    display: flex;
    gap: 4px;
    padding: 6px 16px;
    flex-shrink: 0;
    width: 100%;
    max-width: 500px;
    justify-content: center;
    border-bottom: 1px solid var(--color-border);
}

.mode-btn {
    background: none;
    border: 2px solid var(--color-border);
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1px;
    transition: all 0.2s;
}

.mode-btn.active {
    border-color: var(--color-text);
    color: var(--color-text);
    background: var(--color-border);
}

.mode-btn:hover:not(.active) {
    border-color: var(--color-text-muted);
    color: var(--color-text);
}

/* ==============================
   GAME CONTAINER
   ============================== */
#game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 500px;
    padding: 8px 0 4px;
    overflow: hidden;
}

/* ==============================
   BOARDS WRAPPER
   ============================== */
#boards-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 0 8px;
    overflow: hidden;
}

/* Single board */
.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.board-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: var(--tile-gap);
}

/* ==============================
   TILES
   ============================== */
.tile-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--tile-gap);
}

.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    border: 2px solid var(--color-tile-border);
    background: var(--color-tile-empty);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--color-text);
    transition: border-color 0.1s;
    position: relative;
    overflow: hidden;
}

.tile.filled {
    border-color: var(--color-tile-filled-border);
    animation: pop 0.1s ease-in-out;
}

.tile.revealed-correct {
    background: var(--color-correct);
    border-color: var(--color-correct);
    color: white;
}

.tile.revealed-present {
    background: var(--color-present);
    border-color: var(--color-present);
    color: white;
}

.tile.revealed-absent {
    background: var(--color-absent);
    border-color: var(--color-absent);
    color: white;
}

.tile.current-row {
    border-color: var(--color-tile-filled-border);
}

/* Cursor piscando no tile ativo */
.tile.cursor::after {
    content: '';
    display: block;
    width: 2px;
    height: 60%;
    background: var(--color-text);
    position: absolute;
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Tile flip animation */
.tile.flip {
    animation: flip 0.5s ease forwards;
}

/* Tile shake animation */
.tile-row.shake {
    animation: shake 0.5s ease forwards;
}

/* Tile bounce animation (win) */
.tile.bounce {
    animation: bounce 0.5s ease forwards;
}

/* ==============================
   KEYBOARD
   ============================== */
#keyboard {
    width: 100%;
    max-width: 500px;
    padding: 0 8px 8px;
    flex-shrink: 0;
}

.key-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
}

.key {
    height: 58px;
    min-width: 43px;
    padding: 0 6px;
    background: var(--color-key-bg);
    border: none;
    border-radius: 4px;
    color: var(--color-key-text);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    transition: background 0.2s, transform 0.1s;
    flex: 1;
    max-width: 43px;
    font-family: var(--font-main);
    letter-spacing: 0.5px;
}

.key:active {
    transform: scale(0.95);
}

.key.wide {
    min-width: 65px;
    max-width: 65px;
    font-size: 12px;
}

.key.correct {
    background: var(--color-correct);
    color: white;
}

.key.present {
    background: var(--color-present);
    color: white;
}

.key.absent {
    background: var(--color-absent);
    color: white;
}

/* ==============================
   TOAST NOTIFICATION
   ============================== */
#toast-container {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--color-toast-bg);
    color: var(--color-toast-text);
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    animation: toastIn 0.3s ease;
    opacity: 1;
    transition: opacity 0.3s;
}

.toast.hide {
    opacity: 0;
}

/* ==============================
   MODALS
   ============================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--color-modal-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 24px;
    max-width: 460px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.3s ease;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--color-text);
}

.modal h2 {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 20px;
    color: var(--color-text);
}

/* Help Modal */
.help-section {
    margin-bottom: 20px;
}

.help-section p {
    font-size: 14px;
    color: var(--color-text-muted);
    line-height: 1.6;
    margin-bottom: 12px;
}

.example-row {
    display: flex;
    gap: 5px;
    margin-bottom: 12px;
    align-items: center;
}

.example-tile {
    width: 42px;
    height: 42px;
    border: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
}

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

.example-desc {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-left: 10px;
    line-height: 1.4;
}

.example-desc strong {
    color: var(--color-text);
}

.divider {
    height: 1px;
    background: var(--color-border);
    margin: 16px 0;
}

/* Stats Modal */
.stats-grid {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-item {
    text-align: center;
    min-width: 56px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1;
}

.stat-label {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.guess-distribution {
    margin-bottom: 20px;
}

.guess-distribution h3 {
    text-align: center;
    font-size: 13px;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 12px;
    color: var(--color-text-muted);
}

.dist-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    height: 22px;
}

.dist-num {
    font-size: 14px;
    font-weight: 700;
    width: 16px;
    text-align: right;
    color: var(--color-text);
}

.dist-bar-container {
    flex: 1;
    height: 100%;
}

.dist-bar {
    height: 100%;
    background: var(--color-absent);
    border-radius: 2px;
    min-width: 26px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    font-size: 12px;
    font-weight: 700;
    color: white;
    transition: width 0.6s ease;
}

.dist-bar.current {
    background: var(--color-correct);
}

.play-again-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 16px;
    background: var(--color-correct);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 2px;
    text-transform: uppercase;
    transition: background 0.2s;
    margin-top: 8px;
}

.play-again-btn:hover {
    background: #6aaf64;
}

.share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px;
    background: none;
    color: var(--color-text);
    border: 2px solid var(--color-border);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 2px;
    text-transform: uppercase;
    transition: all 0.2s;
    margin-top: 12px;
}

.share-btn:hover {
    border-color: var(--color-text);
    background: var(--color-border);
}

.result-word {
    text-align: center;
    font-size: 15px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

.result-word span {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: 3px;
    text-transform: uppercase;
    display: block;
    margin-top: 4px;
}

/* Settings Modal */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--color-border);
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-label {
    font-size: 14px;
    color: var(--color-text);
    font-weight: 500;
}

.settings-desc {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--color-border);
    border-radius: 28px;
    transition: 0.4s;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    border-radius: 50%;
    transition: 0.4s;
}

.toggle input:checked + .toggle-slider {
    background-color: var(--color-correct);
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

/* ==============================
   GAME OVER OVERLAY
   ============================== */
#game-over-modal .answer-reveal {
    text-align: center;
    padding: 16px 0;
}

#game-over-modal .answer-reveal .answer-label {
    font-size: 13px;
    color: var(--color-text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
}

#game-over-modal .answer-reveal .answer-word {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 8px;
    color: var(--color-text);
    text-transform: uppercase;
    margin-top: 8px;
}

/* ==============================
   LOADING STATE
   ============================== */
.board-solved .board {
    opacity: 0.7;
}

.board-solved .board-label {
    color: var(--color-correct);
}

.board-solved .board-label::after {
    content: " ✓";
}

/* ==============================
   ANIMATIONS
   ============================== */
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(-90deg); }
    100% { transform: rotateX(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 50%, 90% { transform: translateX(-4px); }
    30%, 70% { transform: translateX(4px); }
}

@keyframes bounce {
    0%, 20% { transform: translateY(0); }
    40% { transform: translateY(-20px); }
    60% { transform: translateY(-10px); }
    80% { transform: translateY(-4px); }
    100% { transform: translateY(0); }
}

@keyframes toastIn {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ==============================
   RESPONSIVE
   ============================== */

/* Dueto: 2 boards side by side */
body.mode-dueto #game-container,
body.mode-quarteto #game-container {
    max-width: 100%;
}

body.mode-dueto #boards-wrapper {
    max-width: 780px;
}

body.mode-quarteto #boards-wrapper {
    max-width: 1060px;
    flex-wrap: wrap;
    gap: 8px;
}

body.mode-quarteto .board-container {
    min-width: 220px;
}

/* Dueto tile size */
body.mode-dueto {
    --tile-size: 54px;
}

/* Quarteto tile size */
body.mode-quarteto {
    --tile-size: 46px;
    --tile-gap: 4px;
}

body.mode-quarteto .tile {
    font-size: 1.6rem;
}

body.mode-quarteto .key {
    height: 50px;
    min-width: 36px;
    max-width: 36px;
    font-size: 12px;
    gap: 4px;
}

body.mode-quarteto .key.wide {
    min-width: 54px;
    max-width: 54px;
}

body.mode-dueto .key, 
body.mode-dueto #keyboard,
body.mode-quarteto #keyboard {
    max-width: 100%;
}

@media (max-width: 600px) {
    :root {
        --tile-size: 52px;
    }

    body.mode-dueto {
        --tile-size: 40px;
        --tile-gap: 4px;
    }

    body.mode-dueto .tile {
        font-size: 1.4rem;
    }

    body.mode-quarteto {
        --tile-size: 32px;
        --tile-gap: 3px;
    }

    body.mode-quarteto .tile {
        font-size: 1.1rem;
    }

    .key {
        height: 50px;
        min-width: 32px;
        max-width: 32px;
        font-size: 12px;
    }

    .key.wide {
        min-width: 50px;
        max-width: 50px;
        font-size: 11px;
    }

    .key-row {
        gap: 4px;
    }

    #game-title {
        font-size: 22px;
        letter-spacing: 3px;
    }

    body.mode-quarteto .key {
        height: 44px;
        min-width: 28px;
        max-width: 28px;
        font-size: 11px;
    }

    body.mode-quarteto .key.wide {
        min-width: 46px;
        max-width: 46px;
    }

    body.mode-quarteto #boards-wrapper {
        gap: 6px;
    }
}

@media (max-width: 380px) {
    :root { --tile-size: 46px; }
    body.mode-dueto { --tile-size: 36px; }
    body.mode-quarteto { --tile-size: 28px; }

    .key {
        min-width: 28px;
        max-width: 28px;
        font-size: 11px;
        height: 46px;
    }

    .key.wide {
        min-width: 46px;
        max-width: 46px;
    }
}

/* Scrollable body for small heights */
@media (max-height: 700px) {
    html, body { overflow: auto; }

    :root { --tile-size: 48px; }
    body.mode-dueto { --tile-size: 40px; }
    body.mode-quarteto { --tile-size: 34px; }

    .tile {
        font-size: 1.5rem;
    }

    .key {
        height: 46px;
    }

    #game-container {
        overflow: visible;
    }
}
