:root {
    --gradient-bg: #1e1e1e;
    --gradient-header: linear-gradient(135deg, #2a2a2a, #1e1e1e);
    --gradient-btn: linear-gradient(135deg, #3a3f51, #2c2f3a);
    --gradient-btn-hover: linear-gradient(135deg, #4b5168, #343845);
    --hover-glow: 0 0 25px rgba(0, 200, 255, 0.6);
    --text: #f5f5f5;
}

html {
    background: var(--gradient-bg);
}

body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    color: var(--text);
    box-sizing: border-box;
    overflow: auto;
    scroll-behavior: smooth;
}

canvas#background-stars {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -2;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.container {
    width: auto;
    min-width: 400px;
    max-width: 500px;
    padding: 30px 20px;
    text-align: center;
    background: linear-gradient(
        145deg,
        rgba(20, 20, 20, 0.7) 0%,
        rgba(30, 30, 30, 0.6) 40%,
        rgba(40, 40, 40, 0.5) 70%,
        rgba(60, 60, 60, 0.4) 100%
    );
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: max-width 0.3s ease, padding 0.3s ease;
}

.container.expanded {
    max-width: none;
}

h1 {
    font-size: 2em;
    margin-bottom: 20px;
    color: var(--text);
    text-shadow: 0 0 10px rgba(0, 200, 255, 0.6);
    pointer-events: none;
    width: 100%;
}

label {
    display: block;
    max-width: 380px;
    text-align: left;
    margin: 16px auto 8px;
    font-weight: 600;
    color: var(--text);
}

.custom-select {
    position: relative;
    max-width: 380px;
    width: 100%;
    margin-bottom: 8px;
    margin-left: auto;
    margin-right: auto;
}

select {
    width: 100%;
    max-width: 380px;
    padding: 10px;
    font-size: 1rem;
    border-radius: 10px;
    border: 1px solid #ccc;
    background: #2a2a2a;
    color: var(--text);
    margin-bottom: 0;
    box-sizing: border-box;
    transition: border-color 0.3s, box-shadow 0.3s;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    display: block;
    -webkit-appearance: menulist;
    -moz-appearance: menulist;
    appearance: menulist;
    background-image: none;
}

#toUnit {
    margin-bottom: 0;
}

.input-container {
    position: relative;
    max-width: 380px;
    width: 100%;
    margin: 5px auto 0;
}

#inputValue {
    margin: 0;
    padding: 10px 10px 10px 10px;
    border: 2px dashed var(--text);
    background: #444;
    cursor: text;
    transition: border-color 0.3s, transform 0.3s;
    width: 100%;
    font-size: 1rem;
    border-radius: 10px;
    color: var(--text);
    box-sizing: border-box;
    text-align: center;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

#inputValue:hover {
    border-color: #00c8ff;
    transform: scale(1.06);
}

select.glow, select:focus {
    outline: none;
    border-color: #00c8ff;
    box-shadow: var(--hover-glow);
}

#inputValue:focus {
    outline: none;
    border-color: #00c8ff;
    box-shadow: var(--hover-glow);
    transform: scale(1.02);
}

.conversion-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding-bottom: 50px;
    width: 100%;
}

span#flipIcon {
    font-size: 1.4rem;
    position: relative;
    z-index: 5;
    display: block;
    width: fit-content;
    margin: 8px auto;
    padding: 6px;
    user-select: none;
    cursor: pointer;
    transition: transform 0.3s ease;
    background: none;
    border-radius: 0;
    box-shadow: none;
    color: var(--text);
}

span#flipIcon:hover {
    transform: rotate(180deg);
    background: none;
    box-shadow: none;
}

.result-wrapper {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.4s ease;
    white-space: nowrap;
    text-align: center;
    width: fit-content;
    min-width: 380px;
}

.result-wrapper.visible {
    max-height: 100px;
    opacity: 1;
}

#result {
    font-size: 1.6rem;
    font-weight: bold;
    margin-top: 50px;
    margin-bottom: 0;
    color: #00c8ff;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s ease;
    display: inline-block;
    padding: 0 10px;
    text-shadow: 0 0 8px rgba(0, 200, 255, 0.4);
}

#result:hover {
    transform: scale(1.03);
    text-shadow: var(--hover-glow);
}

#copyPopup {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 200, 255, 0.7);
    color: #1e1e1e;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
    box-shadow: 0 0 10px rgba(0, 200, 255, 0.4);
}

#copyPopup.show {
    opacity: 1;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

.clear-button {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #888;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: bold;
    transition: color 0.2s ease-in-out;
    display: none;
    background: none; 
    border: none;
    padding: 0;
    line-height: 1;
}

.clear-button.visible {
    display: block;
}

.clear-button:hover {
    color: #f5f5f5;
}

.feedback-message {
    color: #ff6b6b;
    font-size: 0.9em;
    min-height: 1.2em;
    margin-top: 5px;
    margin-bottom: 10px;
    max-width: 380px;
    width: 100%;
    text-align: center;
}

.unit-filter {
    width: 100%;
    max-width: 380px;
    padding: 10px;
    font-size: 1rem;
    border-radius: 10px;
    border: 1px solid #ccc;
    background: #2a2a2a;
    color: var(--text);
    box-sizing: border-box;
    transition: border-color 0.3s, box-shadow 0.3s;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    display: block;
    padding-right: 35px;
    height: 40px;
    margin-bottom: 8px;
}

.unit-filter:focus {
    outline: none;
    border-color: #00c8ff;
    box-shadow: var(--hover-glow);
}

.unit-select-wrapper {
    max-width: 380px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    position: relative;
    margin-bottom: 0;
}

.conversion-block > .unit-select-wrapper:first-of-type {
    margin-bottom: 20px;
}

.conversion-block > .unit-select-wrapper:last-of-type {
    margin-top: 20px;
}

.unit-filter-clear {
    position: absolute;
    right: 10px;
    top: 20px;
    transform: translateY(-50%);
    z-index: 10;
}

select.no-match-found {
    color: #ff6b6b;
    font-style: italic;
}

::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #333;
}

::-webkit-scrollbar-thumb {
    background: #888888;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555555;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #888888 #333333;
}

@media (max-width: 480px) {
    .container {
        padding: 20px;
        min-width: unset;
        width: 95%;
    }

    h1 {
        font-size: 1.5em;
    }

    select,
    input,
    .unit-filter {
        font-size: 0.95em;
        padding: 8px;
        max-width: 100%;
    }

    .result-wrapper {
        min-width: unset;
        width: 95%;
    }

    #result {
        font-size: 1.4rem;
    }
    
    .input-container {
        max-width: 100%;
    }

    .unit-select-wrapper {
        max-width: 100%;
    }
}