
/* #region APP ----------------------------- */

:root {
    --gallery-scrollbar-space: 16px;

    --gray-section: #f7f7f7;
    --gray-tag: #e8e8e8;
    --gray-button: #808080;
}

* {
    box-sizing: border-box;
}

.page {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

body {
    margin: 0;
    background: #f3f3f3;
    color: #171717;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
}

h2 {
    font-size: 26px;
    margin: 10px 0 10px;
}

h3 {
    font-size: 18px;
    margin: 10px 0 4px;
    text-align: left;
}

p {
    line-height: 1.4;
    margin-top: 0;
    margin-bottom: 0;
    text-align: left;
}

.text-center {
    text-align: center;
}

.text-link {
    overflow-wrap: anywhere;
    word-break: break-all;
}

label {
    display: block;
    font-weight: 600;
    text-align: left;
}

.button {
    display: inline-block;
    background: var(--gray-button);
    color: white;
    border: 0;
    border-radius: 22px;
    padding: 13px 20px;
    text-decoration: none;
    font: inherit;
    font-size: 15px;
    font-weight: 650;
    cursor: pointer;
    text-align: center;
    height: 44px;
}

.hidden {
    display: none !important;
}

/* #endregion */
/* #region CARD ---------------------------- */

.card {
    position: relative;
    flex: 0 1 700px;
    width: 100%;
    min-width: 0;
    max-width: 700px;
    padding: 20px;
    background: white;
    border-radius: 24px;
    box-shadow: 0 12px 40px #0000000d;
    text-align: center;
    display: flex;
    flex-direction: column;
}

.card-footer {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-top: 16px;
    padding: 0;
    flex-shrink: 0;
    gap: 8px;
}

.card-footer p {
    margin: 0;
    font-size: 12px;
    color: #777;
    margin-bottom: 4px;
}

.card-footer .form-row img {
    width: auto;
    height: 36px;
    border-radius: 15px;
}

/* #endregion */
/* #region IDs ----------------------------- */

#claim {
    text-transform: uppercase;
    letter-spacing: .12em;
    font-size: 12px;
    text-align: center;
}

#giftUrl {
    margin-top: 10px;
    margin-bottom: 10px;
}

.info-button {
    flex: 0 0 80px;
    width: 80px;
}

/* Ergebnis-Buttons: Laden | Teilen | Info */

#resultButtons {
    display: flex;
    gap: 8px;
}

#resultButtons #loadLink,
#resultButtons #shareLink {
    flex: 1 1 0;
    min-width: 0;
}

#resultButtons .info-button {
    flex: 0 0 80px;
    width: 80px;
}

/* #endregion */
/* #region MEDIA --------------------------- */

.mouse-only {
    display: none;
}

@media (hover: hover) and (pointer: fine) {
    .mouse-only {
        display: inline;
    }
}

@media (max-width: 700px) {
    .card {
        padding: 22px 16px;
    }

    .page {
        padding: 10px;
    }

    /* Formularfelder untereinander */
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    /* Footer-Buttons immer nebeneinander */
    .card-footer .form-row {
        flex-direction: row;
        justify-content: center;
        gap: 16px;
    }

    .form-group {
        width: 100%;
    }
}

/* #endregion */
/* #region FORM ---------------------------- */

form {
    text-align: left;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-top: 20px;
    min-width: 0;
}

form .button {
    width: 100%;
}

.form-group {
    flex: 1;
    margin-bottom: 0;
    min-width: 0;
}

.form-group > label {
    margin-bottom: 8px;
}

.form-group input,
.form-group select {
    width: 100%;
    max-width: 100%;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    padding: 10px 12px;
    font: inherit;
    color: #000;
    accent-color: #000;
}

.form-group input[type="datetime-local"] {
    display: block;
    min-width: 0;
    width: 100%;
    text-align: left;
    -webkit-appearance: none;
    appearance: none;
    height: 44px;
    max-height: 44px;
}

.form-group input[type="datetime-local"]::-webkit-date-and-time-value {
    text-align: left;
}

.form-group.file-drop-zone {
    border: 1px dashed transparent;
    border-radius: 12px;
    transition: border-color 0.2s, background-color 0.2s;
}

.form-group.file-drop-zone.drag-over {
    border-color: #777;
    background-color: #f0f0f0;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

#formStatus {
    overflow-wrap: anywhere;
}

#formStatus:empty {
    display: none;
}

/* #endregion */
/* #region TAG GALLERY --------------------- */

.tag-gallery {
    display: flex;
    flex-direction: row;
    gap: 10px;
    height: calc(36px + var(--gallery-scrollbar-space));
    width: 100%;
    padding: 0;
    margin-bottom: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}

