/* ==============================================
   Base & Reset
   ============================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    width: 100%;
    min-width: 350px;
    min-height: 630px;
    overflow-x: auto;
    overflow-y: auto;
    touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--page-bg);
    color: var(--text-primary);
    min-height: 100dvh;
    transition: background-color 0.3s ease, color 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
}


/* ==============================================
   Variables & Themes
   ============================================== */
:root {
    --page-bg: #cbd5e1;
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --preparation: #f59e0b;
    --work: #10b981;
    --rest: #3b82f6;
    --shadow: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
    --page-bg: #020617;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --preparation: #f59e0b;
    --work: #22c55e;
    --rest: #60a5fa;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* ==============================================
   Global Layout
   ============================================== */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: max(100dvh, 630px);
    display: flex;
    flex-direction: column;
    width: 100%;
    background-color: var(--bg-primary);
    transition: background-color 0.3s ease;
}

.screen {
    display: none;
    flex-direction: column;
    flex: 1;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.screen.active {
    display: flex;
}

.screen.visible {
    opacity: 1;
}

/* ==============================================
   Header Navigation
   ============================================== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    padding-top: 20px;
    flex-shrink: 0;
    transition: margin-bottom 0.25s ease, padding-top 0.25s ease;
}

header.compact {
    margin-bottom: 10px;
    padding-top: 10px;
}

h1 {
    font-size: 28px;
    font-weight: 700;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    height: 32px;
    width: auto;
}

.header-buttons {
    display: flex;
    gap: 10px;
}

.header-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: var(--bg-secondary);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    transition: transform 0.2s ease;
}

.header-btn:hover {
    transform: scale(1.05);
}

.header-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.header-btn:active {
    transform: scale(0.95);
}

/* ==============================================
   Core Buttons
   ============================================== */
.start-btn {
    width: 100%;
    padding: 20px;
    border: none;
    background: var(--work);
    color: white;
    font-size: 20px;
    font-weight: 700;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s ease;
    box-shadow: 0 4px 12px var(--shadow);
}

.start-btn:hover {
    transform: translateY(-2px);
}

.start-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    width: 100%;
    padding: 20px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: 600;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s ease;
    box-shadow: 0 2px 8px var(--shadow);
    margin-top: 12px;
}

.secondary-btn:hover {
    transform: translateY(-1px);
    color: var(--text-primary);
}

.secondary-btn:active {
    transform: translateY(0);
}

/* ==============================================
   Configuration Screen
   ============================================== */
.config-controls {
    display: grid;
    gap: 20px;
    margin-bottom: 30px;
}

.control-group {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow);
}

.control-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-input {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.control-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 12px;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    user-select: none;
}

.control-btn:hover {
    transform: scale(1.05);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-value {
    font-size: 36px;
    font-weight: 700;
    min-width: 120px;
    text-align: center;
}

.summary {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 30px;
    text-align: center;
    color: var(--text-secondary);
}

.summary-text {
    font-size: 16px;
    line-height: 1.6;
}

/* ==============================================
   Timer Interface
   ============================================== */
.timer-screen {
    justify-content: space-between;
    height: 100%;
}

.timer-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 5px 20px;
    gap: 15px;
    min-height: 0;
}

.phase-box {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 10px 32px;
    box-shadow: 0 2px 8px var(--shadow);
    width: 100%;
    max-width: 400px;
    flex-shrink: 0;
}

.phase-label {
    font-size: 20px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-secondary);
    text-align: center;
}

.phase-label.preparation {
    color: var(--preparation);
}

.phase-label.work {
    color: var(--work);
}

.phase-label.rest {
    color: var(--rest);
}

.timer-card {
    background: var(--bg-secondary);
    border-radius: 50%;
    padding: 40px;
    box-shadow: 0 4px 16px var(--shadow);
    width: 100%;
    max-width: min(320px, max(42vh, 265px));
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 1;
    min-height: 0;
    margin: 0 auto;
}

.progress-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

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

.progress-ring-bg {
    fill: none;
    stroke: var(--bg-secondary);
    stroke-width: 4;
}

.progress-ring-progress {
    fill: none;
    stroke: var(--text-primary);
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear;
}

.timer-display {
    position: relative;
    z-index: 1;
    font-size: 80px;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.info-boxes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    flex-shrink: 0;
}

.info-box {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 12px;
    text-align: center;
    box-shadow: 0 2px 8px var(--shadow);
}

.info-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.info-value {
    font-size: 18px;
    font-weight: 700;
}

.timer-controls {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: center;
    padding: 10px 20px 20px 20px;
    flex-shrink: 0;
}

.timer-btn {
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    box-shadow: 0 4px 12px var(--shadow);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.timer-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.timer-btn.play-pause {
    width: 72px;
    height: 72px;
    background: var(--work);
    color: white;
    border-radius: 20px;
}

.timer-btn.play-pause svg {
    width: 28px;
    height: 28px;
}

.timer-btn:hover {
    transform: scale(1.05);
}

.timer-btn:active {
    transform: scale(0.95);
}

/* ==============================================
   Completion Screen
   ============================================== */
.completed-screen {
    text-align: center;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.completed-content {
    max-width: 400px;
    width: 100%;
    padding: 20px;
}

.completed-icon {
    font-size: 64px;
    margin-bottom: 15px;
}

.completed-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 12px;
}

.completed-message {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

/* ==============================================
   Animations
   ============================================== */
.pulse {
    animation: pulse 1s ease-in-out;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* ==============================================
   Media Queries
   ============================================== */
@media (max-width: 480px) {
    h1 {
        font-size: 22px;
    }

    .timer-display {
        font-size: 64px;
    }

    .timer-card {
        padding: 30px;
        max-width: min(280px, max(42vh, 265px));
    }

    .control-value {
        font-size: 28px;
        min-width: 100px;
    }

    .timer-content {
        gap: 12px;
        padding: 5px 15px;
    }
}

@media (min-width: 640px) {
    .timer-card {
        max-width: 320px;
        width: 320px;
        flex-shrink: 0;
    }

    .timer-content {
        justify-content: center;
    }

    .container {
        min-height: 676px;
        height: auto;
        margin: 0 auto;
        border-radius: 0;
        box-shadow: none;
    }

    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        padding-bottom: 0;
    }

    @media (min-height: 716px) {
        .container {
            margin-top: 40px;
            margin-bottom: 0;
            border-radius: 32px;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        }
    }

    @media (min-height: 756px) {
        .container {
            margin-bottom: 40px;
        }
    }
}