/* ===== BASE ===== */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Fredoka', sans-serif;
    background: #3b0f70;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 540px;
    margin: 0 auto;
    background: linear-gradient(180deg, #5b21b6 0%, #3b0f70 100%);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ===== UTILITIES ===== */
.hidden {
    display: none !important;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px;
}

.screen.active {
    display: flex;
}

.container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

.container.center {
    justify-content: center;
    align-items: center;
    text-align: center;
    min-height: 100%;
    padding-bottom: 40px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 16px;
    font-family: inherit;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 16px 24px;
    cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

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

.btn-primary {
    background: #22c55e;
    box-shadow: 0 6px 0 #16a34a, 0 8px 16px rgba(0,0,0,0.25);
}

.btn-primary:hover {
    background: #2dd55a;
}

.btn-primary:active {
    box-shadow: 0 2px 0 #16a34a, 0 4px 8px rgba(0,0,0,0.2);
    transform: translateY(4px) scale(0.98);
}

.btn-secondary {
    background: rgba(255,255,255,0.15);
    box-shadow: 0 4px 0 rgba(255,255,255,0.08), 0 6px 12px rgba(0,0,0,0.15);
    border: 2px solid rgba(255,255,255,0.25);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.25);
}

.btn-large {
    font-size: 1.4rem;
    padding: 20px 40px;
    margin-top: 24px;
}

.btn-back {
    align-self: flex-start;
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.2);
    padding: 10px 18px;
    font-size: 1rem;
    margin-bottom: 16px;
    border-radius: 50px;
}

.btn-icon {
    background: transparent;
    font-size: 1.5rem;
    padding: 8px;
    border-radius: 50%;
}

.btn-check {
    width: 100%;
    background: #f59e0b;
    box-shadow: 0 6px 0 #d97706, 0 8px 16px rgba(0,0,0,0.2);
    margin-top: 16px;
}

.btn-check:active {
    box-shadow: 0 2px 0 #d97706, 0 4px 8px rgba(0,0,0,0.15);
    transform: translateY(4px);
}

.btn-next {
    width: 100%;
    background: #22c55e;
    box-shadow: 0 6px 0 #16a34a;
    margin-top: 16px;
    font-size: 1.2rem;
}

.btn-text {
    background: transparent;
    color: rgba(255,255,255,0.8);
    font-size: 0.95rem;
    padding: 10px;
    text-decoration: underline;
    text-shadow: none;
}

/* ===== START SCREEN ===== */
.logo-grammar {
    font-size: 4.5rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 8px;
    text-shadow: 0 4px 12px rgba(0,0,0,0.35);
    color: #fbbf24;
}

.main-title {
    font-size: 2.2rem;
    font-weight: 700;
    margin: 0 0 8px;
    text-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.sub-title {
    font-size: 1.6rem;
    font-weight: 600;
    margin: 0 0 12px;
    color: #e9d5ff;
}

.mini-info {
    font-size: 1.1rem;
    color: rgba(255,255,255,0.75);
    margin: 0 0 24px;
}

/* ===== MENU SCREEN ===== */
.section-title {
    font-size: 1.8rem;
    text-align: center;
    margin: 8px 0 20px;
    text-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.card-topic {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #fff;
    color: #3b0f70;
    border: none;
    border-radius: 18px;
    padding: 22px 10px;
    font-family: inherit;
    font-weight: 700;
    font-size: 1.05rem;
    cursor: pointer;
    box-shadow: 0 6px 0 #d8b4fe, 0 8px 16px rgba(0,0,0,0.2);
    transition: transform 0.08s ease, box-shadow 0.15s ease;
}

.card-topic:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #d8b4fe, 0 4px 8px rgba(0,0,0,0.15);
}

.topic-icon {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: #7e22ce;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
}

.topic-label {
    line-height: 1.2;
}

/* ===== LEVEL SCREEN ===== */
.level-subtitle {
    font-size: 1.2rem;
    color: rgba(255,255,255,0.75);
    margin: -12px 0 24px;
}

.level-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.btn-level {
    flex-direction: column;
    padding: 28px;
    font-size: 1.4rem;
    background: #fff;
    color: #3b0f70;
    box-shadow: 0 6px 0 #d8b4fe, 0 8px 16px rgba(0,0,0,0.2);
}

.btn-level:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #d8b4fe, 0 4px 8px rgba(0,0,0,0.15);
}