.tag-gallery-item {
    flex: 0 0 auto;
    height: 36px;
    padding: 0 15px;
    border: 0;
    border-radius: 18px;
    background: var(--gray-tag);
    color: var(--gray-button);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.tag-gallery-item.selected {
    background: var(--gray-button);
    color: white;
}

/* #endregion */
/* #region TOP GALLERY --------------------- */

.top-gallery {
    display: flex;
    flex-direction: row;
    gap: 10px;
    height: calc(120px + var(--gallery-scrollbar-space));
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}

.top-gallery-item {
    flex: 0 0 120px;
    height: 120px;
    padding: 0;
    border: 3px solid transparent;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
    scroll-snap-align: start;
}

.top-gallery-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 5px; /* 3px border berücksichtigen */
}

.top-gallery-item.selected {
    border-color: var(--gray-button);
}

.top-gallery-item:focus-visible {
    outline: 2px solid var(--gray-button);
    outline-offset: 2px;
}

/* #endregion */
/* #region INPUT --------------------------- */

input,
select {
    height: 44px;
}

input,
textarea,
select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font: inherit;
    background: white;
}

input {
    padding: 10px;
}

/* #endregion */
/* #region UPLOAD -------------------------- */

.upload-preview {
    display: block;
    width: 100%;
    max-height: 240px;
    margin-top: 8px;
    object-fit: contain;
    border-radius: 12px;
    background: transparent;
}

/* #endregion */
/* #region IMAGE BUTTON -------------------- */

.image-button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    align-self: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    border: 1px solid var(--gray-button);
    background: var(--gray-button);
}

.image-button img {
    width: 20px;
    height: 20px;
    object-fit: scale-down;
    filter: invert(1);
}

/* #endregion */
/* #region SCRATCH ------------------------- */

.scratch-wrap {
    position: relative;
    overflow: hidden;
    border: 1px solid #ddd;
    border-radius: 24px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.scratch-background {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    z-index: 0;
}

#scratchCanvas {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    height: auto;
    touch-action: none;
    cursor: pointer;
}

.scratch-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffffdd;
}

.scratch-again-wrapper.hidden {
    display: none;
}

.scratch-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 21px;
}

#scratchProgressTrack {
    flex: 1;
    height: 10px;
    background: #e0e0e0;
    border-radius: 5px;
    overflow: hidden;
}

.scratch-progress-fill {
    width: 0;
    height: 100%;
    background: red;
    border-radius: inherit;
    transition: width 0.15s ease-out;
}

#scratchProgressPercent {
    flex: 0 0 42px;
    text-align: right;
    font-size: 13px;
}

/* #endregion */
/* #region RESULT -------------------------- */

#result {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.result-image {
    display: block;
    width: 100%;
    max-width: 650px;
    height: auto;
    margin: 20px auto;
    border-radius: 24px;
}

.result-buttons {
    display: grid;
    gap: 12px;
    width: 100%;
    margin-top: 20px;
}

.result-buttons.columns-1 {
    grid-template-columns: 1fr;
}

.result-buttons.columns-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.result-buttons.columns-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.result-buttons.columns-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.result-buttons .button {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 12px 4px;
    text-align: center;
    white-space: nowrap;
}

/* #endregion */
/* #region RESULT GALLERY ------------------ */

/* Ergebnisgalerie */
#resultGallery {
    display: flex;
    flex-direction: row;
    gap: 10px;
    height: calc(142px + var(--gallery-scrollbar-space));
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}

/* Items mit 10 px Innenabstand */
.result-gallery-item {
    display: flex;
    flex: 0 0 120px;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    height: 142px;
    padding: 7px;
    border: 3px solid transparent;
    border-radius: 8px;
    background: #f2f2f2;
    cursor: pointer;
    overflow: hidden;
    scroll-snap-align: start;
    text-align: left;
}

/* Auswahlrahmen */
.result-gallery-item.selected {
    border-color: var(--gray-button)333;
}

.result-gallery-item:focus-visible {
    outline: 2px solid var(--gray-button);
    outline-offset: 2px;
}

/* Einheitliche Beschriftung */
.result-gallery-caption {
    display: block;
    flex: 0 0 18px;
    width: 100%;
    overflow: hidden;
    font-size: 13px;
    line-height: 18px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: black;
}

/* Zweizeilige Beschriftungen für Link und Kurzcode */
.result-gallery-caption-multiline {
    flex: 0 0 28px;
    height: 28px;
    white-space: pre-line;
    line-height: 14px;
    display: block;
    text-align: left;
    padding-top: 0;
}

/* Inhaltsbereich: 100 × 100 px */
.result-gallery-body {
    position: relative;
    flex: 0 0 100px;
    width: 100px;
    height: 100px;
    min-width: 100px;
    min-height: 100px;
    overflow: hidden;
}

/* Link und Kurzcode */
.result-gallery-text {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    width: 100px;
    height: 100px;
    padding: 4px;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: left;
    font-size: 11px;
    line-height: 1.4;
    color: black;
}

/* Erstes und zweites Galeriebild identisch skalieren */
.result-gallery-body > img,
.result-gallery-top-image > img.result-gallery-main-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100px;
    max-height: 100px;
    object-fit: contain;
    border-radius: 8px;
}

/* Fertiges Rubbelbild mit QR-Code */
.result-gallery-composite-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100px;
    max-height: 100px;
    object-fit: contain;
    border-radius: 8px;
}

