/* ==========================================================================
   EverySingleCent — Calculator Demo (Neumorphic)
   Scoped under .calc-demo to avoid leaking into landing page styles.
   Light + Dark mode via .calc-demo and .calc-demo.dark
   ========================================================================== */

/* --- CSS Variables (Light Mode) --- */
.calc-demo {
    --cd-base: #e0e5ec;
    --cd-base-border: #f0f2f5;
    --cd-display-bg: #EBE1D6;
    --cd-text: #555555;
    --cd-text-heading: #444444;
    --cd-text-muted: #8898aa;
    --cd-shadow-raised: 3px 3px 6px rgba(163,177,198,0.6), -3px -3px 6px rgba(255,255,255,0.9);
    --cd-shadow-pressed: inset 2px 2px 5px rgba(0,0,0,0.3), inset -2px -2px 5px rgba(255,255,255,0.2);
    --cd-shadow-inset: inset 2px 2px 5px rgba(163,177,198,0.6), inset -2px -2px 5px rgba(255,255,255,0.5);
    --cd-shadow-dropdown: 4px 4px 10px rgba(163,177,198,0.5), -4px -4px 10px rgba(255,255,255,0.7);
    --cd-shadow-container: 0 0 25px rgba(0,0,0,0.2);
    --cd-expense: #f23e16;
    --cd-income: #949e34;
    --cd-submit: #595959;
    --cd-tax-active: #003366;
}

/* --- Dark Mode Variables --- */
.calc-demo.dark {
    --cd-base: #2d3239;
    --cd-base-border: #3a4149;
    --cd-display-bg: #3d342d;
    --cd-text: #e0e5ec;
    --cd-text-heading: #d0d5dc;
    --cd-text-muted: #8898aa;
    --cd-shadow-raised: 3px 3px 6px rgba(0,0,0,0.4), -3px -3px 6px rgba(55,62,70,0.5);
    --cd-shadow-pressed: inset 2px 2px 5px rgba(0,0,0,0.5), inset -2px -2px 5px rgba(55,62,70,0.3);
    --cd-shadow-inset: inset 2px 2px 5px rgba(0,0,0,0.4), inset -2px -2px 5px rgba(55,62,70,0.3);
    --cd-shadow-dropdown: 4px 4px 10px rgba(0,0,0,0.4), -4px -4px 10px rgba(55,62,70,0.3);
    --cd-shadow-container: 0 0 25px rgba(0,0,0,0.4);
    --cd-tax-active: #6699cc;
}

/* --- Container --- */
.calc-demo {
    width: 100%;
    max-width: 380px;
    background: var(--cd-base);
    border-radius: 30px;
    border: 6px solid var(--cd-base-border);
    padding: 20px;
    box-shadow: var(--cd-shadow-container);
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    color: var(--cd-text);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box;
    position: relative;
    transition: background 0.3s, color 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.calc-demo *, .calc-demo *::before, .calc-demo *::after {
    box-sizing: border-box;
}

/* --- Layout Spacing --- */
.calc-demo .cd-row {
    margin-bottom: 10px;
}
.calc-demo .cd-row:last-child {
    margin-bottom: 0;
}

/* ========== CONTROL ROW ========== */
.calc-demo .cd-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 50px;
}

/* Menu button (decorative) */
.calc-demo .cd-btn-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    color: var(--cd-text);
    transition: box-shadow 0.15s, background 0.3s, color 0.3s;
    position: relative;
}

.calc-demo .cd-btn-icon:active {
    box-shadow: var(--cd-shadow-pressed);
}

.calc-demo .cd-btn-icon svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Receipt button — flat (matches real app) */
.calc-demo .cd-btn-receipt {
    box-shadow: none;
    position: relative;
}

/* Receipt reminder pulse when tax is on */
.calc-demo .cd-btn-receipt.reminder .cd-pulse-ring {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 2px solid var(--cd-tax-active);
    border-radius: 12px;
    animation: cd-pulse-expand 1.8s ease-out forwards;
    pointer-events: none;
}
.calc-demo .cd-btn-receipt.reminder .cd-pulse-ring:nth-child(2) { animation-delay: 0.4s; }
.calc-demo .cd-btn-receipt.reminder .cd-pulse-ring:nth-child(3) { animation-delay: 0.8s; }

