:root {
    --bg: #f4f6f8;
    --text: #1a1a1a;
    --accent: #007bff;
    --card: #fff;
    --border: #d9d9d9;
}

body.dark {
    --bg: #1e1e1e;
    --text: #f5f5f5;
    --accent: #4dabf7;
    --card: #2b2b2b;
    --border: #3a3a3a;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Roboto, sans-serif;
    margin: 0;
    transition: all 0.3s ease;
}

header,
footer {
    text-align: center;
    padding: 1rem;
}

.container {
    width: 90%;
    max-width: 700px;
    margin: 2rem auto;
    background-color: var(--card);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

h1 {
    color: var(--accent);
}

input,
button {
    font-size: 1rem;
}

#function {
    width: 100%;
    padding: 0.8rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    outline: none;
}

#function:focus {
    border-color: var(--accent);
}

#keyboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 8px;
    margin: 1rem 0;
}

.key {
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.6rem;
    transition: 0.3s;
}

.key:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.special-key {
    background-color: #e63946;
}

.special-key:hover {
    background-color: #b71c1c;
}

.calculate-btn {
    width: 100%;
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 0.9rem;
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: 0.3s;
}

.calculate-btn:hover {
    background-color: #0056b3;
}

#result-container {
    margin-top: 1.5rem;
    background-color: var(--bg);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

pre {
    white-space: pre-wrap;
    background-color: var(--card);
    border: 1px solid var(--border);
    padding: 0.8rem;
    border-radius: 6px;
}

#theme-toggle {
    background: none;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.3s;
}

#theme-toggle:hover {
    background-color: var(--accent);
    color: white;
}

.toggle-container {
    margin: 1rem 0;
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }

    .key {
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    .calculate-btn {
        font-size: 1rem;
    }
}

/* Sliding rules panel */
.rules-panel {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    width: 920px;
    max-width: 95%;
    transform: translateX(110%);
    transition: transform 300ms ease;
    background: var(--card, #fff);
    box-shadow: -20px 0 40px rgba(0, 0, 0, 0.12);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(0, 0, 0, 0.06);
}

.rules-panel[aria-hidden="false"] {
    transform: translateX(0);
}

.rules-panel__inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.rules-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.rules-panel__header h2 {
    margin: 0;
    font-size: 16px;
}

.rules-panel__header button {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
}

.rules-panel__body {
    padding: 12px 16px;
    overflow: auto;
    flex: 1;
}

.rules-panel__footer {
    padding: 10px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Table */
.rules-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.rules-table th,
.rules-table td {
    padding: 8px 6px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    text-align: left;
    vertical-align: top;
}

.rules-table th {
    font-size: 13px;
    color: var(--muted, #6b7280);
    font-weight: 600;
}

/* Mobile adjustments */
@media (max-width:600px) {
    .rules-panel {
        width: 100%;
    }

    .rules-table th,
    .rules-table td {
        font-size: 13px;
        padding: 8px;
    }
}