:root {
    --bg-color: #f0f0f0;
    --text-color: #333;
    --header-bg: #333;
    --header-text: #fff;
    --input-bg: #fff;
    --keypad-bg: #e0e0e0;
    --code-font: "Courier New", Courier, monospace;
    --accent-color: #007bff;
    --error-color: #d32f2f;
    --result-color: #00796b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
        sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    background: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 1.2rem;
}

#controls button {
    background: transparent;
    border: 1px solid #fff;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

#history {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.history-input {
    font-family: var(--code-font);
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 4px;
}

.history-input::before {
    content: "> ";
    color: #999;
}

.history-result {
    font-family: var(--code-font);
    color: var(--result-color);
    white-space: pre-wrap;
}

.history-error {
    font-family: var(--code-font);
    color: var(--error-color);
    white-space: pre-wrap;
}

.history-ai-response {
    font-family: var(--code-font);
    color: #444;
    white-space: pre-wrap;
    background-color: #f9f9f9;
    padding: 8px;
    border-radius: 4px;
    border-left: 3px solid var(--accent-color);
}

.ai-code-block {
    background-color: #2d2d2d;
    color: #f8f8f2;
    padding: 8px;
    border-radius: 4px;
    font-family: "Courier New", Courier, monospace;
    cursor: pointer;
    margin: 5px 0;
    overflow-x: auto;
}

.ai-code-block:hover {
    outline: 2px solid var(--accent-color);
}

.ai-code-block::after {
    content: " (Click to use)";
    font-size: 0.8em;
    color: #aaa;
    float: right;
}

#input-area {
    background-color: var(--keypad-bg);
    border-top: 1px solid #ccc;
}

#keypad {
    display: flex;
    flex-wrap: wrap;
    padding: 5px;
    max-height: 120px;
    overflow-y: auto;
    gap: 4px;
    justify-content: center;
    border-bottom: 1px solid #ccc;
}

.keypad-btn {
    width: 36px;
    height: 36px;
    font-family: var(--code-font);
    font-size: 1.2rem;
    border: 1px solid #aaa;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.keypad-btn:active {
    background: #ddd;
}

#input-container {
    display: flex;
    padding: 10px;
    background: var(--input-bg);
}

#code-input {
    flex: 1;
    padding: 10px;
    font-family: var(--code-font);
    font-size: 1.1rem;
    border: 1px solid #ccc;
    border-radius: 4px 0 0 4px;
    outline: none;
}

#run-btn {
    padding: 10px 20px;
    background-color: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    font-weight: bold;
}

#run-btn:active {
    filter: brightness(0.9);
}
.history-input:hover {
    cursor: pointer;
    text-decoration: underline;
    background-color: rgba(0, 0, 0, 0.05);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--input-bg);
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-content h2 {
    margin-top: 0;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

#save-settings-btn {
    background-color: var(--accent-color);
    color: #fff;
}

#close-settings-btn {
    background-color: #ccc;
    color: #333;
}

/* Markdown Elements within AI Response */
.history-ai-response p {
    margin: 0.5em 0;
}

.history-ai-response ul,
.history-ai-response ol {
    margin: 0.5em 0;
    padding-left: 20px;
}

.history-ai-response li {
    margin-bottom: 0.2em;
}

.history-ai-response blockquote {
    border-left: 3px solid #ccc;
    margin: 0.5em 0;
    padding-left: 10px;
    color: #666;
}

.history-ai-response strong {
    font-weight: bold;
}

.history-ai-response em {
    font-style: italic;
}

.history-ai-response h1,
.history-ai-response h2,
.history-ai-response h3,
.history-ai-response h4,
.history-ai-response h5,
.history-ai-response h6 {
    margin: 0.8em 0 0.4em 0;
    font-size: 1.1em;
    font-weight: bold;
}

/* Update Code Block Styles to match marked output structure (pre > code) */
.history-ai-response pre {
    margin: 0.5em 0;
    /* Ensure styles match .ai-code-block if not applied directly */
}

/* Ensure inline code also looks distinct */
.history-ai-response :not(pre) > code {
    background-color: #eee;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: var(--code-font);
    font-size: 0.9em;
}
