:root {
    --primary: #3498db;
    --primary-glow: rgba(52, 152, 219, 0.4);
    --secondary: #9b59b6;
    --danger: #e74c3c;
    --warning: #f1c40f;
    --bg-color: #f8f9fa;
    --card-bg: rgba(255, 255, 255, 0.85);
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --border-color: rgba(0, 0, 0, 0.05);
    --glass-blur: 12px;
    --dropdown-bg: #ffffff;
}

body.dark-mode {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --dropdown-bg: #1e293b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile-first: full height, centered, min scrolling */
body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    transition: background-color 0.4s ease, color 0.4s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    width: 100vw;
    overflow-x: hidden;
    padding: 0;
}

/* On wide screens, show a subtle grid pattern behind the card */
@media (min-width: 500px) {
    body {
        background-image:
            radial-gradient(circle, rgba(0,0,0,0.04) 1px, transparent 1px);
        background-size: 28px 28px;
    }
    body.dark-mode {
        background-image:
            radial-gradient(circle, rgba(255,255,255,0.04) 1px, transparent 1px);
        background-size: 28px 28px;
    }
}

/* Mobile (<500px): fill the entire screen with no border-radius */
.fitbbeak-container {
    width: 100%;
    max-width: 393px;          /* iOS 393pt baseline */
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--card-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: 0;
    padding: clamp(15px, 4vmin, 28px);
    box-shadow: none;
    margin: 0;
}

/* Tablet / PC: show as a floating phone card */
@media (min-width: 500px) {
    .fitbbeak-container {
        height: min(852px, 96dvh); /* iOS 852pt baseline */
        border-radius: 40px;
        box-shadow: 0 24px 80px rgba(0,0,0,0.18), 0 0 0 1px var(--border-color);
        margin: auto;
    }
}

/* Header */
.header-area {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end; /* controls sit on the right */
    margin-bottom: clamp(10px, 3vh, 24px);
}

h1 {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Oswald', sans-serif;
    font-size: clamp(1.6rem, 6vmin, 2.5rem);
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
}

.header-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: clamp(8px, 2vmin, 12px);
}

