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

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #222;
}

body.settings-open {
    overflow: hidden;
}

.settings-button {
    position: fixed;
    top: 0.7rem;
    right: 0.7rem;
    z-index: 5;
    padding: 0.35rem 0.55rem;
    border: 1px solid #71717a;
    border-radius: 0.25rem;
    background: #27272a;
    color: #d4d4d8;
    font-family: sans-serif;
    font-size: 0.72rem;
    line-height: 1rem;
    cursor: pointer;
}

.settings-button:hover,
.settings-button:focus-visible {
    background: #3f3f46;
    color: #fff;
}

/* Papier */
.receipt {
    position: relative;

    width: 400px;

    padding: 30px 25px;
    margin-top: 60px;
    margin-bottom: 20px;

    background-color: #f0f0f0;
    color: #222;

    font-family: "Space Mono", monospace;

}

.receipt-block {
    min-height: 2.1rem;
    padding: 0.35rem 0.5rem;
    outline: 1px dashed transparent;
    cursor: text;
    white-space: pre-wrap;
}

.receipt-block.is-empty {
    outline-color: #aaa;
}

.receipt-block.is-empty::before {
    content: attr(data-placeholder);
    color: #999;
    font-size: 0.72rem;
    font-weight: 400;
    letter-spacing: 0;
}

.receipt-block:focus {
    outline-color: #555;
}

.receipt-block.is-empty:not(.header):focus::before {
    display: none;
}

#toggleTime,
#toggleEmpty,
#resetBlocks,
#addImage,
#imageSettingsButton,
#imageLocationButton,
#removeImageButton {
    flex: 1 1 120px;
    padding: 0.5rem 0.75rem;
    border: 1px solid #3f3f46;
    border-radius: 0.375rem;
    background: transparent;
    color: #f4f4f5;
    font-family: sans-serif;
    font-size: 0.875rem;
    line-height: 1.25rem;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 150ms, border-color 150ms;
}

.receipt-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
    width: min(100%, 42rem);
    margin-top: 0.5rem;
}

.control-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.control-category {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    border: 1px solid #3f3f46;
    border-radius: 0.375rem;
    overflow: hidden;
}

.control-category summary {
    padding: 0.55rem 0.75rem;
    background: #27272a;
    color: #a1a1aa;
    font-family: sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    list-style: none;
}

.control-category summary::-webkit-details-marker {
    display: none;
}

.control-category summary::after {
    float: right;
    content: '+';
    font-size: 1rem;
    line-height: 0.8;
}

.control-category[open] summary::after {
    content: '\2212';
}

.control-category > .control-group {
    padding: 0.55rem;
}

.image-controls {
    border-top: 1px solid #3f3f46;
}

#printBlocks {
    display: block;
    margin: 1.5rem auto 0;
    padding: 0.7rem 1.75rem;
    border: 2px solid #f4f4f5;
    border-radius: 0.375rem;
    background: #f4f4f5;
    color: #222;
    font-family: sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.25rem;
    cursor: pointer;
    box-shadow: 0 2px 0 #a1a1aa;
    transition: background-color 150ms, border-color 150ms, box-shadow 150ms, transform 150ms;
}

#toggleEmpty,
 #resetBlocks,
#addImage,
#imageSettingsButton,
#imageLocationButton,
#removeImageButton {
    position: static;
}

#toggleTime:hover,
#toggleEmpty:hover,
#resetBlocks:hover,
#addImage:hover,
#imageSettingsButton:hover,
#imageLocationButton:hover,
#removeImageButton:hover {
    background: #27272a;
    border-color: #71717a;
}

#printBlocks:hover {
    background: #fff;
    border-color: #fff;
    box-shadow: 0 2px 0 #d4d4d8;
}

#toggleTime:focus-visible,
#printBlocks:focus-visible,
#toggleEmpty:focus-visible,
#resetBlocks:focus-visible,
#addImage:focus-visible,
#imageSettingsButton:focus-visible,
#imageLocationButton:focus-visible,
#removeImageButton:focus-visible {
    outline: 2px solid #a1a1aa;
    outline-offset: 2px;
}

#printBlocks:active {
    transform: translateY(2px);
    box-shadow: none;
}

#printBlocks:disabled {
    opacity: 0.5;
    cursor: wait;
}

#printBlocks.is-loading {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    opacity: 1;
}

#printBlocks.is-loading::after {
    width: 0.9rem;
    height: 0.9rem;
    border: 2px solid rgba(34, 34, 34, 0.25);
    border-top-color: #222;
    border-radius: 50%;
    content: '';
    animation: print-spinner 700ms linear infinite;
}

#printStatus {
    min-height: 1.4rem;
    margin-top: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.6rem 0.9rem;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    color: #f0f0f0;
    text-align: center;
    font-family: sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0;
    transform: translateY(0.35rem);
}

.receipt-image-block {
    margin: 0.75rem 0;
    text-align: center;
}