.level-emoji {
    font-size: 1.8rem;
    margin-top: 6px;
}

/* ===== GRAMMAR RULES SCREEN ===== */
.rules-container {
    padding-bottom: 80px;
}

.rule-card {
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 18px;
    padding: 18px;
    margin-bottom: 16px;
}

.rule-card h3 {
    margin: 0 0 14px;
    font-size: 1.25rem;
    color: #fbbf24;
}

.rule-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rule-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255,255,255,0.08);
    border-radius: 10px;
    font-size: 1rem;
}

.rule-row.head {
    background: rgba(126, 34, 206, 0.5);
    font-weight: 700;
}

.rule-row span:first-child {
    text-align: left;
}

.rule-row span:last-child {
    text-align: right;
    font-weight: 700;
}

.rule-table.questions .rule-row {
    flex-direction: column;
    gap: 4px;
}

.rule-table.contractions .rule-row span:nth-child(2),
.rule-table.contractions .rule-row span:nth-child(3) {
    font-weight: 700;
}

.rule-example {
    margin: 12px 0 0;
    font-size: 1rem;
    color: #e9d5ff;
    text-align: center;
}

.rule-note {
    margin: 8px 0 0;
    font-size: 0.95rem;
    color: #fca5a5;
    text-align: center;
}

.rule-tip {
    margin: 0 0 14px;
    font-size: 1.05rem;
    color: #e9d5ff;
}

.rule-list {
    margin: 0;
    padding-left: 22px;
    font-size: 1.05rem;
    line-height: 1.8;
}

/* ===== GAME SCREEN ===== */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    flex-shrink: 0;
}

.game-meta {
    display: flex;
    gap: 8px;
    align-items: center;
}

.topic-pill, .level-pill {
    padding: 6px 14px;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.85rem;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.2);
}

.score-pill {
    padding: 8px 16px;
    border-radius: 50px;
    background: rgba(255,255,255,0.15);
    font-weight: 700;
}

.game-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

#btn-game-stop {
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
    box-shadow: 0 3px 0 #b91c1c;
    padding: 0;
}

#btn-game-stop:active {
    transform: translateY(3px);
    box-shadow: 0 0 0 #b91c1c;
}

.progress-wrap {
    padding: 0 16px 12px;
    flex-shrink: 0;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: rgba(255,255,255,0.15);
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: #22c55e;
    border-radius: 5px;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: right;
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
    margin-top: 6px;
}

.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-bottom: 80px;
}