/* Beseitigt iPhone-Refresh-Problem */
.result-gallery-body > img {
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden; 
}

.code-error {
    color: #d93025;
}

.clipboard-helper {
    position: fixed;
    opacity: 0;
}

/* #endregion */
/* #region IMAGE VIEWER -------------------- */

#imageViewer {
    margin-top: 20px;
    text-align: center;
}

#imageViewer img {
    display: block;
    width: 100%;
    max-width: 650px;
    height: auto;
    margin: 0 auto 20px;
    border-radius: 24px;
    cursor: pointer;
}

.image-viewer-hint {
    color: black;
    text-align: center;
}

/* #endregion */
/* #region CODE ---------------------------- */

/* Gemeinsame Gestaltung aller grauen Formularbereiche. */
.form-section {
    background: var(--gray-section);
    padding: 12px;
    border-radius: 12px;
    min-width: 0;
}

/* Abstand zwischen 2a (Galerie) und 2b (eigene Datei). */
.form-section:not(.advanced-options) > .form-group + .form-group {
    margin-top: 16px;
}

/* Abstand zum ersten Formularbereich */
#createForm {
    margin-top: 10px;
}

.gift-code-entry:not(.hidden) + #createForm {
    margin-top: 16px;
}


.gift-code-entry {
    margin-top: 10px;
}

.gift-code-entry form {
    margin: 0;
    gap: 0;
}

.gift-code-entry .form-bar {
    margin-top: 8px;
}

/* Eingabefeld und Öffnen-Button teilen sich den Platz */
.gift-code-entry .form-bar #giftCode,
.gift-code-entry .form-bar .button {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
}

/* Einfügen-Button: immer 44px */
.gift-code-entry .form-bar #giftCodePaste {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
}

/* #endregion */
/* #region LANGUAGE ------------------------ */

.language-buttons {
    display: flex;
    gap: 5px;
}

.language-button {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
}

/* #endregion */
/* #region HOME ---------------------------- */

.home-button {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgb(from var(--gray-button) r g b / 85%);
    color: #555;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    text-decoration: none;
    z-index: 10;
    transition: background 0.2s, transform 0.2s;
}

.home-button.floating {
    position: fixed;
    right: max(20px, calc((100vw - 700px) / 2 + 20px)); /* Breite Card */
    bottom: 20px;
    z-index: 1000;
}

.home-button:hover {
    background: var(--gray-button);
    transform: scale(1.10);
}
.home-button.floating.at-card-bottom {
    position: absolute;
    right: 20px;
    bottom: 20px;
}

.home-button img {
    width: 20px;
    height: 20px;
    object-fit: scale-down;
    filter: invert(1);
}

@media (max-width: 700px) {
    .home-button.floating {
        right: 30px;
    }

    .home-button.floating.at-card-bottom {
        right: 20px;
    }
}

/* #endregion */
/* #region INTRO --------------------------- */

.intro-dev {
    background: red;
    color: #fff;
}

.intro-dev a {
    color: #fff;
}

/* #endregion */
/* #region OPTION -------------------------- */

/* Erstellen-Button */
#createForm > .form-bar > .button {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
}

/* Optionen-Button */
form #optionButton {
    flex: 0 0 60px;
    width: 60px;
    border-radius: 22px;
}

form #optionButton img {
    display: block;
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    max-width: 20px;
    max-height: 20px;
    object-fit: contain;
    transition: transform 180ms ease;
}

form #optionButton[aria-expanded="true"] img {
    transform: rotate(180deg);
}

form #advancedOptions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

form #advancedOptions > .option-help:not(.hidden) {
    margin-top: -8px;
}

@media (prefers-reduced-motion: reduce) {
    form #optionButton img { transition: none; }
}

/* #endregion */
/* #region SHORT CODE ---------------------- */

.short-code-bar input { 
    flex: 1 1 auto; 
    min-width: 0; 
    width: 0; }

.short-code-bar .image-button { 
    flex: 0 0 44px; 
}

.option-help {
    padding: 12px;
    border-radius: 12px;
    background: #fff;
    color: #171717;
    text-align: left;
    line-height: 1.5;
    white-space: pre-line;
    scroll-margin-top: 20px;
}

.option-help p + p {
    margin-top: 10px;
}

.option-info-button.active {
    background: white;
}

.option-info-button.active img {
    filter: none;
}

@media (max-width: 390px) {
    .short-code-bar { gap: 5px; }
    .short-code-bar .image-button { flex-basis: 40px; width: 40px; height: 40px; }
}

/* Fehler beim Erstellen deutlich hervorheben */
#formStatus.form-status-error {
    color: #c62828;
    font-weight: 600;
}

#shortCode.short-code-invalid {
    border-color: #c62828;
    outline: 2px solid #c62828;
    outline-offset: 1px;
}

/* Verhindert automatischen iPhone-Zoom bei allen Eingabefeldern */
input,
textarea,
select,
.form-group input,
.form-group select,
.gift-code-entry .form-bar input,
#shortCode {
    font-size: 16px;
}

/* #endregion */
