/* HP12c Calculator Simulator Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #004262;
    min-height: 100vh;
    color: #333;
}

:root {
    --mono-font: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Noto Sans Mono", monospace;
}

/* Font-independent x̄ rendering (used in steps/FAQ) */
.xbar {
    position: relative;
    display: inline-block;
    line-height: 1;
    padding-top: 0.15em;
}

.xbar::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 0.05em;
    border-top: 0.12em solid currentColor;
}

.container {
    display: flex;
    max-width: 1500px;
    margin: 0 auto;
    padding: 15px;
    gap: 20px;
    min-height: 100vh;
}

/* Calculator Section */
.calculator-section {
    flex: 2;
    background: white;
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 1, 1);
    height: fit-content;
}

.calculator-section h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 25px;
    font-size: 1.8rem;
    font-weight: 600;
}

.calculator-container {
    position: relative;
    max-width: 100%;
    margin: 0 auto;
}

/* Display Container */
.display-container {
    position: absolute;
    top: 6.75%;
    left: 18%;
    width: 46%;
    height: 15%;
    z-index: 10;
}

.display {
    background: transparent;
    border-radius: 3px;
    padding: 4px;
    height: 100%;
    position: relative;
    border: none;
}

.display-indicators {
    display: flex;
    justify-content: space-between;
    font-size: clamp(0.5rem, 1vw, 0.75rem);
    color: #18220d;
    margin-top: -5px;
    padding: 0 6px;
    font-weight: bold;
    background: transparent;
}

.indicator {
    opacity: 0.2;
    transition: opacity 0.3s;
}

.indicator.active {
    opacity: 1;
    color: #000000;
}

.display-screen {
    background: transparent;
    color: #000;
    font-family: 'Share Tech Mono', 'Courier New', monospace;
    font-size: clamp(1.5rem, 3.5vw, 2.8rem);
    font-weight: 500;
    text-align: left;
    padding: 4px 8px;
    border-radius: 2px;
    height: calc(100% - 14px);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    letter-spacing: 0.05em;
    text-shadow: 0 0 2px rgba(0,0,0,0.4);
    overflow: hidden;
    white-space: nowrap;
    max-width: 100%;
}

/* Calculator Image and Buttons */
.calculator-image-container {
    position: relative;
    width: 100%;
    margin: 0 auto;
}

.calculator-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 10px;
}

.calc-btn {
    position: absolute;
    background: #4a4a4a;
    border: 2px solid #000;
    cursor: pointer;
    border-radius: 8px;
    width: 7%;
    height: 9%;
    font-size: clamp(0.6rem, 1.25vw, 1.25rem);
    font-weight: bold;
    color: #fff;
    transition: all 0.3s ease;
    z-index: 5;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    line-height: 1;
}

/* F-shift label positioned above the button */
.calc-btn::before {
    content: attr(data-f);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(0.4rem, 0.85vw, 0.65rem);
    color: #ff8c42;
    font-weight: 600;
    white-space: nowrap;
    padding-bottom: 2px;
    pointer-events: none;
}

.calc-btn .primary-label {
    flex: 0 0 55%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.calc-btn .g-label {
    font-size: clamp(0.45rem, 0.95vw, 0.75rem);
    color: #4dabf7;
    font-weight: 600;
    background: #2a2a2a;
    width: 100%;
    flex: 0 0 45%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 0 6px 6px;
}

.calc-btn .f-label {
    font-size: clamp(0.45rem, 0.95vw, 0.75rem);
    color: #ff8c42;
    font-weight: 600;
    background: #2a2a2a;
    width: 100%;
    flex: 0 0 45%;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    border-radius: 0 0 6px 6px;
    position: absolute;
    bottom: 0;
    left: 0;
}

.calc-btn:hover {
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.8), 0 0 30px rgba(255, 255, 255, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.6);
    transform: translate(-50%, -50%) scale(1.1);
    z-index: 10;
}

.calc-btn:active {
    animation: flash 0.3s ease;
}

