* {
    box-sizing: border-box;
}


body {
    margin: 0;
    background: white;
    color: black;
    font-family: "Courier New", monospace;
    font-size: 14px;
}


.container {
    width: 95%;
    max-width: 1000px;

    margin: 20px auto;

    border: 1px solid black;
}


/* =========================
   HEADER
========================= */

header {
    height: 36px;

    border-bottom: 1px solid black;

    display: flex;

    align-items: center;
    justify-content: space-between;

    padding: 0 18px;
}


.logo {
    font-size: 14px;
}


.search {
    display: flex;

    align-items: center;

    gap: 7px;
}


.search span {
    font-size: 18px;
}


.search input {
    border: none;

    outline: none;

    font-family: inherit;

    font-size: 14px;

    width: 120px;

    background: transparent;
}


/* =========================
   INTRO
========================= */

.intro {
    padding: 40px 25px 25px;
}


.intro h1 {
    font-size: 14px;

    font-weight: normal;

    margin: 0 0 6px;
}


.intro p {
    margin: 0;
}


/* =========================
   CATEGORIES
========================= */

.categories {
    padding: 10px 25px 35px;
}


h2 {
    font-size: 13px;

    font-weight: normal;

    margin: 10px 0 20px;

    letter-spacing: 0.5px;
}


.category-grid {
    display: grid;

    grid-template-columns: repeat(3, 1fr);

    max-width: 600px;

    row-gap: 3px;
}


.category-grid button {
    border: none;

    background: none;

    padding: 0;

    margin: 0;

    text-align: left;

    font-family: inherit;

    font-size: 14px;

    color: black;

    cursor: pointer;

    width: fit-content;
}


.category-grid button:hover {
    text-decoration: underline;
}


.category-grid button.active {
    text-decoration: underline;
}


/* =========================
   TEMPLATES
========================= */

.templates-section {
    border-top: 1px solid black;

    padding: 20px 25px 40px;
}


.template-grid {
    display: flex;

    flex-wrap: wrap;

    gap: 20px 15px;
}


.template-card {
    width: 110px;

    cursor: pointer;
}


.preview {
    height: 100px;
    border: 1px solid black;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 12px;
    transition: background 0.15s;
}

.preview img {
    width: 80%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}


.template-card:hover .preview {
    background: #f5f5f5;
}


.template-name {
    margin-top: 7px;

    font-size: 14px;
}


.template-category {
    margin-top: 3px;
    font-size: 11px;
    color: #666;
}

.template-status {
    margin-top: 4px;

    font-size: 10px;

    color: #666;

    letter-spacing: 0.2px;
}


/* =========================
   HIDDEN
========================= */

.hidden {
    display: none;
}


/* =========================
   MODAL
========================= */

.modal {
    position: fixed;

    inset: 0;

    background: rgba(255, 255, 255, 0.9);

    display: flex;

    align-items: center;

    justify-content: center;

    padding: 20px;

    z-index: 1000;
}


.modal.hidden {
    display: none;
}


.modal-content {
    position: relative;

    width: 100%;

    max-width: 500px;

    border: 1px solid black;

    background: white;

    padding: 25px;
}


/* =========================
   MODAL CLOSE
========================= */

.modal-close {
    position: absolute;

    top: 3px;

    right: 3px;

    border: none;

    background: none;

    font-family: inherit;

    font-size: 20px;

    cursor: pointer;
}


/* =========================
   MODAL PREVIEW
========================= */

.modal-preview {
    width: 100%;

    height: 300px;

    border: 1px solid black;

    display: flex;

    align-items: center;

    justify-content: center;

    margin-bottom: 20px;

    overflow: hidden;
}


.modal-preview img {
    max-width: 100%;

    max-height: 100%;

    object-fit: contain;

    display: none;
}


#previewText {
    font-size: 12px;
}


/* =========================
   MODAL TEXT
========================= */

.modal-content h3 {
    font-size: 14px;

    font-weight: normal;

    margin: 0 0 5px;
}


.modal-content>p {
    margin: 0 0 20px;
}


/* =========================
   TEMPLATE DETAILS
========================= */

.template-details {
    border-top: 1px solid black;

    border-bottom: 1px solid black;

    padding: 12px 0;

    margin-bottom: 20px;

    display: flex;

    flex-direction: column;

    gap: 6px;
}


.template-details div {
    display: flex;

    justify-content: space-between;

    align-items: center;
}


.template-details span {
    font-size: 11px;

    color: #666;
}


.template-details strong {
    font-size: 12px;

    font-weight: normal;
}


/* =========================
   MODAL ACTIONS
========================= */

.modal-actions {
    display: flex;

    gap: 15px;
}


.modal-actions button {
    border: 1px solid black;

    background: white;

    padding: 8px 14px;

    font-family: inherit;

    font-size: 14px;

    cursor: pointer;
}


.modal-actions button:hover {
    background: black;

    color: white;
}

/* =========================
   HEADER TOOLS
========================= */

.header-tools {
    display: flex;

    align-items: center;

    gap: 15px;
}


.tools-button {
    border: none;

    background: none;

    padding: 0;

    font-family: inherit;

    font-size: 14px;

    color: black;

    cursor: pointer;
}


.tools-button:hover {
    text-decoration: underline;
}


/* =========================
   TOOLS MODAL
========================= */

.tools-modal {
    position: fixed;

    inset: 0;

    background: rgba(255, 255, 255, 0.9);

    display: flex;

    align-items: center;

    justify-content: center;

    padding: 20px;

    z-index: 2000;
}


.tools-modal.hidden {
    display: none;
}


.tools-modal-content {
    position: relative;

    width: 100%;

    max-width: 700px; 

    border: 1px solid black;

    background: white;

    padding: 25px;
}