.task-card {
    background: #fff;
    color: #1f2937;
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.task-prompt {
    margin: 0 0 12px;
    font-size: 1rem;
    color: #6b7280;
    font-weight: 600;
}

.task-question {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 16px;
    color: #3b0f70;
    word-break: break-word;
}

.task-hint {
    font-size: 0.95rem;
    color: #7c3aed;
    margin-bottom: 16px;
    min-height: 20px;
}

.answer-block {
    display: none !important;
}

.answer-block.active {
    display: block !important;
}

#answer-choice.answer-block.active {
    display: grid !important;
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.option-btn {
    background: rgba(126, 34, 206, 0.1);
    border: 2px solid rgba(126, 34, 206, 0.25);
    color: #3b0f70;
    border-radius: 14px;
    padding: 16px;
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    transition: all 0.12s ease;
}

.option-btn:hover {
    background: rgba(126, 34, 206, 0.18);
}

.option-btn:active {
    transform: scale(0.98);
}

.option-btn.selected {
    background: #7e22ce;
    color: #fff;
    border-color: #7e22ce;
}

.option-btn.correct {
    background: #22c55e !important;
    border-color: #22c55e !important;
    color: #fff !important;
}

.option-btn.wrong {
    background: #ef4444 !important;
    border-color: #ef4444 !important;
    color: #fff !important;
}

.option-btn.disabled {
    opacity: 0.7;
    pointer-events: none;
}

/* Fill sentence style */
.fill-sentence {
    font-size: 1.4rem;
    font-weight: 700;
    color: #3b0f70;
    margin-bottom: 16px;
    text-align: center;
    line-height: 1.5;
}

.blank {
    display: inline-block;
    min-width: 56px;
    border-bottom: 3px solid #7e22ce;
    text-align: center;
    color: #22c55e;
    padding: 0 4px;
    margin: 0 4px;
}

/* Type input */
.type-input {
    width: 100%;
    padding: 16px;
    border: 2px solid rgba(126, 34, 206, 0.3);
    border-radius: 14px;
    font-family: inherit;
    font-size: 1.15rem;
    color: #1f2937;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
    cursor: text;
}

.type-input:focus {
    border-color: #7e22ce;
}

/* Word order */
.order-target {
    min-height: 58px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    margin-bottom: 16px;
    border: 2px dashed rgba(126, 34, 206, 0.35);
    border-radius: 14px;
    background: rgba(126, 34, 206, 0.05);
}

.order-bank {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    justify-content: center;
}

.word-tile {
    padding: 10px 16px;
    border-radius: 10px;
    background: #fff;
    color: #3b0f70;
    border: 2px solid #7e22ce;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 3px 0 #d8b4fe;
    transition: transform 0.08s ease;
}

.word-tile:active {
    transform: translateY(3px);
    box-shadow: 0 0 0 #d8b4fe;
}

.word-tile.used {
    opacity: 0.4;
    pointer-events: none;
}

/* Feedback */
.feedback {
    margin-top: 16px;
    padding: 14px;
    border-radius: 14px;
    text-align: center;
    font-weight: 700;
    display: none;
}

.feedback.show {
    display: block;
}

.feedback.correct-fb {
    background: rgba(34, 197, 94, 0.25);
    border: 2px solid rgba(34, 197, 94, 0.5);
}

.feedback.wrong-fb {
    background: rgba(239, 68, 68, 0.25);
    border: 2px solid rgba(239, 68, 68, 0.5);
}

/* ===== PAUSE MODAL ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

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

.pause-content {
    background: #fff;
    color: #3b0f70;
    border-radius: 24px;
    padding: 28px 24px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 16px 40px rgba(0,0,0,0.35);
}

.pause-content .modal-title {
    font-size: 1.8rem;
    margin: 0 0 24px;
}

.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pause-buttons .btn {
    width: 100%;
}

.pause-buttons .btn-secondary {
    background: rgba(126, 34, 206, 0.08);
    color: #3b0f70;
    border-color: rgba(126, 34, 206, 0.25);
}

.pause-buttons .btn-secondary:hover {
    background: rgba(126, 34, 206, 0.18);
}

/* ===== RESULT SCREEN ===== */
.result-icon {
    font-size: 5rem;
    margin-bottom: 16px;
}

.result-title {
    font-size: 2.4rem;
    margin: 0 0 8px;
    text-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.result-score {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0 0 8px;
}

.result-detail {
    font-size: 1.1rem;
    color: rgba(255,255,255,0.8);
    margin: 0 0 16px;
}

.result-message {
    font-size: 1.2rem;
    margin: 0 0 32px;
    color: #e9d5ff;
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

/* ===== CONFETTI CANVAS ===== */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* ===== RESPONSIVE TWEAKS ===== */
@media (max-height: 640px) {
    .logo-grammar { font-size: 3.5rem; }
    .main-title { font-size: 1.8rem; }
    .sub-title { font-size: 1.3rem; }
    .btn-large { font-size: 1.2rem; padding: 16px 32px; }
    .section-title { font-size: 1.5rem; margin-bottom: 14px; }
    .card-topic { padding: 16px 8px; }
    .task-card { padding: 18px; }
    .task-question { font-size: 1.35rem; }
}

@media (min-width: 480px) {
    #app {
        border-left: 1px solid rgba(255,255,255,0.08);
        border-right: 1px solid rgba(255,255,255,0.08);
    }

    #answer-choice.answer-block.active,
    #answer-fill .options-grid,
    .options-grid.two-col {
        grid-template-columns: 1fr 1fr;
    }
}