.receipt-image {
    display: block;
    max-width: 100%;
    max-height: 14rem;
    margin: 0 auto;
    filter: grayscale(100%) contrast(1.1);
}

.receipt-image-caption {
    min-height: 1.5rem;
    margin-top: 0.45rem;
    padding: 0.25rem 0.5rem;
    color: #444;
    font-size: 0.78rem;
    font-style: italic;
    text-align: center;
    outline: 1px dashed transparent;
}

.receipt-image-caption:focus {
    outline-color: #777;
}

.receipt-image-caption:empty::before {
    content: attr(data-placeholder);
    color: #999;
}

.image-location-button {
    margin-top: 0.45rem;
    padding: 0.3rem 0.55rem;
    border: 1px solid #aaa;
    border-radius: 0.25rem;
    background: transparent;
    color: #555;
    cursor: pointer;
    font-size: 0.72rem;
}

.image-location-button:hover {
    background: #ddd;
}

.receipt-image-location {
    margin-top: 0.3rem;
    color: #555;
    font-size: 0.72rem;
    font-style: italic;
}

.image-settings {
    display: grid;
    gap: 0.35rem;
    margin: 0.65rem auto 0;
    max-width: 18rem;
    color: #555;
    font-family: sans-serif;
    font-size: 0.72rem;
    text-align: left;
}

.image-settings label {
    display: grid;
    gap: 0.25rem;
}

.settings-page {
    position: fixed;
    inset: 0;
    z-index: 10;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow-x: hidden;
    overflow-y: scroll;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scroll-behavior: auto;
    scrollbar-width: auto;
    padding: 1.5rem 1rem 3rem;
    padding-bottom: max(3rem, env(safe-area-inset-bottom));
    background: #222;
}

.settings-page[hidden] {
    display: none;
}

.settings-modal-content {
    width: min(100%, 42rem);
    margin: 0 auto;
    min-height: calc(100% - 1rem);
    padding: 1.25rem;
    border: 1px solid #3f3f46;
    border-radius: 0.5rem;
    background: #27272a;
    color: #f4f4f5;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.45);
    font-family: sans-serif;
}

.settings-menu-content {
    min-height: auto;
    max-width: 26rem;
}

.settings-menu-close {
    margin-top: 1rem;
}

.settings-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.settings-modal-header h2 {
    font-size: 1.1rem;
}

.settings-page-preview {
    display: block;
    width: min(100%, 32rem);
    max-height: 28rem;
    height: auto;
    margin: 1rem auto;
    background: #f0f0f0;
    object-fit: contain;
}

.settings-page-empty {
    padding: 2rem 1rem;
    color: #a1a1aa;
    text-align: center;
}

.settings-intro,
.settings-help {
    margin-top: 0.75rem;
    color: #d4d4d8;
    font-size: 0.8rem;
    line-height: 1.4;
}

.settings-page .image-settings {
    max-width: none;
    margin-top: 1rem;
    color: #f4f4f5;
}

.settings-page .image-settings label {
    padding: 0.55rem 0;
}

.settings-page .image-settings input,
.settings-page .image-settings select {
    accent-color: #a1a1aa;
}

.settings-page .image-settings small {
    color: #a1a1aa;
    font-size: 0.72rem;
    line-height: 1.35;
}

.settings-confirm {
    display: block;
    flex: 1;
    padding: 0.7rem 1rem;
    border: 1px solid #f4f4f5;
    border-radius: 0.375rem;
    background: #f4f4f5;
    color: #222;
    font-family: sans-serif;
    font-weight: 700;
    cursor: pointer;
}

.settings-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

.settings-cancel {
    flex: 0 0 auto;
    padding: 0.7rem 1rem;
    border: 1px solid #71717a;
    border-radius: 0.375rem;
    background: transparent;
    color: #f4f4f5;
    font-family: sans-serif;
    cursor: pointer;
}

.settings-cancel:hover {
    background: #3f3f46;
}

.api-key-field {
    display: grid;
    gap: 0.45rem;
    color: #d4d4d8;
    font-family: sans-serif;
    font-size: 0.85rem;
}

.api-key-field input {
    width: 100%;
    padding: 0.7rem 0.75rem;
    border: 1px solid #71717a;
    border-radius: 0.375rem;
    background: #18181b;
    color: #f4f4f5;
    font: inherit;
}

.api-key-input-row {
    position: relative;
    display: flex;
    gap: 0.45rem;
}

.api-key-last-character {
    position: absolute;
    top: 0.7rem;
    z-index: 1;
    display: none;
    padding: 0 0.05rem;
    background: #18181b;
    color: #f4f4f5;
    font: inherit;
    line-height: 1.2;
    pointer-events: none;
}

