:root {
    --bg-overlay: rgba(0, 0, 0, 0.6);
    --sidebar-bg: rgba(20, 20, 20, 0.98);
    --btn-bg: #333;
    --btn-text: #fff;
    --accent-color: #0078d7;
    --frame-color: rgba(255, 255, 255, 0.1);
}

/* ========================================
   BASE RESET & BODY
   ======================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;
}

body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #111;
    background-size: cover;
    background-position: center;
    transition: background 0.3s;
}

/* ========================================
   MENU BUTTON
   ======================================== */
.menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.8rem;
    cursor: pointer;
    transition: transform 0.2s;
    line-height: 1;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-btn:hover {
    transform: scale(1.1);
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
    height: 100%;
    width: 320px;
    max-width: 85vw;
    position: fixed;
    z-index: 999;
    top: 0;
    left: -100%;
    background-color: var(--sidebar-bg);
    backdrop-filter: blur(10px);
    overflow-x: hidden;
    transition: left 0.3s ease-in-out;
    padding-top: 60px;
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar.open {
    left: 0;
}

.sidebar-content {
    padding: 20px;
    color: #eee;
    overflow-y: auto;
    flex-grow: 1;
    padding-bottom: 30px;
}

.sidebar h2 {
    margin-top: 0;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
    font-size: 1.4rem;
}

.sidebar h3 {
    color: var(--accent-color);
    margin-bottom: 8px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 18px;
}

.setting-group {
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.05);
    padding: 14px;
    border-radius: 8px;
}

.setting-item {
    margin-bottom: 12px;
}

.setting-item label {
    display: block;
    font-size: 0.85rem;
    color: #ccc;
    margin-bottom: 4px;
}

select,
input[type="text"] {
    width: 100%;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    border: 1px solid #444;
    border-radius: 4px;
    box-sizing: border-box;
}

input[type="color"] {
    width: 100%;
    height: 35px;
    border: none;
    cursor: pointer;
    background: none;
    margin-bottom: 5px;
}

input[type="file"] {
    width: 100%;
    font-size: 0.8rem;
    color: #aaa;
    margin-top: 5px;
}

.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #555;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

.btn-action {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 5px;
    font-weight: bold;
    transition: opacity 0.2s;
}

.btn-action:hover {
    opacity: 0.85;
}

.btn-warning {
    background: #ff9800;
    color: #000;
}

.btn-danger {
    background: #d32f2f;
    color: white;
    margin-top: 20px;
}

.btn-pip {
    background: var(--accent-color);
    color: white;
    margin-bottom: 10px;
}

/* ========================================
   CALCULATOR CONTAINER
   ======================================== */
.calculator-container {
    position: relative;
    background: rgba(30, 30, 30, 0.75);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    border: 2px solid var(--frame-color);
    width: 360px;
    max-width: calc(100vw - 40px);
    display: flex;
    flex-direction: column;
    transition: border-color 0.3s;
}

/* ========================================
   HEADER
   ======================================== */
.calc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    gap: 10px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.welcome-text {
    color: white;
    font-size: 1rem;
    opacity: 0.8;
    font-weight: 500;
    text-align: right;
    flex-grow: 1;
    word-break: break-word;
    line-height: 1.3;
}

.mic-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    min-width: 38px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    transition: background 0.3s;
    flex-shrink: 0;
}

.mic-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mic-btn.listening {
    background: #ff4444;
    border-color: #ff4444;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 14px rgba(255, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0);
    }
}

/* ========================================
   DISPLAY SECTION
   ======================================== */
.display-container {
    text-align: right;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 14px;
    padding-right: 8px;
    padding-left: 8px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.sub-display {
    font-size: 1rem;
    color: #aaa;
    min-height: 22px;
    white-space: nowrap;
    overflow-x: hidden;
    overflow-y: hidden;
    margin-bottom: 4px;
    opacity: 0.8;
}

.sub-display::-webkit-scrollbar {
    height: 3px;
}

.sub-display::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 2px;
}

.display {
    width: 100%;
    background: transparent;
    color: white;
    font-size: 3rem;
    font-weight: 300;
    border: none;
    outline: none;
    overflow: hidden;
    white-space: nowrap;
    line-height: 1.2;
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    transition: font-size 0.15s ease;
}

/* ========================================
   BUTTONS GRID
   ======================================== */
.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    flex-grow: 1;
}

.calc-btn {
    aspect-ratio: 1;
    border-radius: 50%;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    background: var(--btn-bg);
    color: var(--btn-text);
    transition: filter 0.1s, transform 0.1s;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: inherit;
    width: 100%;
    user-select: none;
    -webkit-user-select: none;
}

.calc-btn:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
}

.calc-btn:active {
    transform: scale(0.93);
    filter: brightness(1.3);
}

.calc-btn.accent {
    background: var(--accent-color);
    color: white;
}

.calc-btn.wide {
    grid-column: span 2;
    width: 100%;
    border-radius: 40px;
    aspect-ratio: auto;
    padding: 14px;
}

.calc-btn.top-row {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
}

.pressed {
    transform: scale(0.93) !important;
    filter: brightness(1.3);
}

/* ========================================
   HISTORY
   ======================================== */
#history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#history-list li {
    border-bottom: 1px solid #333;
    padding: 8px 0;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
}

.hist-time {
    font-size: 0.75rem;
    color: #777;
    margin-bottom: 2px;
}

.hist-res {
    color: var(--accent-color);
    font-weight: bold;
    word-break: break-all;
}

/* ========================================
   CREDITS
   ======================================== */
.credits {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.4);
    line-height: 1.7;
}

.credits a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.credits a:hover {
    color: white;
    text-decoration: underline;
}

/* Mini credits on calculator face */
.credits-mini {
    text-align: center;
    margin-top: 10px;
    font-size: 0.55rem;
    color: rgba(255, 255, 255, 0.2);
    letter-spacing: 0.3px;
}

.credits-mini a {
    color: rgba(255, 255, 255, 0.25);
    text-decoration: none;
    transition: color 0.2s;
}

.credits-mini a:hover {
    color: var(--accent-color);
}

/* ========================================
   RESPONSIVE — SMALL SCREENS & ELECTRON
   ======================================== */
@media (max-width: 420px) {
    .calculator-container {
        padding: 16px;
        width: 100%;
        max-width: 100vw;
        border-radius: 0;
        border: none;
        min-height: 100vh;
        max-height: 100vh;
    }

    .display {
        font-size: 2.4rem;
        min-height: 48px;
    }

    .buttons-grid {
        gap: 8px;
    }

    .calc-btn {
        font-size: 1.2rem;
    }

    .credits {
        font-size: 0.65rem;
    }
}

@media (max-height: 650px) {
    .calc-header {
        margin-bottom: 8px;
    }

    .display-container {
        margin-bottom: 8px;
        padding-bottom: 8px;
    }

    .display {
        font-size: 2.2rem;
        min-height: 44px;
    }

    .buttons-grid {
        gap: 7px;
    }

    .credits {
        margin-top: 10px;
        font-size: 0.65rem;
    }
}