/* ============================================================================
   DESIGN TOKENS (Modern Aesthetic)
   ============================================================================ */
:root {
    color-scheme: light dark;

    /* Page & Card */
    --page-bg: #f5f5f7;
    --card-bg: #ffffff;
    --card-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.08);
    
    /* Typography */
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --section-label-color: #0071e3;
    
    /* Inputs */
    --input-bg: #f5f5f7;
    --input-border: transparent;
    --input-focus-ring: rgba(0, 113, 227, 0.3);
    
    /* Buttons & Accents */
    --accent: #0071e3;
    --accent-hover: #0077ED;
    --button-text: #ffffff;
    --icon-bg: #f5f5f7;
    --icon-hover: #e8e8ed;

    /* Results */
    --results-bg: #fafafa;
    --specs-bg: #f5f5f7;

    /* Modals */
    --modal-mask: rgba(0,0,0,0.4);

    /* Geometry */
    --radius-card: 24px;
    --radius-input: 12px;
    --radius-button: 98px; /* Pill shape */
}

[data-theme="dark"] {
    --page-bg: #000000;
    --card-bg: #1c1c1e;
    --card-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    
    --text-primary: #f5f5f7;
    --text-secondary: #86868b;
    --section-label-color: #2997ff;
    
    --input-bg: #2c2c2e;
    --input-focus-ring: rgba(41, 151, 255, 0.4);
    
    --accent: #2997ff;
    --accent-hover: #3e9eff;
    --icon-bg: #2c2c2e;
    --icon-hover: #3a3a3c;

    --results-bg: #2c2c2e;
    --specs-bg: #2c2c2e;
    --modal-mask: rgba(0,0,0,0.7);
}

/* ============================================================================
   GLOBAL STYLES
   ============================================================================ */
body {
    background-color: var(--page-bg);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 40px 20px;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom);
}

.container {
    background: var(--card-bg);
    width: 100%;
    max-width: 860px; /* Wide enough for 2 columns */
    padding: 40px;
    border-radius: var(--radius-card);
    box-shadow: var(--card-shadow);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.hidden { display: none !important; }

.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================================
   HEADER
   ============================================================================ */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.header-text h1 {
    margin: 0 0 4px 0;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-text .subtitle {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.header-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.track-input-group input {
    width: 85px;
    text-align: center;
    padding: 10px;
}

.theme-toggle-button {
    background: var(--icon-bg);
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.theme-toggle-button:hover {
    background: var(--icon-hover);
    transform: scale(1.05);
}

/* ============================================================================
   FORMS & INPUTS
   ============================================================================ */
.form-grid {
    display: flex;
    flex-direction: column;
    gap: 32px;
    margin-bottom: 32px;
}

@media (min-width: 768px) {
    .form-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 48px;
    }
}

.column {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--section-label-color);
    font-weight: 700;
    margin: 0 0 8px 0;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.label-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
    font-weight: 500;
    transition: color 0.2s ease;
}

.link-btn:hover {
    color: var(--accent-hover);
}

input[type="number"], select {
    background: var(--input-bg);
    border: 2px solid var(--input-border);
    color: var(--text-primary);
    font-size: 1.05rem;
    padding: 14px 16px;
    border-radius: var(--radius-input);
    transition: all 0.2s ease;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
    width: 100%;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2386868b%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 16px top 50%;
    background-size: 10px auto;
}

input[type="number"]::placeholder { color: var(--text-secondary); opacity: 0.5; }
input[type="number"]:focus, select:focus {
    background: var(--card-bg);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--input-focus-ring);
}

.range-wrapper {
    height: 52px; /* Matches input height */
    display: flex;
    align-items: center;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;         /* Modern Standard */
    width: 100%;
    height: 6px;
    background: var(--input-bg);
    border-radius: 3px;
    outline: none;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 2px solid var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
}

.primary-button {
    width: 100%;
    background: var(--accent);
    color: var(--button-text);
    border: none;
    padding: 16px;
    border-radius: var(--radius-button);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.primary-button:hover { background: var(--accent-hover); }
.primary-button:active { transform: scale(0.98); }

/* ============================================================================
   RESULTS
   ============================================================================ */
.results-container {
    margin-top: 32px;
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.results-panel {
    background: var(--results-bg);
    border-radius: var(--radius-card);
    padding: 32px;
    text-align: center;
}

.result-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--input-bg);
}

.result-hero .result-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.result-value-large {
    font-size: 4rem;
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--accent);
    line-height: 1;
}

.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.result-item .result-value {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.result-item .result-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Tech Specs Block */
.tech-specs-panel {
    margin-top: 16px;
    background: var(--specs-bg);
    border-radius: var(--radius-input);
    padding: 20px;
}

.specs-title {
    margin: 0 0 12px 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.specs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 0.85rem;
}

.spec-item {
    display: flex;
    justify-content: space-between;
}

.spec-label { color: var(--text-secondary); }
.spec-item span:last-child { color: var(--text-primary); font-weight: 500; }

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

/* ============================================================================
   MODAL & FOOTER
   ============================================================================ */
.card-footer {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--input-bg);
    text-align: center;
}

.card-footer p { margin: 0; font-size: 0.85rem; color: var(--text-secondary); }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-mask);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 999;
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-card {
    background: var(--card-bg);
    padding: 32px;
    border-radius: var(--radius-card);
    width: 90%;
    max-width: 400px;
    box-shadow: var(--card-shadow);
}

.modal-header h3 { margin: 0 0 8px 0; font-size: 1.4rem; font-weight: 600; }
.modal-header p { margin: 0 0 24px 0; font-size: 0.9rem; color: var(--text-secondary); }

.modal-actions { display: flex; gap: 12px; margin-top: 24px; }

.secondary-button {
    flex: 1;
    background: var(--input-bg);
    color: var(--text-primary);
    border: none;
    padding: 14px;
    border-radius: var(--radius-button);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.secondary-button:hover { background: var(--icon-hover); }

.modal-btn { flex: 1; margin-top: 0; padding: 14px; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================================================
   SQUIRCLE PROGRESSIVE ENHANCEMENT
   Applies continuous-curve superellipse corners where supported (Chrome 139+).
   Falls back silently to standard border-radius on all other browsers.

   Intentionally excluded:
     - .primary-button / .secondary-button  (--radius-button: 98px pill shape)
     - .theme-toggle-button                 (border-radius: 50% circle)
     - input[type=range] track & thumb      (decorative/circular, sub-pixel)
   ============================================================================ */
@supports (corner-shape: squircle) {
    /* Card-scale panels (--radius-card: 24px) */
    .container,
    .results-panel,
    .modal-card {
        corner-shape: squircle;
    }

    /* Input-scale controls (--radius-input: 12px) */
    input[type="number"],
    select,
    .tech-specs-panel {
        corner-shape: squircle;
    }
}

@media (max-width: 520px) {
    .container { padding: 24px; }
    .specs-grid { grid-template-columns: 1fr; }
}
