:root {
    --pink: #FFD1DC;
    --green: #C1E1C1;
    --blue: #AEC6CF;
    --yellow: #FDFD96;
    --dark: #2c3e50;
    --success: #27ae60;
    --error: #e74c3c;
    --accent: #8e44ad;
    --secondary: #eef2f3;
}


body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    color: var(--dark);
}

nav {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    padding: 0.8rem;
    display: flex;
    justify-content: center;
    gap: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 1000;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}


nav a {
    text-decoration: none;
    color: var(--dark);
    font-weight: bold;
    padding: 8px 16px;
    border-radius: 20px;
    transition: 0.3s;
}

nav a.active {
    background: var(--accent);
    color: white;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page {
    display: none;
    padding: 60px 15px 30px;
    animation: fadeIn 0.3s ease-out;
}


.page#capture-page {
    padding-top: 30px;
}


.page.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}


.container {
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 600px;
    text-align: center;
    box-sizing: border-box;
}

@media (max-width: 600px) {
    .container {
        padding: 20px 15px;
        border-radius: 12px;
    }

    input[type="number"] {
        width: 50px;
        height: 40px;
        font-size: 1.2rem;
    }
}


.input-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

/* Global History Controls (Linked Sticky) */
.global-controls {
    position: sticky;
    top: 64px;
    left: 20px;
    z-index: 1001;
    width: fit-content;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    padding: 8px 15px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    margin: 10px 0 0 20px;
    float: left;
}


.storage-label {
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    color: var(--dark);
}

.btn-clear-minimal {
    background: rgba(231, 76, 60, 0.05);
    border: 1px solid var(--error);
    border-radius: 20px;
    color: var(--error);
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
    padding: 3px 12px;
    text-decoration: none;
    opacity: 0.8;
    transition: 0.2s;
}


.btn-clear-minimal:hover {
    opacity: 1;
    color: darkred;
}


input[type="number"] {
    width: 60px;
    height: 50px;
    text-align: center;
    font-size: 1.4rem;
    font-weight: bold;
    border: 2px solid #ddd;
    border-radius: 12px;
    appearance: textfield;
    /* Standard */
    -moz-appearance: textfield;
    /* Hides persistent spinner in Firefox */
}

/* Hide separators by default in Chrome/Safari/Edge/Opera */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Show spinners on hover/focus */
input[type="number"]:hover,
input[type="number"]:focus {
    appearance: auto;
    -moz-appearance: number-input;
}

input[type="number"]:hover::-webkit-outer-spin-button,
input[type="number"]:hover::-webkit-inner-spin-button,
input[type="number"]:focus::-webkit-outer-spin-button,
input[type="number"]:focus::-webkit-inner-spin-button {
    -webkit-appearance: auto;
}

#n1 {
    background-color: var(--pink);
}

#n2 {
    background-color: var(--green);
}

#n3 {
    background-color: var(--blue);
}

#n4 {
    background-color: var(--yellow);
}

.solution-section {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 15px;
    border: 2px dashed #ccc;
    margin-top: 20px;
}

#userExpr {
    width: 90%;
    padding: 12px;
    font-size: 1.2rem;
    border-radius: 8px;
    border: 2px solid #ddd;
    text-align: left !important;
    margin-bottom: 10px;
    direction: ltr !important;
    unicode-bidi: embed;
}


button {
    padding: 12px 20px;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: bold;
    transition: all 0.2s;
    margin-top: 10px;
}

.btn-solve {
    background-color: var(--dark);
    color: white;
}

.btn-rules {
    background-color: var(--secondary) !important;
    color: var(--dark) !important;
    border: 1px solid #dcdde1 !important;
}



.btn-generate {
    background-color: var(--success);
}

.btn-check,
.btn-submit {
    background-color: var(--accent);
    width: 100%;
}

button:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

.nav-controls {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-nav {
    background: #95a5a6;
    flex: 1;
    max-width: 120px;
}

.btn-nav:disabled {
    background: #d5dbdb;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-clear-minimal {
    background: transparent !important;
    color: #e74c3c !important;
    border: 1px solid #e74c3c !important;
    font-size: 0.75rem !important;
    opacity: 0.6;
}

/* Fix for the Contact Form Layout */
#contact-form label {
    display: block;
    margin-top: 15px;
    margin-bottom: 5px;
    text-align: left;
    font-weight: bold;
}

#contact-form input,
#contact-form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-sizing: border-box;
    font-family: inherit;
}

/* Hebrew/RTL: keep labels and typed text aligned to the right */
html[dir="rtl"] #contact-form label {
    text-align: right;
}

html[dir="rtl"] #contact-form input,
html[dir="rtl"] #contact-form textarea {
    text-align: right;
    direction: rtl;
    unicode-bidi: plaintext;
}

html[dir="ltr"] #contact-form input,
html[dir="ltr"] #contact-form textarea {
    text-align: left;
    direction: ltr;
    unicode-bidi: plaintext;
}

.btn-goto-highlight {
    background-color: var(--success) !important;
    transform: scale(1.08);
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.4);
    color: #fff !important;
}

.input-with-prefix {
    display: flex;
    align-items: center;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    padding: 0 10px;
    width: 80px;
    height: 35px;
    box-sizing: border-box;
}

