:root {
    --bg-color: #f2f2f7;
    --text-color: #000000;
    --card-bg: rgba(255, 255, 255, 0.85);
    --primary-color: #007aff;
    --secondary-bg: #ffffff;
    --secondary-text: #8e8e93;
    --border-color: rgba(0, 0, 0, 0.1);
    --progress-bg: #e5e5ea;
    --radius: 14px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.dark-mode {
    --bg-color: #000000;
    --text-color: #ffffff;
    --card-bg: rgba(28, 28, 30, 0.85);
    --secondary-bg: #1c1c1e;
    --secondary-text: #98989d;
    --border-color: rgba(255, 255, 255, 0.1);
    --progress-bg: #3a3a3c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }

body { 
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px 20px 100px 20px;
    transition: background-color 0.3s ease;
}

#app { max-width: 420px; margin: 0 auto; }

.header-row { margin-bottom: 25px; padding: 0 5px; text-align: left; }
h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; }

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 85px;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding-bottom: 20px;
    z-index: 1000;
}

.nav-item {
    background: none;
    border: none;
    color: var(--secondary-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px;
    cursor: pointer;
    transition: color 0.2s;
}

.nav-item i { width: 24px; height: 24px; }
.nav-item span { font-size: 10px; font-weight: 500; }
.nav-item.active { color: var(--primary-color); }

.tool-btn {
    width: 100%;
    padding: 16px 20px;
    background: var(--secondary-bg);
    border: none;
    color: var(--text-color);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 17px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

.tool-btn i { width: 22px; height: 22px; color: var(--primary-color); }
.tool-btn:active { transform: scale(0.98); background-color: var(--progress-bg); }

#tool-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 85px;
    background: var(--bg-color);
    z-index: 900;
    padding: 20px;
    overflow-y: auto;
}

.tool-header { display: flex; align-items: center; margin-bottom: 5px; }
#tool-title { font-size: 17px; font-weight: 600; flex-grow: 1; text-align: center; margin-right: 60px; }
.tool-desc { font-size: 13px; color: var(--secondary-text); text-align: center; margin-bottom: 25px; line-height: 1.4; padding: 0 20px; }
.back-btn { background: none; border: none; color: var(--primary-color); font-size: 17px; display: flex; align-items: center; cursor: pointer; }

/* Overhauled Input Styles */
.text-input, .text-area, .select-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--secondary-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 16px;
    font-weight: 400;
    margin-bottom: 15px;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}

.text-input:focus, .text-area:focus, .select-input:focus {
    border-color: var(--primary-color);
    background: var(--secondary-bg);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.text-area {
    min-height: 140px;
    line-height: 1.5;
    resize: none;
}

.select-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 40px;
}

.dark-mode .select-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2398989d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* Speedtest Overlap Fixes */
.speed-gauge {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 10px 0 20px 0;
    min-height: 100px;
}

.speed-value { font-size: 52px; font-weight: 800; line-height: 1; color: var(--primary-color); }
.speed-unit { font-size: 14px; font-weight: 600; color: var(--secondary-text); margin-top: 4px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 15px;
}

.stat-card {
    background: var(--secondary-bg);
    padding: 12px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden; 
}

.stat-value { font-size: 15px; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }

/* Rickroll Generator Styles */
.rick-preview {
    background: var(--progress-bg);
    padding: 15px;
    border-radius: 10px;
    font-family: monospace;
    font-size: 13px;
    word-break: break-all;
    margin: 15px 0;
    border: 1px solid var(--border-color);
    text-align: left;
}

.progress-container { 
    height: 12px; 
    border-radius: 6px; 
    background: var(--progress-bg); 
    margin: 25px 0; 
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.progress-bar { 
    height: 100%; 
    background: linear-gradient(90deg, #007aff, #5856d6); 
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px rgba(0, 122, 255, 0.3);
}

/* Settings & Media UI Polish */
.settings-group {
    background: var(--secondary-bg);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.settings-cell {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 0.5px solid var(--border-color);
    background: var(--secondary-bg);
    cursor: pointer;
    transition: background-color 0.2s;
}

.settings-cell:last-child { border-bottom: none; }
.settings-cell:active { background-color: var(--progress-bg); }
.settings-label { font-size: 17px; font-weight: 400; }

.upload-box {
    border: 2px dashed var(--border-color);
    background: var(--secondary-bg);
    padding: 40px 20px;
    border-radius: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 20px;
}

.upload-box:active { background-color: var(--progress-bg); border-color: var(--primary-color); }

.tab-container {
    display: flex;
    background: var(--progress-bg);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    border: none;
    background: none;
    padding: 8px;
    color: var(--text-color);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background-color 0.2s;
}

.tab-btn i { width: 16px; height: 16px; }
.tab-btn.active { background: var(--secondary-bg); box-shadow: 0 2px 6px rgba(0,0,0,0.1); color: var(--primary-color); }

.stats-info {
    font-size: 13px;
    color: var(--secondary-text);
    font-weight: 500;
    margin-bottom: 20px;
    padding: 0 5px;
    display: flex;
    gap: 15px;
}

.util-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.small-btn {
    border: none;
    background: var(--secondary-bg);
    color: var(--primary-color);
    padding: 14px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.1s, background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.small-btn:active { transform: scale(0.96); background-color: var(--progress-bg); }

/* Metronome Polish */
.metro-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: var(--secondary-bg);
    margin: 40px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 800;
    color: var(--text-color);
    box-shadow: var(--shadow);
    border: 6px solid var(--progress-bg);
    transition: transform 0.1s, border-color 0.1s;
}

.metro-active { border-color: var(--primary-color); transform: scale(1.05); }

input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary-color); }
input[type="range"] { -webkit-appearance: none; width: 100%; background: transparent; height: 30px; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--progress-bg); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; height: 26px; width: 26px; border-radius: 50%; background: white; margin-top: -11px; box-shadow: 0 2px 6px rgba(0,0,0,0.2); }