.calc-btn.f-active {
    box-shadow: 0 0 15px rgba(255, 165, 0, 0.8);
    border: 2px solid rgba(255, 165, 0, 0.5);
    background: #1a1a1a;
}

/* When f-shift is active, hide primary label and g-label, show f-label */
.calc-btn.f-active .primary-label {
    display: none;
}

.calc-btn.f-active .g-label {
    display: none;
}

.calc-btn.f-active .f-label {
    display: none; /* Keep hidden, we use ::after instead */
}

.calc-btn.f-active::after {
    content: attr(data-f);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(0.7rem, 1.4vw, 1.4rem);
    color: #ff8c42;
    font-weight: bold;
    white-space: nowrap;
}

.calc-btn.g-active {
    box-shadow: 0 0 15px rgba(0, 191, 255, 0.8);
    border: 2px solid rgba(0, 191, 255, 0.5);
    background: #1a1a1a;
}

/* When g-shift is active, hide primary label and g-label, show only g function */
.calc-btn.g-active .primary-label {
    display: none;
}

.calc-btn.g-active .g-label {
    display: none;
}

.calc-btn.g-active::after {
    content: attr(data-g);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(0.7rem, 1.4vw, 1.4rem);
    color: #e7f5ff;
    font-weight: bold;
    white-space: nowrap;
}

.f-key:hover, .f-key.active {
    box-shadow: 0 0 20px rgba(255, 165, 0, 1), 0 0 30px rgba(255, 165, 0, 0.6);
}

.f-key {
    background: #ff8c00;
}

.f-key .g-label {
    background: #cc6600;
}

.g-key:hover, .g-key.active {
    box-shadow: 0 0 20px rgba(0, 191, 255, 1), 0 0 30px rgba(0, 191, 255, 0.6);
}

.g-key {
    background: #4dabf7;
}

.g-key .g-label {
    background: #1c7ed6;
}

/* XYZT Debug Overlay */
#xy-debug {
    position: absolute;
    right: 12px;
    top: 12px;
    padding: 6px 10px;
    background: #0b2e40;
    color: #e6f2f7;
    border-radius: 6px;
    font-family: 'Share Tech Mono', monospace;
    display: none; /* default hidden; toggled to flex in JS */
    gap: 16px;
    z-index: 20;
    pointer-events: none;
}

/* Hide f-label on plus button unless f-active */
.calc-btn[data-key="plus"] .f-label {
    display: none;
}

.calc-btn[data-key="plus"].f-active .f-label {
    display: flex;
}

/* Enter button styling (rectangular) */
.calc-btn[data-key="enter"] {
    width: 7%;
    height: 25%;
    border-radius: 8px;
}

.calc-btn[data-key="enter"] .primary-label {
    writing-mode: vertical-lr;
    text-orientation: upright;
    letter-spacing: -0.1em;
    flex: 1 1 auto;
}

.calc-btn[data-key="enter"] .g-label {
    flex: 0 0 19%;
}

/* ON button styling */
.calc-btn[data-key="on"] {
    justify-content: center;
}

.calc-btn[data-key="on"] .primary-label {
    flex: 1 1 auto;
}

.calc-btn[data-key="on"] .g-label {
    display: none;
}

/* Zero button styling (wider) */
.calc-btn[data-key="0"] {
    width: 7%;
    height: 9%;
    border-radius: 8px;
}

/* Steps Section */
.steps-section {
    flex: 1;
    background: #eceef0;
    border-radius: 15px;
    padding: 10px 25px 10px 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 1, 1);
    max-height: calc(100vh - 30px);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.steps-section h2 {
    color: #2c3e50;
    margin-bottom: 20px;
    margin-top: 19px;
    font-size: 1.4rem;
    text-align: center;
}

.steps-section h2:first-of-type {
    margin-top: 0;
}

