:root {
    --primary-color: #007AFF; /* iOS Blue */
    --secondary-color: #5856D6; /* iOS Purple */
    --accent-color: #FF3B30; /* iOS Red */
    --text-color: #1D1D1F; /* Near Black */
    --secondary-text-color: #8A8A8E; /* Gray */
    --background-color: #F2F2F7; /* Light Gray */
    --calculator-bg: #FFFFFF;
    --key-bg: #FFFFFF;
    --key-hover: #F2F2F7;
    --key-active: #E5E5EA;
    --display-bg: #EFEFF4;
    --border-color: #D1D1D6;
    --shadow-color: rgba(0, 0, 0, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
}

.container {
    width: 100%;
    max-width: 420px; /* Optimal width for calculator */
    margin: 20px auto;
}

header {
    text-align: center;
    margin-bottom: 20px; /* Reduce margin */
}

.main-title {
    font-size: 2.2em;
    font-weight: 600;
    margin-bottom: 5px;
    letter-spacing: -0.5px;
}

.title-text {
    color: var(--text-color);
}

.title-pro {
    color: var(--primary-color);
    font-weight: 700;
}

.subtitle {
    font-size: 1.1em;
    color: var(--secondary-text-color);
}

.calculator {
    background-color: var(--calculator-bg);
    border-radius: 20px; /* Slightly smaller radius */
    box-shadow: 0 10px 30px var(--shadow-color); /* Adjust shadow */
    padding: 20px; /* Reduce padding */
    overflow: hidden;
}

.display {
    background-color: var(--display-bg);
    border-radius: 12px; /* Adjust radius */
    padding: 20px 15px; /* Adjust padding */
    margin-bottom: 15px; /* Reduce margin */
    text-align: right;
}

.conversion-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 40px; /* Ensure consistent height */
}

.value-display {
    font-size: 2.5em; /* Larger display font */
    font-weight: 400; /* Lighter weight for numbers */
    color: var(--text-color);
    line-height: 1.2;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-grow: 1; /* Allow display to take space */
    justify-content: flex-end;
    overflow: hidden;
    white-space: nowrap;
}

#inputValue,
#resultValue {
    max-width: 45%; /* Prevent very long numbers from overlapping */
    overflow: hidden;
    text-overflow: ellipsis;
}

.unit {
    font-size: 0.4em; /* Smaller unit text */
    font-weight: 500;
    color: var(--secondary-text-color);
    margin-left: 4px;
}

.arrow {
    color: var(--primary-color);
    display: flex;
    align-items: center;
    margin: 0 10px;
}

.arrow-icon {
    width: 20px;
    height: 20px;
}

.unit-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 15px; /* Reduce margin */
}

.unit-btn {
    flex: 1;
    padding: 10px 5px;
    border: 1px solid transparent; /* Keep border for layout, but make transparent */
    border-radius: 10px;
    background-color: var(--key-bg);
    color: var(--text-color);
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    text-align: center;
}

.unit-btn:hover {
    background-color: var(--key-hover);
}

.unit-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    font-weight: 600;
}

.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px; /* Reduce gap */
    margin-bottom: 15px; /* Reduce margin */
}

.key {
    aspect-ratio: 1.8 / 1; /* Increase width relative to height even further */
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background-color: var(--key-bg);
    color: var(--text-color);
    font-size: 1.4em;
    font-weight: 400;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.key:hover {
    background-color: var(--key-hover);
}

.key:active {
    background-color: var(--key-active);
    transform: scale(0.96);
}

.key.zero {
    grid-column: span 2;
    aspect-ratio: auto;
}

.key.clear {
    background-color: var(--accent-color);
    color: white;
    font-weight: 500;
    border: none;
}

.key.clear:hover {
    background-color: #E53023;
}

.key.clear:active {
    background-color: #D12B1F;
}

.preset-torques {
    background-color: var(--display-bg);
    border-radius: 12px;
    padding: 15px;
    margin-top: 15px;
}

.preset-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0; /* Remove bottom margin when collapsed */
    cursor: pointer;
}

.preset-header h2 {
    font-size: 1em; /* Adjust font size */
    font-weight: 600;
    color: var(--text-color);
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--secondary-text-color);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}

.toggle-icon {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
}

.toggle-btn.active .toggle-icon {
    transform: rotate(180deg);
}

.preset-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
    max-height: 0; /* Initially hidden */
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-top 0.3s ease;
    opacity: 0;
    margin-top: 0; /* No margin when hidden */
}

.preset-buttons:not(.hidden) {
    max-height: 200px; /* Adjust max height when visible */
    opacity: 1;
    margin-top: 15px; /* Add margin when visible */
    overflow-y: auto;
}

.preset-btn {
    background-color: var(--key-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 8px;
    color: var(--text-color);
    font-size: 0.8em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    text-align: left;
}

.preset-btn:hover {
    background-color: var(--key-hover);
    border-color: #C7C7CC;
}

.preset-value {
    display: block;
    font-size: 0.9em;
    font-weight: 400;
    color: var(--primary-color);
    margin-top: 4px;
}

footer {
    text-align: center;
    margin-top: 20px; /* Reduce margin */
    color: var(--secondary-text-color);
    font-size: 0.8em;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    body {
        align-items: flex-start; /* Align to top on small screens */
        background-color: var(--calculator-bg); /* Match calculator background */
    }
    .container {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }
    header {
        padding: 10px;
        margin-bottom: 10px;
    }
    .calculator {
        padding: 10px;
    }
    .main-title {
        font-size: 1.6em;
    }
    .subtitle {
        font-size: 0.8em;
    }
    .display {
        padding: 15px 10px;
        margin-bottom: 10px;
    }
    .value-display {
        font-size: 1.9em;
    }
    .unit {
        font-size: 0.45em;
    }
    .arrow-icon {
        width: 18px;
        height: 18px;
    }
    .unit-btn {
        padding: 10px 5px;
        font-size: 0.8em;
        border-radius: 10px;
    }
    .keypad {
        gap: 6px;
        margin-bottom: 10px;
    }
    .key {
        font-size: 1.3em;
        border-radius: 10px;
        aspect-ratio: 1.8 / 1; /* Apply similar ratio for mobile */
    }
    .key.zero {
        aspect-ratio: auto;
    }
    .preset-torques {
        padding: 10px;
        margin-top: 10px;
    }
    .preset-header h2 {
        font-size: 1em;
    }
    .preset-buttons:not(.hidden) {
        max-height: 150px; /* Adjust mobile max height */
    }
    footer {
        margin-top: 15px;
    }
} 