.btn-icon {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: clamp(8px, 2vmin, 12px);
    padding: clamp(6px, 1.5vmin, 8px);
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon svg {
    width: clamp(16px, 4.5vmin, 22px);
    height: clamp(16px, 4.5vmin, 22px);
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

body:not(.dark-mode) .sun-icon, 
.dark-mode .moon-icon {
    display: none;
}

/* Custom Select */
.custom-select {
    position: relative;
    font-family: inherit;
    font-weight: 600;
}

.custom-select .select-selected {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: clamp(8px, 2vmin, 12px);
    padding: clamp(4px, 1vh, 6px) clamp(16px, 4vw, 22px) clamp(4px, 1vh, 6px) clamp(8px, 2vw, 10px);
    font-size: clamp(0.8rem, 2.5vmin, 1rem);
    color: var(--text-main);
    cursor: pointer;
    user-select: none;
    position: relative;
    min-width: clamp(45px, 12vmin, 60px);
    text-align: center;
    transition: background 0.2s;
}

.custom-select .select-selected:hover {
    background: rgba(0,0,0,0.05);
}

.dark-mode .custom-select .select-selected:hover {
    background: rgba(255,255,255,0.05);
}

.custom-select .select-selected::after {
    content: "";
    position: absolute;
    top: 50%;
    right: clamp(4px, 1vw, 8px);
    margin-top: -2px;
    border: clamp(3px, 1vw, 4px) solid transparent;
    border-top-color: var(--text-main);
    border-bottom: none;
    transition: transform 0.2s;
}

.custom-select .select-selected.select-arrow-active::after {
    transform: rotate(180deg);
}

.custom-select .select-items {
    position: absolute;
    background-color: var(--dropdown-bg);
    top: 100%;
    right: 0;
    margin-top: 8px;
    border: 1px solid var(--border-color);
    border-radius: clamp(12px, 3vmin, 16px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    z-index: 100;
    overflow: hidden;
    min-width: 100%;
}

.dark-mode .custom-select .select-items {
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
}

.custom-select .select-items div {
    color: var(--text-main);
    padding: clamp(6px, 1.5vh, 10px) clamp(10px, 2.5vw, 16px);
    font-size: clamp(0.75rem, 2.5vmin, 0.9rem);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    text-align: center;
}

.custom-select .select-items div:hover {
    background-color: rgba(127, 140, 141, 0.1);
}

.select-hide {
    display: none;
}

/* Settings Grid */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(8px, 2vmin, 16px);
    margin-bottom: clamp(10px, 3vh, 30px);
}

.setting-card {
    background: white;
    border-radius: clamp(12px, 3vmin, 24px);
    padding: clamp(8px, 2vmin, 14px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(4px, 1vh, 8px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}

.dark-mode .setting-card {
    background: rgba(255, 255, 255, 0.05);
    box-shadow: none;
}

label {
    font-size: clamp(0.65rem, 2vmin, 0.85rem);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.number-control {
    display: flex;
    align-items: center;
    background: rgba(0,0,0,0.05);
    border-radius: clamp(8px, 2vmin, 12px);
    overflow: hidden;
    height: clamp(35px, 8vh, 70px);
    width: 100%;
    border: none;
}

.dark-mode .number-control {
    background: rgba(0,0,0,0.2);
}

.wheel-picker {
    flex: 1;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: ns-resize;
}

/* Selection Center Lines */
.wheel-picker::before,
.wheel-picker::after {
    content: '';
    position: absolute;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-color, var(--primary)), transparent);
    opacity: 0.3;
    z-index: 2;
    pointer-events: none;
}

.wheel-picker::before { top: calc(50% - clamp(12px, 3vh, 16px)); }
.wheel-picker::after { top: calc(50% + clamp(12px, 3vh, 16px)); }

.wheel-viewport {
    width: 100%;
    height: 100%;
    perspective: 1200px;
}

.wheel-scroller {
    width: 100%;
    transform-style: preserve-3d;
    transition: transform 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.wheel-item {
    height: clamp(24px, 6vh, 32px);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Oswald', sans-serif;
    font-weight: 500;
    font-size: clamp(0.8rem, 2.5vmin, 1rem);
    color: var(--text-muted);
    transition: all 0.2s;
    backface-visibility: hidden;
    user-select: none;
}

.wheel-item.active {
    color: var(--text-main);
    font-size: clamp(1.4rem, 5.5vmin, 2.6rem);
    font-weight: 800;
    opacity: 1;
    transform: scale(1.15);
    text-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
}

.wheel-item.nearby {
    opacity: 0.5;
    transform: rotateX(45deg) scale(0.85);
}

.wheel-item.far {
    opacity: 0.15;
    transform: rotateX(75deg) scale(0.7);
}

.wheel-input {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg-color);
    text-align: center;
    font-family: 'Oswald', sans-serif;
    font-size: clamp(1.2rem, 4vmin, 1.8rem);
    color: var(--text-main);
    font-weight: 700;
    outline: none;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
}

.wheel-input::-webkit-outer-spin-button,
.wheel-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.btn-adjust {
    border: none;
    background: transparent;
    color: var(--text-main);
    width: clamp(24px, 6vw, 36px);
    height: 100%;
    cursor: pointer;
    font-size: clamp(1rem, 3vmin, 1.4rem);
    font-weight: bold;
    transition: background 0.2s;
}

.btn-adjust:hover { background: rgba(0,0,0,0.1); }

.unit {
    font-size: clamp(0.6rem, 1.8vmin, 0.75rem);
    color: var(--text-muted);
}

/* Display Area with Radial Progress */
#display-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: clamp(10px, 2vh, 20px) 0 clamp(10px, 3vh, 30px);
    min-height: 0; /* Let flexbox compress it if necessary */
}

.progress-container {
    position: relative;
    width: clamp(140px, 45vmin, 320px);
    height: clamp(140px, 45vmin, 320px);
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.progress-ring__circle-bg {
    color: var(--border-color);
}

.progress-ring__circle {
    transition: stroke-dashoffset 0.1s linear;
}

.counter-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

#counter {
    font-family: 'Oswald', sans-serif;
    font-size: clamp(3.5rem, 18vmin, 8.5rem);
    line-height: 1;
    font-weight: 700;
    margin: 0;
    position: relative;
    top: -0.06em; /* Visually center Oswald font which has low baseline */
    transition: transform 0.1s;
}

/* Controls */
.controls-area {
    display: flex;
    flex-direction: column;
    gap: clamp(10px, 2vmin, 16px);
}

.btn-cta {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    border-radius: clamp(12px, 3vmin, 20px);
    padding: clamp(12px, 2.5vh, 18px);
    font-weight: 800;
    font-size: clamp(1rem, 3vmin, 1.2rem);
    cursor: pointer;
    box-shadow: 0 10px 20px var(--primary-glow);
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
    width: 100%;
}

.btn-cta:active {
    transform: scale(0.96);
}

.btn-group {
    display: flex;
    gap: clamp(8px, 2vmin, 12px);
    width: 100%;
}

.btn-group button {
    flex: 1;
    padding: clamp(12px, 2.5vh, 16px);
    border-radius: clamp(10px, 2.5vmin, 16px);
    border: none;
    font-weight: 700;
    font-size: clamp(0.9rem, 2.5vmin, 1.1rem);
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-secondary {
    background: var(--border-color);
    color: var(--text-main);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.hidden { display: none !important; }

/* Flash Overlay */
#flash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: var(--primary);
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
}

.flash-active {
    animation: flash-animation 0.2s ease-out;
}

@keyframes flash-animation {
    0% { opacity: 0.3; }
    100% { opacity: 0; }
}

.counting-down #counter {
    color: var(--warning);
}