/* Registers Display */
.registers-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.register-group {
    background: white;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.register-group h3 {
    display: none;
}

.register-display {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.register-display-horizontal {
    display: grid;
    grid-template-columns: 0.75fr 0.75fr 1.5fr 1.5fr 1.5fr;
    gap: 8px;
    align-items: center;
    padding: 4px;
    background: #f8f9fa;
    border-radius: 4px;
}

.register-item {
    display: flex;
    gap: 8px;
    justify-content: space-between;
    padding: 4px 6px;
    border-right: none;
    background: white;
}

.register-display-horizontal .register-label {
    font-weight: bold;
    color: #34495e;
}

.register-display-horizontal > div > span:not(.register-label) {
    text-align: right;
    flex: 1;
    min-width: 60px;
}

.register-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 0.85rem;
}

.register-row.empty {
    justify-content: center;
    color: #95a5a6;
    font-style: italic;
}

.register-label {
    font-weight: bold;
    color: #34495e;
    min-width: 35px;
}

.register-row span:last-child {
    color: #2c3e50;
    letter-spacing: 0.05em;
}

#steps-container {
    flex: 1;
    font-family: 'Courier New', monospace;
    line-height: 1.6;
    overflow-y: auto;
    overflow-x: hidden;
}

.steps-intro {
    color: #6c757d;
    font-style: italic;
    text-align: center;
    margin: 20px 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.step {
    background: white;
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 5px;
    border-left: 4px solid #3498db;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 10px;
    align-items: start;
    position: relative;
}

.step-number {
    background: #3498db;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
    min-width: 0;
    padding-right: 10px;
}

.step-button {
    display: inline;
    line-height: 1.8;
}

.step-key {
    background: #e8e8e8;
    color: #2c3e50;
    padding: 2px 6px;
    border-radius: 3px;
    /* UI fonts tend to render combining marks (e.g., x̄) more reliably across browsers */
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, 'Noto Sans', Arial, sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
}

.step-description {
    color: #6c757d;
    font-size: 0.9rem;
    margin-top: 2px;
    padding-right: 0;
}

.step-result {
    color: #27ae60;
    font-weight: bold;
    font-size: 0.9rem;
    white-space: nowrap;
    position: absolute;
    right: 12px;
    top: 8px;
    pointer-events: none;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .steps-section {
        max-height: calc(100vh - 30px);
    }
}

@media (max-width: 768px) {
    .container {
        flex-direction: column;
        gap: 20px;
        padding: 10px;
    }
    
    .calculator-section, .steps-section {
        padding: 15px;
    }
    
    .calculator-section h1 {
        font-size: 1.4rem;
    }
    
    .register-display-horizontal {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    
    .calculator-image {
        width: 100%;
        max-width: 100%;
    }
    
    .calculator-image-container {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .calc-btn {
        width: 6%;
        height: 8%;
    }
}

/* Animation for button press feedback */
@keyframes flash {
    0% { 
        background: rgba(255, 255, 255, 0.8);
        box-shadow: 0 0 30px rgba(255, 255, 255, 1), 0 0 40px rgba(255, 255, 255, 0.8);
    }
    50% { 
        background: rgba(255, 255, 255, 1);
        box-shadow: 0 0 40px rgba(255, 255, 255, 1), 0 0 50px rgba(255, 255, 255, 1);
    }
    100% { 
        background: transparent;
        box-shadow: none;
    }
}

@keyframes buttonPress {
    0% { transform: translate(-50%, -50%); }
    50% { transform: translate(-50%, -50%); }
    100% { transform: translate(-50%, -50%); }
}

.calc-btn.pressed {
    animation: flash 0.3s ease;
}

/* Scrollbar styling for steps container */
#steps-container::-webkit-scrollbar {
    width: 8px;
}

#steps-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#steps-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

#steps-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Stack Section */
.stack-section {
    margin-top: 15px;
    text-align: center;
}

.stack-toggle-btn {
    background-color: #ff6b35;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.2s;
}

.stack-toggle-btn:hover {
    background-color: #e55a2b;
}

#stack-content {
    margin-top: 10px;
}

/* Help Section */
.help-section {
    background: white;
    border-radius: 10px;
    padding: 15px;
    margin-top: 0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.help-section.collapsed {
    padding: 10px;
}

.help-section h2 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.3rem;
    text-align: center;
}

.help-section h3 {
    color: #34495e;
    margin-bottom: 12px;
    font-size: 1.1rem;
}

#help-content {
    min-height: 200px;
    max-height: 600px;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 15px;
}