@keyframes cd-pulse-expand {
    0%   { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Breathing glow (ongoing reminder) */
.calc-demo .cd-btn-receipt.breathing {
    animation: cd-breathe 2s ease-in-out infinite;
}
.calc-demo .cd-btn-receipt.breathing svg {
    color: var(--cd-tax-active);
}

@keyframes cd-breathe {
    0%, 100% { box-shadow: 0 0 0 0 transparent; }
    50%      { box-shadow: 0 0 12px 4px rgba(0, 51, 102, 0.3); }
}
.calc-demo.dark .cd-btn-receipt.breathing {
    animation-name: cd-breathe-dark;
}
@keyframes cd-breathe-dark {
    0%, 100% { box-shadow: 0 0 0 0 transparent; }
    50%      { box-shadow: 0 0 12px 4px rgba(102, 153, 204, 0.3); }
}

/* Category button */
.calc-demo .cd-category-btn {
    flex: 1;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: none;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--cd-shadow-inset);
    transition: background-color 0.2s, color 0.2s, box-shadow 0.3s;
    padding: 0 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Date display */
.calc-demo .cd-date {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background: var(--cd-base);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: var(--cd-shadow-inset);
    flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}

.calc-demo .cd-date-day {
    font-size: 18px;
    font-weight: 800;
    line-height: 1;
    color: var(--cd-text-heading);
    transition: color 0.3s;
}

.calc-demo .cd-date-month {
    font-size: 9px;
    text-transform: uppercase;
    font-weight: 600;
    line-height: 1;
    margin-top: 2px;
    color: var(--cd-text-muted);
    transition: color 0.3s;
}

/* ========== DISPLAY AREA ========== */
.calc-demo .cd-display {
    background: var(--cd-display-bg);
    border-radius: 15px;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    position: relative;
    min-height: 60px;
    border: 2px solid var(--cd-expense);
    box-shadow: var(--cd-shadow-pressed);
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.calc-demo .cd-display.income-mode {
    border-color: var(--cd-income);
}

/* Currency selector */
.calc-demo .cd-currency-btn {
    font-size: 18px;
    font-weight: 600;
    opacity: 0.7;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--cd-text);
    margin-right: 8px;
    flex-shrink: 0;
    transition: background 0.2s, color 0.3s;
}

.calc-demo .cd-currency-btn:hover {
    background: rgba(0,0,0,0.05);
}
.calc-demo.dark .cd-currency-btn:hover {
    background: rgba(255,255,255,0.08);
}

/* Main number display */
.calc-demo .cd-number {
    flex: 1;
    font-size: 36px;
    font-weight: 700;
    text-align: right;
    overflow: hidden;
    white-space: nowrap;
    color: var(--cd-text);
    direction: rtl;
    mask-image: linear-gradient(to right, transparent, black 15%);
    -webkit-mask-image: linear-gradient(to right, transparent, black 15%);
    transition: color 0.3s;
}

.calc-demo .cd-number span {
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
    white-space: nowrap;
}

/* ========== NOTES / TAG / TAX ROW ========== */
.calc-demo .cd-meta-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: stretch;
    gap: 10px;
}

/* Notes input */
.calc-demo .cd-notes-wrap {
    background: var(--cd-display-bg);
    box-shadow: var(--cd-shadow-pressed);
    border-radius: 10px;
    transition: background 0.3s, box-shadow 0.3s;
}

.calc-demo .cd-notes {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    padding: 12px 15px;
    font-size: 16px;
    font-family: inherit;
    color: var(--cd-text);
    box-sizing: border-box;
    transition: color 0.3s;
}

.calc-demo .cd-notes::placeholder {
    color: var(--cd-text-muted);
    font-style: italic;
}

/* Tag button */
.calc-demo .cd-tag-btn {
    min-width: 60px;
    max-width: 80px;
    height: 100%;
    border-radius: 10px;
    padding: 4px 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: var(--cd-shadow-inset);
    background: var(--cd-base);
    color: var(--cd-text-muted);
    border: none;
    cursor: pointer;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    line-height: 1.3;
    word-break: break-word;
    transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s;
}

/* Tax toggle */
.calc-demo .cd-tax-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.calc-demo .cd-tax-switch {
    width: 64px;
    height: 26px;
    background: var(--cd-base);
    border-radius: 13px;
    position: relative;
    box-shadow: var(--cd-shadow-inset);
    transition: background 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

.calc-demo .cd-tax-text {
    position: absolute;
    top: 50%;
    left: 2px;
    width: 36px;
    text-align: center;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--cd-text-muted);
    transform: translate(24px, -50%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.3s ease;
    user-select: none;
    pointer-events: none;
    z-index: 0;
}

.calc-demo .cd-tax-knob {
    width: 22px;
    height: 22px;
    background: var(--cd-base-border);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    box-shadow: 2px 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
    z-index: 1;
}

.calc-demo .cd-tax-wrap.active .cd-tax-switch {
    background: var(--cd-tax-active);
    box-shadow: inset 2px 2px 5px rgba(0,0,0,0.5);
}

.calc-demo .cd-tax-wrap.active .cd-tax-text {
    transform: translate(0, -50%);
    color: rgba(255,255,255,0.85);
}

.calc-demo .cd-tax-wrap.active .cd-tax-knob {
    transform: translateX(38px);
    background: #ffffff;
}

/* ========== KEYPAD ========== */
.calc-demo .cd-keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(5, 1fr);
    grid-template-areas:
        "c      pct     mul     div"
        "n7     n8      n9      plus"
        "n4     n5      n6      minus"
        "n1     n2      n3      eq"
        "dot    n0      bksp    eq";
    gap: 10px;
}

.calc-demo .cd-key {
    aspect-ratio: 1;
    border-radius: 15px;
    border: none;
    background: var(--cd-base);
    color: var(--cd-text);
    font-weight: 500;
    font-size: 20px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.1s, transform 0.1s, background 0.3s, color 0.3s;
}

/* Operator keys — raised */
.calc-demo .cd-key-op {
    box-shadow: var(--cd-shadow-raised);
}

/* Number keys — flat */
.calc-demo .cd-key-num {
    box-shadow: none;
}

/* Pressed state */
.calc-demo .cd-key:active,
.calc-demo .cd-key.pressed {
    box-shadow: var(--cd-shadow-inset) !important;
    transform: scale(0.95);
}

/* Grid area assignments */
.calc-demo .cd-key[data-key="C"]    { grid-area: c; }
.calc-demo .cd-key[data-key="%"]    { grid-area: pct; }
.calc-demo .cd-key[data-key="×"]    { grid-area: mul; }
.calc-demo .cd-key[data-key="÷"]    { grid-area: div; }
.calc-demo .cd-key[data-key="7"]    { grid-area: n7; }
.calc-demo .cd-key[data-key="8"]    { grid-area: n8; }
.calc-demo .cd-key[data-key="9"]    { grid-area: n9; }
.calc-demo .cd-key[data-key="+"]    { grid-area: plus; }
.calc-demo .cd-key[data-key="4"]    { grid-area: n4; }
.calc-demo .cd-key[data-key="5"]    { grid-area: n5; }
.calc-demo .cd-key[data-key="6"]    { grid-area: n6; }
.calc-demo .cd-key[data-key="-"]    { grid-area: minus; }
.calc-demo .cd-key[data-key="1"]    { grid-area: n1; }
.calc-demo .cd-key[data-key="2"]    { grid-area: n2; }
.calc-demo .cd-key[data-key="3"]    { grid-area: n3; }
.calc-demo .cd-key[data-key="="]    { grid-area: eq; aspect-ratio: auto; }
.calc-demo .cd-key[data-key="."]    { grid-area: dot; }
.calc-demo .cd-key[data-key="0"]    { grid-area: n0; }
.calc-demo .cd-key[data-key="⌫"]   { grid-area: bksp; }

/* Backspace icon */
.calc-demo .cd-key[data-key="⌫"] svg {
    width: 24px;
    height: 24px;
    stroke: var(--cd-text);
    fill: none;
    stroke-width: 1.5;
    transition: stroke 0.3s;
}

/* ========== ACTION BAR ========== */
.calc-demo .cd-actions {
    display: flex;
    gap: 10px;
}

.calc-demo .cd-action-btn {
    flex: 1;
    padding: 14px 8px;
    border-radius: 15px;
    border: none;
    color: white;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.calc-demo .cd-btn-expense { background: var(--cd-expense); }
.calc-demo .cd-btn-income  { background: var(--cd-income); }
.calc-demo .cd-btn-submit  { background: var(--cd-submit); }

.calc-demo .cd-action-btn.active {
    box-shadow: var(--cd-shadow-pressed);
    transform: scale(0.97);
}

.calc-demo .cd-action-btn:not(.active) {
    box-shadow: var(--cd-shadow-raised);
}

.calc-demo .cd-action-btn:active {
    transform: scale(0.95);
}

/* ========== DROPDOWNS ========== */
.calc-demo .cd-dropdown {
    position: absolute;
    background: var(--cd-base);
    border-radius: 12px;
    padding: 6px;
    box-shadow: var(--cd-shadow-dropdown);
    z-index: 50;
    display: none;
    flex-direction: column;
    gap: 3px;
    transition: background 0.3s, box-shadow 0.3s;
}

.calc-demo .cd-dropdown.open {
    display: flex;
}

/* Category dropdown — below controls row */
.calc-demo .cd-dropdown-category {
    top: 62px;
    left: 50px;
    right: 50px;
    max-width: 280px;
}

/* Currency dropdown — below display, full width */
.calc-demo .cd-dropdown-currency {
    top: 135px;
    left: 20px;
    right: 20px;
}

/* Tag dropdown — below tag button */
.calc-demo .cd-dropdown-tag {
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 160px;
}

.calc-demo .cd-dropdown-item {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-align: center;
    background: transparent;
    color: var(--cd-text);
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    width: 100%;
}

.calc-demo .cd-dropdown-item:hover {
    background: rgba(0,0,0,0.06);
}
.calc-demo.dark .cd-dropdown-item:hover {
    background: rgba(255,255,255,0.08);
}

.calc-demo .cd-dropdown-item.selected {
    color: white;
}

/* Currency dropdown items */
.calc-demo .cd-currency-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 9px 12px;
    text-align: left;
}

.calc-demo .cd-currency-code {
    font-weight: 700;
    font-size: 15px;
    width: 40px;
    flex-shrink: 0;
}

.calc-demo .cd-currency-name {
    flex: 1;
    font-size: 12px;
    opacity: 0.55;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calc-demo .cd-currency-rate {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.4;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    margin-left: 6px;
}

.calc-demo .cd-currency-rate.home {
    opacity: 0.6;
    font-weight: 700;
    color: var(--cd-income);
}

/* Tag dropdown items */
.calc-demo .cd-tag-item {
    font-size: 12px;
    text-align: left;
    padding: 8px 12px;
}

.calc-demo .cd-tag-item.no-tag {
    opacity: 0.5;
    font-style: italic;
}

/* ========== TOOLTIPS ========== */
.calc-demo .cd-tooltip {
    position: absolute;
    background: var(--cd-text-heading);
    color: var(--cd-base);
    font-size: 12px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 220px;
    line-height: 1.4;
    z-index: 60;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    text-align: center;
}

.calc-demo .cd-tooltip.visible {
    opacity: 1;
}

.calc-demo .cd-tooltip-menu {
    top: 60px;
    left: 10px;
}

.calc-demo .cd-tooltip-receipt {
    top: 60px;
    right: 10px;
}

/* (saved flash — instant, no animation needed) */

/* ========== ANNOTATIONS (handwritten callouts) ========== */
.phone-mockup .cd-annotation {
    position: absolute;
    font-family: 'Caveat', cursive;
    font-size: 17px;
    font-weight: 600;
    color: #1a3a5c;
    white-space: nowrap;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.phone-mockup .cd-annotation svg {
    color: #1a3a5c;
    flex-shrink: 0;
}

/* Top annotation — above the calculator */
.phone-mockup .cd-annotation-top {
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
}

/* Left annotation — next to currency button */
.phone-mockup .cd-annotation-left {
    right: calc(100% + 8px);
    top: 100px;
    flex-direction: row;
    gap: 4px;
}

/* Bottom annotation — below the calculator */
.phone-mockup .cd-annotation-bottom {
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
}

/* ========== PHONE FRAME WRAPPER ========== */
.phone-mockup {
    position: relative;
    display: inline-block;
}

/* Dark mode toggle on phone frame */
.phone-mockup .theme-toggle {
    position: absolute;
    top: 50%;
    right: -52px;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #d1d9e6;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s;
    z-index: 10;
}

.phone-mockup .theme-toggle:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-50%) scale(1.05);
}

.phone-mockup .theme-toggle svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s;
}

.phone-mockup .theme-toggle.is-dark {
    background: #2d3239;
    border-color: #3a4149;
}

.phone-mockup .theme-toggle.is-dark svg {
    transform: rotate(180deg);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 960px) {
    .phone-mockup .cd-annotation { display: none; }
}

@media (max-width: 768px) {
    /* Move dark mode toggle below the calculator on mobile */
    .phone-mockup {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .phone-mockup .theme-toggle {
        position: static;
        transform: none;
        margin-top: 16px;
        width: 44px;
        height: 44px;
    }

    .phone-mockup .theme-toggle:hover {
        transform: scale(1.05);
    }
}

@media (max-width: 480px) {
    .calc-demo {
        border-radius: 24px;
        padding: 16px;
        border-width: 4px;
    }

    .calc-demo .cd-number {
        font-size: 30px;
    }

    .calc-demo .cd-key {
        font-size: 18px;
        border-radius: 12px;
    }

    .calc-demo .cd-keypad {
        gap: 8px;
    }

    .calc-demo .cd-action-btn {
        padding: 12px 6px;
        font-size: 14px;
        border-radius: 12px;
    }
}