.api-key-visibility {
    flex: 0 0 auto;
    padding: 0.7rem 0.75rem;
    border: 1px solid #71717a;
    border-radius: 0.375rem;
    background: #3f3f46;
    color: #f4f4f5;
    font: inherit;
    cursor: pointer;
}

.api-key-visibility:hover,
.api-key-visibility:focus-visible {
    background: #52525b;
}

.api-key-field input:focus-visible {
    outline: 2px solid #a1a1aa;
    outline-offset: 2px;
}

.api-key-modal-content .settings-page-empty {
    min-height: 1.2rem;
    margin-top: 0.75rem;
}

.settings-confirm:hover {
    background: #fff;
}

.settings-reset-link {
    display: block;
    margin: 0.65rem auto 0;
    border: 0;
    background: transparent;
    color: #a1a1aa;
    font-family: sans-serif;
    font-size: 0.8rem;
    text-decoration: underline;
    cursor: pointer;
}

.settings-reset-link:hover {
    color: #f4f4f5;
}

.image-settings input,
.image-settings select {
    min-width: 0;
    width: 100%;
}

.remove-image {
    margin-top: 0.4rem;
    border: 0;
    background: transparent;
    color: #777;
    cursor: pointer;
    font-size: 0.72rem;
    text-decoration: underline;
}

.remove-image:hover {
    color: #222;
}

#printStatus.is-visible {
    animation: print-status-in 420ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

#printStatus.success {
    color: #8ee6a8;
    border-color: rgba(142, 230, 168, 0.45);
    background: rgba(49, 112, 70, 0.25);
    box-shadow: 0 0 1rem rgba(142, 230, 168, 0.12);
}

#printStatus.error {
    color: #ff9999;
    border-color: rgba(255, 153, 153, 0.45);
    background: rgba(130, 53, 53, 0.25);
    box-shadow: 0 0 1rem rgba(255, 153, 153, 0.1);
}

@keyframes print-status-in {
    0% {
        opacity: 0;
        transform: translateY(0.35rem) scale(0.98);
    }

    60% {
        opacity: 1;
        transform: translateY(-0.05rem) scale(1.01);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes print-spinner {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    #printStatus.is-visible {
        animation: none;
        opacity: 1;
        transform: none;
    }

    #printBlocks.is-loading::after {
        animation: none;
    }
}

/* Découpe du haut du papier */
.receipt::before {
    content: "";

    position: absolute;

    top: -5px;
    left: 0;

    width: 100%;
    height: 6px;

    background:
        linear-gradient(
            45deg,
            transparent 33.333%,
            #f0f0f0 33.333%,
            #f0f0f0 66.667%,
            transparent 66.667%
        ),
        linear-gradient(
            -45deg,
            transparent 33.333%,
            #f0f0f0 33.333%,
            #f0f0f0 66.667%,
            transparent 66.667%
        );

    background-size: 10px 12px;

    filter: drop-shadow(
        0 -1px 1px rgba(0, 0, 0, 0.05)
    );
}

.header {
    text-align: center;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.header:not(.is-empty)::before,
.header:not(.is-empty)::after {
    display: block;
    content: "================================";
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0;
}

.header:not(.is-empty)::before {
    margin-bottom: 0.45rem;
}

.header:not(.is-empty)::after {
    margin-top: 0.45rem;
}

.meta {
    text-align: center;
    font-size: 0.75rem;
    color: #555;

    margin-top:20px;
    margin-bottom: 15px;
    padding-bottom: 10px;

    border-top: 1px dashed #aaa;
    cursor: pointer;
}

.meta.is-hidden {
    min-height: 1px;
    margin-top: 0;
    margin-bottom: 0;
    padding-bottom: 0;
    border-top-color: transparent;
}

.quote {
    font-size: 1rem;
    line-height: 1.4;
    font-weight: 700;
}

.attribution {
    margin-top: 15px;
    text-align: right;
    font-size: 0.8rem;
    font-style: italic;
    color: #444;
}

.attribution:not(.is-empty)::before {
    content: attr(data-author-prefix);
}

.receipt-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1rem;
}

@media (max-width: 480px) {
    body {
        padding-left: 12px;
        padding-right: 12px;
    }

    .receipt-wrapper {
        width: 100%;
    }

    .receipt {
        width: 100%;
        max-width: 400px;
    }
}

@media (max-width: 600px) {
    body.settings-open {
        display: block;
        overflow-y: auto;
    }

    body.settings-open .settings-button {
        display: none;
    }

    body.settings-open .receipt-wrapper,
    body.settings-open #printBlocks,
    body.settings-open #printStatus {
        display: none;
    }

    body.settings-open .settings-page {
        position: static;
        width: 100%;
        min-height: 100dvh;
        height: auto;
        max-height: none;
        overflow: visible;
        overscroll-behavior: auto;
        touch-action: auto;
        padding: 1rem 4px max(3rem, env(safe-area-inset-bottom));
    }

    body.settings-open .settings-modal-content {
        width: 100%;
    }
}