.input-with-prefix span {
    color: #7f8c8d;
    font-weight: bold;
    font-size: 1.1rem;
    margin-right: 2px;
}

.input-with-prefix input {
    border: none;
    outline: none;
    background: transparent;
    font-size: 1.1rem;
    width: 100%;
    padding: 0;
    text-align: left;
}

.cork-tile {
    width: 80px;
    height: 80px;
    background: radial-gradient(circle at 30% 30%, #e6ccb2, #b08968);
    border-radius: 50%;
    border: 3px solid #7f5539;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.3), inset -2px -2px 4px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
    margin: 5px;
}

.cork-tile:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 4px 8px 15px rgba(0, 0, 0, 0.4);
}

.cork-tile.selected {
    border: 4px solid var(--accent);
    box-shadow: 0 0 15px var(--accent);
    transform: scale(1.1);
}

/* Pot UI */
.pot-container {
    position: relative;
    width: 220px;
    height: 250px;
    margin: 30px auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    perspective: 800px;
}

.pot-rim {
    width: 115px;
    height: 16px;
    background: #a67c52;
    border-radius: 10px;
    z-index: 6;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(0, 0, 0, 0.2);
}

.pot-neck {
    width: 65px;
    height: 35px;
    background: linear-gradient(to right, #8a4a1a, #bf814b, #8a4a1a);
    margin-top: -4px;
    z-index: 4;
    clip-path: polygon(15% 0%, 85% 0%, 100% 100%, 0% 100%);
    box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.2);
}

.pot-body {
    width: 175px;
    height: 155px;
    background: radial-gradient(circle at 30% 30%, #cd925b 0%, #bf814b 30%, #8a4a1a 100%);
    border-radius: 50% 50% 35% 35% / 25% 25% 75% 75%;
    position: relative;
    box-shadow:
        inset -18px -18px 40px rgba(0, 0, 0, 0.6),
        inset 12px 12px 30px rgba(255, 255, 255, 0.2),
        0 25px 60px rgba(0, 0, 0, 0.5);
    margin-top: -12px;
    z-index: 3;
    border: 1px solid rgba(0, 0, 0, 0.25);
    transition: transform 0.3s ease;
}





.pot-label {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 15px;
    border-radius: 8px;
    font-size: 1.6rem;
    font-weight: bold;
    color: var(--dark);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    min-width: 65px;
    min-height: 48px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

/* Victory Seal Cork Animation */
.victory-cork {
    display: none;
    /* Persistent Invisibility */
    width: 75px;
    height: 48px;
    background: radial-gradient(circle at 40% 40%, #c29970, #5d4037);
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 6px 6px 30% 30%;
    border: 2px solid #7f5539;
    box-shadow: 2px 6px 18px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.pot-container.sealed .victory-cork {
    display: block;
    animation: dropIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes dropIn {
    0% {
        transform: translate(-50%, -150px);
        opacity: 0;
    }

    100% {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}




/* Fraction Rendering */
.frac {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 1.4rem;
    vertical-align: middle;
}

.frac .n {
    border-bottom: 2px solid currentColor;
    padding: 2px 4px;
}

.frac .d {
    padding: 2px 4px;
}

/* Rules Box Styling */
.rules-box {
    background: #fdfaf6;
    border: 1px solid #e9d8c4;
    border-radius: 12px;
    padding: 15px 20px;
    margin: 15px 0;
    text-align: left;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    animation: slideDown 0.3s ease-out;
}

.rules-box h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: #8a4a1a;
    border-bottom: 1px solid #f2e6d9;
    padding-bottom: 5px;
}

.rules-content {
    font-size: 0.9rem;
    line-height: 1.6;
    color: #5d4037;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.fraction-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    align-items: center;
    justify-items: center;
    max-width: 450px;
    margin: 25px auto;
}

.cork-tile {
    width: 70px;
    height: 70px;
    background: radial-gradient(circle at 40% 40%, #c29970, #8d6e63);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow:
        inset -4px -4px 8px rgba(0, 0, 0, 0.4),
        inset 4px 4px 6px rgba(255, 255, 255, 0.2),
        0 4px 10px rgba(0, 0, 0, 0.3);
    border: 2px solid #5d4037;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
}

.cork-tile::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: url('https://www.transparenttextures.com/patterns/cork-board.png');
    opacity: 0.3;
    pointer-events: none;
}

.cork-tile:hover {
    transform: scale(1.05) rotate(1deg);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
}

.cork-tile.selected {
    border-color: #fff;
    box-shadow: 0 0 15px var(--accent);
    transform: scale(1.1);
}

.op-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--dark);
    color: var(--dark);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.op-btn:hover {
    background: var(--dark);
    color: white;
}

.op-btn.selected {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: scale(1.1);
}

/* ======= Tutoring Intro ======= */
.tutoring-intro {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-left: 4px solid var(--accent);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 22px;
    font-size: 0.97rem;
    line-height: 1.6;
    color: var(--dark);
}

[dir="rtl"] .tutoring-intro {
    border-left: none;
    border-right: 4px solid var(--accent);
}

#expr-preview {

    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin: 15px 0;
    font-size: 1.4rem;
    min-height: 48px;
    font-weight: bold;
    color: var(--accent);
    direction: ltr !important;
    unicode-bidi: embed;
}