/* ========== Theme toggle ========== */
.theme-toggle {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: transform 0.15s, background 0.2s;
}

.theme-toggle:active {
    transform: scale(0.9);
}

.theme-icon {
    width: 20px;
    height: 20px;
    fill: var(--tg-hint);
}

/* ========== Cards ========== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: var(--gap);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* ========== Buttons ========== */
.btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.15s;
    text-align: center;
}

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

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--tg-text);
    border: 1px solid var(--border);
}

.btn-ghost {
    background: transparent;
    color: var(--tg-hint);
}

.btn-large {
    padding: 16px 24px;
    font-size: 17px;
    border-radius: var(--radius);
}

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

/* ========== Tab Bar ========== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tab-height);
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--divider);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
    transition: transform 0.2s;
}

.tab-bar.hidden {
    transform: translateY(100%);
}

.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--tg-hint);
    font-size: 10px;
    cursor: pointer;
    transition: color 0.15s;
    padding: 4px 0;
}

.tab-item.active {
    color: var(--accent);
}

.tab-icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* ========== Today card ========== */
.today-row {
    display: flex;
    align-items: center;
}

.today-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px 0;
}

.today-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--tg-hint);
}

.today-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--tg-text);
    line-height: 1.1;
}

.today-sub {
    font-size: 12px;
    color: var(--tg-hint);
}

.streak-divider {
    width: 1px;
    align-self: stretch;
    background: var(--divider);
    margin: 0 4px;
}

/* ========== Toggle group ========== */
.settings-toggle-group {
    display: flex;
    gap: 8px;
}

.settings-toggle {
    flex: 1;
    padding: 10px 8px;
    border: 2px solid var(--divider);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--tg-text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.settings-toggle.active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-text);
}

/* ========== Switch ========== */
.switch {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
}

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

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--tg-hint);
    border-radius: 31px;
    transition: background 0.2s;
    cursor: pointer;
}

.switch-slider::before {
    content: '';
    position: absolute;
    height: 27px;
    width: 27px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.switch input:checked + .switch-slider {
    background: var(--accent);
}

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

/* ========== Stats tabs ========== */
.stats-tabs {
    display: flex;
    gap: 4px;
    background: var(--page-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: var(--gap);
}

.stats-tab {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--tg-hint);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.stats-tab.active {
    background: var(--card-bg);
    color: var(--tg-text);
    box-shadow: var(--shadow);
}

.stats-panel {
    display: none;
}

.stats-panel.active {
    display: block;
}

/* ========== New game card ========== */
.new-game-card {
    padding: 0;
    overflow: hidden;
}

.ngame-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px var(--gap);
}

.ngame-dropdown {
    cursor: pointer;
    user-select: none;
}

.ngame-dropdown:active {
    background: var(--border);
}

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

.ngame-value-wrap {
    display: flex;
    align-items: center;
    gap: 2px;
    color: var(--tg-hint);
    font-size: 14px;
}

.ngame-current {
    color: var(--accent);
    font-size: 14px;
}

.ngame-chevron {
    width: 20px;
    height: 20px;
    fill: var(--tg-hint);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.ngame-dropdown.open .ngame-chevron {
    transform: rotate(180deg);
}

.ngame-options {
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 var(--gap) 12px;
}

.ngame-options.open {
    display: flex;
}

.ngame-chip {
    padding: 6px 14px;
    border: 1.5px solid var(--divider);
    border-radius: 20px;
    background: transparent;
    color: var(--tg-hint);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.ngame-chip.active {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

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

/* ========== Round selector ========== */
.round-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--gap);
}

.round-label {
    font-size: 14px;
    color: var(--tg-hint);
}

.round-buttons {
    display: flex;
    gap: 6px;
}

.round-btn {
    width: 48px;
    height: 36px;
    border: 2px solid var(--divider);
    border-radius: 8px;
    background: transparent;
    color: var(--tg-text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

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

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: calc(var(--tab-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--tg-text);
    color: var(--tg-bg);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 200;
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========== Daily goal ========== */
.daily-goal {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--divider);
}

.daily-goal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.daily-goal-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--tg-hint);
}

.daily-goal-count {
    font-size: 12px;
    font-weight: 700;
    color: var(--tg-text);
}

.daily-goal-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.daily-goal-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s ease, background 0.3s;
    width: 0%;
}

.daily-goal-fill.complete {
    background: var(--correct);
}

.daily-goal-count.complete {
    color: var(--correct);
}

/* ========== Goal settings ========== */
.settings-goal-hint {
    font-size: 13px;
    color: var(--tg-hint);
    margin: 0 0 10px;
}

.settings-goal-buttons {
    display: flex;
    gap: 6px;
}

.goal-btn {
    flex: 1;
    padding: 10px 4px;
    border: 2px solid var(--divider);
    border-radius: 8px;
    background: transparent;
    color: var(--tg-text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

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

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

/* ========== Loading ========== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--tg-hint);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
