/* CSS Variables for Theming */
:root {
    --primary: #e74c3c;
    --primary-hover: #c0392b;
    --primary-light: rgba(231, 76, 60, 0.1);
    --secondary: #3498db;
    --secondary-hover: #2980b9;
    --success: #27ae60;
    --warning: #f39c12;

    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-card: #ffffff;
    --bg-card-hover: #f5f5f5;
    --bg-input: #ffffff;
    --bg-modal: rgba(0, 0, 0, 0.5);

    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-muted: #95a5a6;
    --text-on-primary: #ffffff;

    --border: #e9ecef;
    --border-focus: #3498db;

    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);

    --work-color: #e74c3c;
    --short-break-color: #27ae60;
    --long-break-color: #3498db;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --bg-card-hover: #1a4a7a;
    --bg-input: #16213e;
    --bg-modal: rgba(0, 0, 0, 0.8);

    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;

    --border: #2a2a4a;
    --border-focus: #4a9eff;

    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-left .logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.logo-icon {
    font-size: 1.5rem;
}

.header-center {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    justify-content: center;
    margin: 0 1rem;
}

.presets {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.preset-btn {
    padding: 0.4rem 0.75rem;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.preset-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.preset-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--text-on-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.fullscreen-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.fullscreen-btn:hover {
    background: var(--bg-secondary);
    color: var(--primary);
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-full);
    transition: background 0.2s;
    user-select: none;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
}

.theme-toggle .moon-icon,
.theme-toggle .sun-icon {
    font-size: 1.1rem;
    transition: opacity 0.2s;
}

[data-theme="light"] .theme-toggle .moon-icon {
    opacity: 0.3;
}

[data-theme="light"] .theme-toggle .sun-icon {
    opacity: 1;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    opacity: 0.3;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    opacity: 1;
}

.lang-toggle {
    display: flex;
    gap: 0.25rem;
    background: var(--bg-secondary);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

.lang-btn {
    padding: 0.35rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.lang-btn.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

.header-right .lang-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.user-id {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
}

.sync-status {
    font-size: 0.75rem;
    color: var(--success);
}

.sync-status.offline {
    color: var(--warning);
}

.sync-status.error {
    color: var(--primary);
}

.sync-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: transform 0.3s;
}

.sync-btn:hover {
    transform: rotate(180deg);
}

.sync-btn.syncing {
    animation: spin 1s linear infinite;
}

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

/* Main Content */
.main-content {
    max-width: 600px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Tabs */
.tabs {
    display: flex;
    justify-content: space-around;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    font-size: 0.75rem;
}

.tab-btn .tab-icon {
    font-size: 1.25rem;
}

.tab-btn.active {
    background: var(--bg-secondary);
    color: var(--primary);
}

.tab-btn:hover:not(.active) {
    background: var(--bg-card-hover);
}

.tab-content {
    position: relative;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* Timer */
.timer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem 0;
}

.timer-status {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--work-color);
}

.timer-status.break-short {
    color: var(--short-break-color);
}

.timer-status.break-long {
    color: var(--long-break-color);
}

.timer-dial {
    position: relative;
    width: 250px;
    height: 250px;
}

.timer-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.timer-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 8;
}

.timer-progress {
    fill: none;
    stroke: var(--work-color);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 565.48;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.5s, stroke 0.3s;
}

.timer-progress.break-short {
    stroke: var(--short-break-color);
}

.timer-progress.break-long {
    stroke: var(--long-break-color);
}

.timer-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3.5rem;
    font-weight: 300;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-primary);
}

.timer-controls {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--text-on-primary);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    color: var(--primary);
}

.btn-warning {
    background: var(--warning);
    color: var(--text-on-primary);
}

.btn-warning:hover {
    background: #e67e22;
}

.btn-danger {
    background: var(--primary);
    color: var(--text-on-primary);
}

.btn-danger:hover {
    background: var(--primary-hover);
}