.tools-modal-close {
    position: absolute;

    top: 8px;

    right: 12px;

    border: none;

    background: none;

    font-family: inherit;

    font-size: 20px;

    cursor: pointer;
}


/* =========================
   TOOLS CONTAINER
========================= */

.tools-container {
    display: grid;

    grid-template-columns: 1fr 230px;

    gap: 25px;

    margin-top: 10px;
}


.sketch-section h3,
.calculator-section h3 {
    font-size: 13px;

    font-weight: normal;

    margin: 0 0 12px;
}


/* =========================
   SKETCH PAD
========================= */

#sketchPad {
    width: 100%;

    height: 300px;

    border: 1px solid black;

    resize: none;

    outline: none;

    padding: 12px;

    font-family: "Courier New", monospace;

    font-size: 14px;

    color: black;

    background: white;
}


#sketchPad:focus {
    outline: none;
}


.clear-notes {
    margin-top: 10px;

    border: 1px solid black;

    background: white;

    padding: 7px 12px;

    font-family: inherit;

    font-size: 12px;

    cursor: pointer;
}


.clear-notes:hover {
    background: black;

    color: white;
}


/* =========================
   CALCULATOR
========================= */

.calculator {
    border: 1px solid black;

    padding: 10px;
}


#calculatorDisplay {
    width: 100%;

    height: 45px;

    border: 1px solid black;

    outline: none;

    margin-bottom: 10px;

    padding: 5px;

    text-align: right;

    font-family: inherit;

    font-size: 18px;

    background: white;

    color: black;
}


.calculator-buttons {
    display: grid;

    grid-template-columns: repeat(4, 1fr);

    gap: 5px;
}


.calculator-buttons button {
    height: 40px;

    border: 1px solid black;

    background: white;

    font-family: inherit;

    font-size: 14px;

    cursor: pointer;
}


.calculator-buttons button:hover {
    background: black;

    color: white;
}


.calculator-buttons .equals {
    grid-column: span 2;
}

/* =========================
   CALCULATOR HISTORY
========================= */

.calculator-history {

    margin-top: 15px;

    border-top: 1px solid black;

    padding-top: 10px;

    transition:
        max-height 0.2s ease,
        transform 0.2s ease;

}


.history-header {

    display: flex;

    align-items: center;

    justify-content: space-between;

    margin-bottom: 6px;

}


.history-header span {

    font-size: 10px;

    color: #666;

    letter-spacing: 0.5px;

}


.history-header button {

    border: 1px solid black;

    background: white;

    color: black;

    padding: 4px 7px;

    font-family: inherit;

    font-size: 9px;

    cursor: pointer;

}


.history-header button:hover {

    background: black;

    color: white;

}


/* =========================
   LATEST HISTORY
========================= */

.latest-history {

    border: 1px solid #ddd;

    padding: 8px;

    font-size: 11px;

    cursor: pointer;

    white-space: nowrap;

    overflow: hidden;

    text-overflow: ellipsis;

}


.latest-history:hover {

    border-color: black;

}


/* =========================
   FULL HISTORY
========================= */

.history-list {

    display: none;

    height: 180px;

    overflow-y: auto;

    overflow-x: hidden;

    margin-top: 8px;

    border: 1px solid black;

}


/* =========================
   SCROLLBAR
========================= */

.history-list::-webkit-scrollbar {

    width: 6px;

}


.history-list::-webkit-scrollbar-track {

    background: #f5f5f5;

}


.history-list::-webkit-scrollbar-thumb {

    background: #999;

}


.history-list::-webkit-scrollbar-thumb:hover {

    background: black;

}


/* EXPANDED */

.calculator-history.expanded {

    position: relative;

    z-index: 20;

}


.calculator-history.expanded .latest-history {

    display: none;

}


.calculator-history.expanded .history-list {

    display: block;

}


.history-item {

    display: flex;

    align-items: center;

    justify-content: space-between;

    gap: 10px;

    border-bottom: 1px solid #ddd;

    padding: 8px;

    cursor: pointer;

    background: white;

}


.history-item:last-child {

    border-bottom: none;

}


.history-item:hover {

    background: #f5f5f5;

}


.history-expression {

    font-size: 11px;

    color: #555;

    overflow: hidden;

    text-overflow: ellipsis;

    white-space: nowrap;

}


.history-result {

    font-size: 12px;

    font-weight: bold;

    white-space: nowrap;

}


.history-empty {

    font-size: 10px;

    color: #999;

    padding: 8px;

}


/* =========================
   MOBILE
========================= */

@media (max-width: 600px) {

    .history-list {

        max-height: 140px;

    }

}




/* =========================
   MOBILE
========================= */

@media (max-width: 600px) {

    .header-tools {
        gap: 8px;
    }


    .tools-button {
        font-size: 12px;
    }


    .search input {
        width: 80px;
    }


    .tools-modal-content {
        padding: 20px;
    }


    .tools-container {
        grid-template-columns: 1fr;

        gap: 20px;
    }


    #sketchPad {
        height: 220px;
    }

}


/* =========================
   MOBILE
========================= */

@media (max-width: 600px) {

    .container {
        width: 100%;

        margin: 0;

        border-left: none;

        border-right: none;
    }


    header {
        padding: 0 12px;
    }


    .intro {
        padding: 30px 15px 20px;
    }


    .categories,
    .templates-section {
        padding-left: 15px;

        padding-right: 15px;
    }


    .category-grid {
        grid-template-columns: repeat(2, 1fr);

        row-gap: 5px;
    }


    .template-grid {
        gap: 20px 15px;
    }


    .template-card {
        width: calc(50% - 8px);

        max-width: 110px;
    }


    .modal-content {
        padding: 20px;
    }


    .modal-preview {
        height: 250px;
    }

}