.help-default ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.help-default li {
    margin-bottom: 4px;
    line-height: 1.3;
    font-size: 0.85rem;
}

.help-default code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--mono-font);
    font-size: 0.85em;
    color: #c7254e;
}

.faq-btn {
    width: 100%;
    padding: 12px 20px;
    background: #003855;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s;
}

.faq-btn:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

.help-nav {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.help-nav-btn {
    flex: 1;
    padding: 12px 20px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s;
}

.help-nav-btn:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
}

.help-back-btn {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 5px;
    cursor: pointer;
    margin-bottom: 15px;
    font-size: 0.9rem;
    transition: background 0.3s;
}

.help-back-btn:hover {
    background: #7f8c8d;
}

.help-header-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.help-back-arrow {
    background: #95a5a6;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
    flex-shrink: 0;
    line-height: 1;
    padding: 0;
}

.help-back-arrow:hover {
    background: #7f8c8d;
}

.help-header-row h3 {
    margin: 0;
    flex: 1;
}

.help-categories {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(4, auto);
    gap: 10px;
    margin-top: 15px;
}

/* Responsive layout for help categories */
@media (max-width: 1100px) {
    .help-categories {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(6, auto);
    }
}

@media (max-width: 700px) {
    .help-categories {
        grid-template-columns: 1fr;
        grid-template-rows: none;
    }
    .help-category-btn {
        font-size: 0.95rem;
        padding: 12px;
    }
}

.help-category-btn {
    padding: 15px;
    background: #ecf0f1;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: #2c3e50;
    transition: all 0.3s;
}

.help-category-btn:hover {
    background: #3498db;
    color: white;
    border-color: #2980b9;
    transform: translateY(-2px);
}

.help-category-btn-wide {
    grid-column: 1 / -1;
}

#example-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.help-example-btn {
    padding: 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.help-example-btn:hover {
    background: #e8f4f8;
    border-color: #3498db;
    transform: translateX(5px);
}

.example-problem {
    background: white;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
    border-left: 4px solid #3498db;
}

.example-steps {
    background: white;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
}

.steps-header {
    cursor: pointer;
    user-select: none;
    padding: 10px;
    background: #ecf0f1;
    border-radius: 5px;
    transition: background 0.2s;
}

.steps-header:hover {
    background: #dfe6e9;
}

.toggle-icon {
    float: right;
    color: #3498db;
    font-size: 0.9rem;
}

.steps-list {
    margin-top: 10px;
    margin-left: 30px;
    padding-left: 10px;
}

.steps-list li {
    margin-bottom: 4px;
    line-height: 1.4;
    font-family: inherit;
    font-size: 0.9rem;
}

.steps-list li code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 3px;
    /* Prefer UI fonts here so combining marks like x̄ render reliably across browsers/OSes */
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, 'Noto Sans', Arial, sans-serif;
    font-size: 1em;
    color: #000000;
    font-weight: 600;
}

.example-result {
    background: #d5f4e6;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #27ae60;
    font-size: 1rem;
}

#help-content::-webkit-scrollbar {
    width: 8px;
}

#help-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#help-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

#help-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.tips-content {
    padding: 15px;
    background: white;
    border-radius: 5px;
}

.tips-content h4 {
    color: #2c3e50;
    margin-top: 15px;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.tips-content h4:first-child {
    margin-top: 0;
}

.tips-content ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.tips-content li {
    margin-bottom: 8px;
    line-height: 1.5;
    font-size: 0.9rem;
}

.tips-content code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    color: #000000;
}