.btn-lg {
    padding: 0.85rem 2.5rem;
    font-size: 1.1rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.settings-trigger {
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* Panel Title */
.panel-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    text-align: center;
    color: var(--text-primary);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.stat-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.stat-unit {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Level Card */
.level-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.level-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.level-badge {
    background: linear-gradient(135deg, var(--warning), var(--primary));
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 1rem;
}

.level-value {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.level-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.xp-bar {
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    height: 12px;
    overflow: hidden;
}

.xp-progress {
    background: linear-gradient(90deg, var(--warning), var(--primary));
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.5s ease;
}

/* Achievements Grid */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.achievement-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1rem;
    text-align: center;
    box-shadow: var(--shadow);
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.achievement-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.achievement-card.locked {
    opacity: 0.6;
    filter: grayscale(0.8);
}

.achievement-card.unlocking {
    animation: achievementUnlock 0.6s ease;
}

@keyframes achievementUnlock {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); box-shadow: 0 0 20px var(--warning); }
    100% { transform: scale(1); }
}

.achievement-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.achievement-name {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.achievement-desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.achievement-progress {
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    height: 6px;
    overflow: hidden;
}

.achievement-progress-bar {
    background: var(--success);
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.3s;
}

.achievement-reward {
    font-size: 0.65rem;
    color: var(--warning);
    margin-top: 0.25rem;
}

.achievement-lock {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 0.75rem;
}

/* Rankings */
.rankings-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    justify-content: center;
}

.rankings-type-btn {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.rankings-type-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.rankings-list {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.ranking-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.rankings-list > .ranking-item:last-child {
    border-bottom: none;
}

.rankings-list > .ranking-item:hover {
    background: var(--bg-card-hover);
}

.rankings-list > .ranking-item.is-current-user {
    background: var(--primary-light);
    font-weight: 600;
}

.rank-position {
    width: 2.5rem;
    text-align: center;
    font-weight: 700;
    margin-right: 0.75rem;
}

.rank-position.gold {
    color: #ffc107;
}

.rank-position.silver {
    color: #adb5bd;
}

.rank-position.bronze {
    color: #b87333;
}

.rank-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    margin-right: 0.75rem;
    font-size: 0.8rem;
}

.rank-info {
    flex: 1;
}

.rank-name {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.rank-level {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.rank-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Settings */
.settings-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-label {
    font-weight: 500;
    color: var(--text-primary);
}

.lang-toggle-inline,
.theme-toggle-inline {
    display: flex;
    gap: 0.25rem;
    background: var(--bg-secondary);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
}

.lang-toggle-inline .lang-btn,
.theme-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.theme-btn.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

.settings-danger {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.settings-danger .btn {
    width: 100%;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-modal);
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    padding: 2rem;
    width: 90%;
    max-width: 400px;
    position: relative;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.range-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
    height: 6px;
}

.range-value {
    font-weight: 600;
    color: var(--primary);
    min-width: 2rem;
    text-align: right;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.modal-actions .btn {
    flex: 1;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.toast {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.5rem;
    box-shadow: var(--shadow-hover);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    font-weight: 500;
    color: var(--text-primary);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(-100%); }
}

/* Immersive Mode */
.immersive-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.immersive-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding: 2rem;
}

.immersive-status {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--work-color);
}

.immersive-status.break-short {
    color: var(--short-break-color);
}

.immersive-status.break-long {
    color: var(--long-break-color);
}

.immersive-dial {
    position: relative;
    width: 400px;
    height: 400px;
}

.immersive-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.immersive-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 6;
}

.immersive-progress {
    fill: none;
    stroke: var(--work-color);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s, stroke 0.3s;
}

.immersive-progress.break-short {
    stroke: var(--short-break-color);
}

.immersive-progress.break-long {
    stroke: var(--long-break-color);
}

.immersive-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    font-weight: 300;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-primary);
}

.immersive-info {
    display: flex;
    gap: 2rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.immersive-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.exit-immersive {
    margin-top: 1rem;
}

/* Timer Options */
.timer-options {
    margin-top: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--primary);
    width: 1.1rem;
    height: 1.1rem;
}

/* Timer Info */
.timer-info {
    text-align: center;
}

.timer-round {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Timer Interrupts */
.timer-interrupts {
    font-size: 0.85rem;
    color: var(--warning);
    margin-top: 0.5rem;
}

/* Stats Summary */
.stats-summary {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-top: 1.5rem;
    box-shadow: var(--shadow);
}

.summary-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-label {
    font-weight: 600;
    color: var(--text-primary);
    margin-right: 0.75rem;
}

.summary-value {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    .presets {
        display: none;
    }

    .header-center {
        justify-content: flex-end;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .header-left .logo {
        font-size: 1rem;
    }

    .header-center {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .header-right {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .main-content {
        padding: 1rem;
    }

    .timer-dial {
        width: 200px;
        height: 200px;
    }

    .timer-display {
        font-size: 2.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .achievements-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tabs {
        padding: 0.25rem;
    }

    .tab-btn {
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }

    .immersive-dial {
        width: 280px;
        height: 280px;
    }

    .immersive-display {
        font-size: 3.5rem;
    }

    .immersive-info {
        flex-direction: column;
        gap: 0.5rem;
    }

    .immersive-controls {
        gap: 0.5rem;
    }

    .immersive-controls .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}
