/* Základní styly */
body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    color: #333;
    flex-direction: column;
    background-color: #d6d6d6; /* Trochu tmavá pro rozeznání plátna */
}

img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  user-select: none;
}

/* --- Styly pro kreslící plátno --- */
#drawing-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* z-index: 10; 
      Je nad pozadím (z-index: 1), 
      ale pod horní lištou (z-index: 1000) 
    */
    z-index: 10;
    cursor: crosshair;
    /* Začíná neaktivní, aby neblokoval klikání.
      Aktivuje se až výběrem nástroje.
    */
    pointer-events: none; 
}

.hidden {
    display: none !important;
}

/* Varování pro otočení */
#rotate-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: #ffc;
    border-bottom: 2px solid #e6db55;
    padding: 15px;
    text-align: center;
    font-weight: bold;
    z-index: 2000;
    box-sizing: border-box;
    font-size: clamp(0.85em, 4.5vw, 1em);
}

@media (orientation: portrait) {
    #rotate-warning {
        display: block;
    }
    body {
        padding-top: 60px !important;
    }
    #top-ui-container {
        top: 50px !important;
    }

    #background-container, #drawing-area {
        /* Výpočet:
          Toolbar 'top' (50px) + padding (10px) + výška (44px) + padding (10px) = 114px.
          + 20px symetrický margin = 134px.
        */
        top: 134px !important;
    }
}

#info-text {
    position: fixed;
    bottom: 5px;
    right: 5px;
    font-size: 60%;
    color: #888;
    z-index: 1000000;
    text-decoration: underline;
    cursor: pointer;
}

/* Horní UI */
#top-ui-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px;
    display: flex;
    justify-content: center;
    box-sizing: border-box;
    z-index: 1000;
    transition: top 0.3s ease;
}

#ui-group {
    display: flex;
    width: 90%;
    gap: 10px;
    align-items: center;
}

/* Lišta pro hlavní nástroje */
#main-toolbar {
    flex-grow: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    padding: 0 8px;
    height: 44px;
    box-sizing: border-box;
    color: #555;
    min-width: 560px;
}

/* Styl pro samostatná tlačítka (Projekty, Šablony, Hřiště) */
.toolbar-btn {
    font-family: Arial, sans-serif;
    font-size: 1em;
    font-weight: bold;
    color: #333;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    height: 44px;
    padding: 0 15px;
    box-sizing: border-box;
}

.toolbar-btn:hover {
    background-color: rgba(230, 230, 230, 0.9);
}

@media (pointer: coarse) {
  .toolbar-btn:hover {
    background-color: rgba(255, 255, 255, 0.9);
  }
}

/* --- Styly pro tlačítka nástrojů --- */
.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background-color: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 0;
    flex-shrink: 0;
}

.tool-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

@media (pointer: coarse) {
    .tool-btn:hover {
        background-color: transparent;
    }
}

.tool-btn img {
    width: 20px;
    height: 20px;
    display: block;
    filter: none; /* Zajistí, že ikony jsou černé (výchozí) */
    transition: filter 0.2s;
}

#tool-pen.active,
#tool-line.active,
#tool-eraser.active {
    background-color: #7ed0ec;
}

#tool-lock.active {
    background-color: #007bff;
}

/* Invert ikony pro aktivní nástroje */
#tool-lock.active img {
    filter: invert(100%) brightness(200%);
}

/* Speciální styl pro tlačítko přehrávání */
.tool-btn.active-play {
    background-color: #28a745; /* Zelená */
}
.tool-btn.active-play img {
    filter: invert(100%) brightness(200%); /* Bílá ikona */
}

/* Oddělovač v liště */
.toolbar-divider {
    width: 1px;
    height: 24px;
    background-color: #ccc;
    margin: 0 4px;
    flex-shrink: 0;
}

/* --- Styly pro samolepky --- */
#recent-stickers-container {
    flex-grow: 1; /* Zabere volné místo */
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px;
    overflow: hidden; /* Skryje samolepky, co se nevejdou */
    flex-shrink: 1;  /* Dovolí kontejneru se smrštit */
    flex-basis: 0;   /* Jeho základní šířka je 0 (roste jen, když je místo) */
    min-width: 0;    /* Klíčové: Dovolí mu smrštit se pod šířku jeho obsahu */
}

.sticker-preview {
    width: 30px;
    height: 30px;
    object-fit: contain;
    background-color: #fff;
    border-radius: 4px;
    border: 1px solid #ddd;
    cursor: pointer; /* Bude se na to klikat */
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.sticker-preview:hover {
    transform: scale(1.1);
    border-color: #007bff;
}

@media (pointer: coarse) {
    .sticker-preview:hover {
        transform: none;
        border-color: #ddd;
    }
}

/* Mřížka v popupu pro samolepky */
.sticker-grid {
    grid-template-columns: repeat(4, 1fr); /* 4 sloupce */
}

.sticker-grid .grid-item img {
    aspect-ratio: 1 / 1; /* Čtvercové */
}

/* Fullscreen tlačítko */
#fullscreen-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.3s;
}

#fullscreen-btn:hover {
    background-color: rgba(230, 230, 230, 0.9);
}

@media (pointer: coarse) {
    #fullscreen-btn:hover {
        background-color: rgba(255, 255, 255, 0.9);
    }
}

#fullscreen-btn img {
    width: 24px;
    height: 24px;
    display: block;
}


/* --- Styly pro Popup (Modální okna) --- */
#popup-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999998;
    transition: opacity 0.3s ease;
}

.popup-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 9999999;
    width: 80%;
    max-width: 80%;
    height: auto;
    max-height: 90%;
    display: flex;
    flex-direction: column;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
}

.popup-header h2 {
    margin: 0;
    font-size: 1.3em;
}

.popup-close-btn {
    font-size: 1.8rem;
    font-weight: bold;
    color: #888;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}
.popup-close-btn:hover {
    color: #000;
}
@media (pointer: coarse) {
    .popup-close-btn:hover {
        color: #888;
    }
}

.popup-content {
    padding: 20px;
    overflow-y: auto;
}

.popup-content h3 {
    margin-top: 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

#stickers-popup.popup-window {
    background-color: transparent;
    box-shadow: none;
    overflow: visible;
    max-height: 90vh;
}

#stickers-popup .popup-header {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    margin-bottom: 10px;
}

#stickers-popup .popup-content {
    padding: 0;
    overflow: auto;
    max-height: 90vh;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.sticker-grid.image-grid {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 15px;
    padding: 10px;
    max-height: none;
}

.sticker-grid .grid-item {
    background-color: transparent;
    border: none;
    border-radius: 8px;
}

/* Obrázek samolepky uvnitř mřížky */
.sticker-grid .grid-item img {
    aspect-ratio: 1 / 1;
    object-fit: contain;
    background-color: transparent;
    padding: 0; /* Bez paddingu */
    width: 100%;
    transition: transform 0.2s ease;
}

/* Text pod samolepkou */
.sticker-grid .grid-item-text {
    font-size: 0.8em;
    padding-top: 4px;
}

.sticker-grid .grid-item:hover {
    background-color: rgba(230, 230, 230, 0.5);
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.sticker-grid .grid-item.selected {
    border-color: transparent;
    background-color: rgba(230, 230, 230, 0.5);
}

/* Seznam projektů/šablon */
.item-list {
    list-style: none;
    padding: 0;
    margin: 0 0 25px 0;
    max-height: 300px;
    overflow-y: auto;
}

.item-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background-color: #f7f7f7;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 8px;
}

.item-list li a:hover {
    background-color: #e9e9e9;
    border-color: #ccc;
}

@media (pointer: coarse) {
    .item-list li a:hover {
        background-color: #f7f7f7;
        border-color: #ddd;
    }
}

.save-section {
    display: flex;
    gap: 10px;
}

.save-section input[type="text"] {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
}

.btn-primary {
    color: white;
    border: none;
    padding: 10px 15px;
    font-size: 1em;
    font-weight: bold;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}


/* --- Styly pro mřížku hřišť --- */
.image-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    overflow-y: auto;
    padding: 5px;
}

.grid-item {
    background-color: #f0f0f0;
    border: 2px solid transparent;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
}

.grid-item img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: contain;
    background-color: #ffffff;
    padding: 10px;
    box-sizing: border-box;
}

.grid-item:hover {
    background-color: #e0e0e0;
    border-color: #ccc;
}

@media (pointer: coarse) {
    .grid-item:hover {
        background-color: #f0f0f0;
        border-color: transparent;
    }
}

.grid-item.selected {
    border-color: #007bff;
    background-color: #e6f2ff;
}

.grid-item-text {
    font-size: 0.9em;
    color: #333;
    font-weight: bold;
    text-align: center;
    padding: 8px;
}

/* --- Styly pro kontejner pozadí --- */
#background-container {
    position: fixed;
    /* Výpočet 'top':
      Toolbar padding (10px) + výška (44px) + padding (10px) = 64px.
    */
    top: 64px;
    bottom: 10px;
    left: 10px;
    right: 10px;

    display: flex;
    justify-content: center;
    z-index: 1;
    transition: top 0.3s ease, opacity 0.3s ease-in-out;
}

#background-container.hidden {
    opacity: 0;
    pointer-events: none;
}

#background-svg {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    background-color: transparent;
}

/* --- Styly pro Dropdown menu --- */
.dropdown-menu {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 1100; /* Nad horní lištou */
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    backdrop-filter: blur(5px); /* Efekt rozostřeného pozadí */
}

.dropdown-btn {
    font-family: Arial, sans-serif;
    font-size: 1em;
    font-weight: bold;
    color: #333;
    background-color: transparent;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center; /* Pro PNG/GIF ikony */
    text-align: left;
    transition: background-color 0.2s;
}
.dropdown-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
}
@media (pointer: coarse) {
    .dropdown-btn:hover {
        background-color: transparent;
    }
}
.dropdown-btn img {
    height: 44px; /* Výška pro PNG/GIF textové ikony */
}


/* --- Styly pro responzivní menu --- */
.responsive-menu-btn {
    display: none; /* Skryté na velkých obrazovkách */
}

@media (max-width: 1200px) {
    .responsive-hide {
        display: none; /* Skryje "Projekty", "Šablony", "Hřiště" */
    }
    .responsive-menu-btn {
        display: flex; /* Zobrazí "Menu" tlačítko */
        width: 44px; /* Stejné jako fullscreen */
        height: 44px;
        padding: 0;
        justify-content: center;
    }
    .responsive-menu-btn img {
        width: 24px;
    }
    /* Upraví tlačítka v menu, aby měla text vlevo */
    #menu-dropdown .dropdown-btn {
        justify-content: flex-start;
        min-width: 150px;
    }
}

/* --- Vrstva pro samolepky --- */
#drawing-area {
    /* Kopírujeme pozici z #background-container, ale dáváme vyšší z-index */
    position: fixed;
    top: 64px;
    bottom: 10px;
    left: 10px;
    right: 10px;
    z-index: 10;
    overflow: hidden;

    display: flex;
    justify-content: center;
    align-items: center;

    transition: top 0.3s ease;
}

/* Kontejner pro samolepky */
#sticker-layer {
    position: relative;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    flex-shrink: 0;
}

/* Samotná samolepka - Wrapper pro manipulaci */
.board-sticker {
    position: absolute;
    cursor: grab;
    z-index: 10;
    aspect-ratio: 1 / 1;
}

.board-sticker:active {
    cursor: grabbing;
}

/* Vizuální zpětná vazba pro vybranou samolepku */
.board-sticker.selected {
    outline: 2px dashed #007bff;
    outline-offset: 5px;
    z-index: 100;
}

/* Obrázek samolepky uvnitř wrapperu */
.board-sticker-image {
    width: 100%;
    height: 100%;
    user-select: none;
    pointer-events: none;
    display: block;
}

/* --- Úchyty pro rotaci a změnu velikosti --- */
.sticker-handle {
    position: absolute;
    width: 24px; /* Výchozí fixní velikost (Delete, Rotate) */
    height: 24px;

    aspect-ratio: 1 / 1;
    background-color: #fff;
    border: 2px solid #007bff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    z-index: 101;
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- DYNAMICKÁ VELIKOST POUZE PRO RESIZE HANDLES --- */
.resize-handle {
    /* Přepisuje fixní 24px definované výše */
    width: clamp(24px, 12%, 40px); /* ZMĚNĚNO NA MIN 24PX pro lepší dotykovou odezvu */
    height: auto;
}

/* Zobrazit jen když je samolepka vybraná (Aplikujeme ZDE) */
.board-sticker:not(.selected) .sticker-handle {
    display: none;
}

/* --- Pozicování úchytů (Vně obrázku) --- */

/* RESIZE - Rohy */
.resize-handle.top-left {
    top: 0; left: 0;
    cursor: nwse-resize;
    transform: translate(-70%, -70%);
}
.resize-handle.top-right {
    top: 0; right: 0;
    cursor: nesw-resize;
    transform: translate(70%, -70%);
}
.resize-handle.bottom-left {
    bottom: 0; left: 0;
    cursor: nesw-resize;
    transform: translate(-70%, 70%);
}
.resize-handle.bottom-right {
    bottom: 0; right: 0;
    cursor: nwse-resize;
    transform: translate(70%, 70%);
}

/* DELETE - FIXNÍ VELIKOST, ZVĚTŠENÁ MEZERA */
.delete-handle {
    top: 0;
    right: 0;
    background-color: #dc3545;
    border-color: #fff;
    cursor: pointer;

    /* Posun: 100% (svá šířka) + 50px pevná mezera pro volný prostor */
    transform: translate(calc(100% + 20px), calc(-100% - 20px));
}

.delete-handle:after {
    content: '✕';
    color: #fff;
    font-size: 0.7em;
    font-weight: bold;
    line-height: 1;
}

/* ROTACE - FIXNÍ VELIKOST */
.rotate-left-handle,
.rotate-right-handle {
    top: 0;
    background-color: #f0f0f0;
    color: #333;
    font-size: 0.9em;
}

/* Pozice rotace: posun 100% pro ukotvení + 15px fixní mezera nahoru */
.rotate-left-handle {
    left: 30%;
    transform: translate(-50%, calc(-100% - 15px));
}
.rotate-right-handle {
    right: 30%;
    transform: translate(50%, calc(-100% - 15px));
}

/* Symboly pro rotaci */
.rotate-left-handle::after {
    content: '↶';
    font-weight: bold;
}
.rotate-right-handle::after {
    content: '↷';
    font-weight: bold;
}

/* Uzamčené samolepky */
#sticker-layer.stickers-locked .board-sticker {
    pointer-events: none;
    z-index: 9;
}

.sticker-image-container {
    width: 100%;
    height: 100%;
    transform-origin: 50% 50%;
    transform: rotate(0deg);
    transition: transform 0.1s ease-in-out;
    /*display: block;*/
}

.file-section {
    display: flex;
    gap: 10px;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 10px 15px;
    font-size: 1em;
    font-weight: bold;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}
.btn-secondary:hover {
    background-color: #5a6268;
}
@media (pointer: coarse) {
    .btn-secondary:hover {
        background-color: #6c757d;
    }
}

.item-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Nová malá tlačítka pro akce */
.btn-small {
    background-color: #f0f0f0;
    color: #333;
    border: 1px solid #ccc;
    padding: 4px 8px;
    font-size: 0.85em;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.btn-small:hover {
    background-color: #e0e0e0;
}

/* Specifická barva pro sdílení */
.btn-small.btn-share {
    background-color: #d1ecf1;
    border-color: #bee5eb;
    color: #0c5460;
}
.btn-small.btn-share:hover {
    background-color: #abdde5;
}

/* Specifická barva pro smazání */
.btn-small.btn-delete {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}
.btn-small.btn-delete:hover {
    background-color: #f1b0b7;
}

.item-list li.empty-message {
    background-color: transparent;
    border: none;
    color: #888;
    font-style: italic;
    text-align: center;
    justify-content: center;
    padding: 20px 0;
    cursor: default;
}

.delete-on-left .delete-handle {
    /* Přepíše 'right: 0' na 'left: 0' */
    right: auto !important;
    left: 0 !important;

    background-color: #dc3545; /* Zachování barvy */

    /* Vrtikální posun zůstává stejný: calc(-100% - 60px) */
    /* Horizontální posun se invertuje: z (100% + 60px) na -(100% + 60px) */
    transform: translate(calc(-100% - 20px), calc(-100% - 20px)) !important;
}

.hide-for-export {
    display: none !important;
}

#drawing-canvas {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.definice-text {
    margin-top: -15px;
    margin-bottom: 20px;
    font-size: 0.8em;
    color: #424242;
}

.share-upozorneni {
    margin-top: 5px;
    font-size: 0.8em;
    color: #555;
}

/* Malý popup s textem */
#custom-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 99999999; /* Musí být úplně nahoře */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Třída pro skrytí */
.popup-hidden {
    visibility: hidden;
    opacity: 0 !important;
    pointer-events: none;
}

/* Samotné okno */
.popup-box {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    max-width: 400px;
    width: 90%;
    text-align: center;
    font-family: sans-serif;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Animace při otevření */
.popup-hidden .popup-box {
    transform: scale(0.8);
}

/* Texty */
#popup-title {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.8rem;
    color: #121212;
}

#popup-message {
    margin-bottom: 20px;
    color: #2c2c2c;
    line-height: 1.5;
}

#popup-link {
    word-break: break-all;
    white-space: normal;
}

/* Tlačítka */
#popup-actions {
    display: flex;
    justify-content: center;
    gap: 40px;
}

.popup-btn {
    padding: 10px 40px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: background 0.2s;
}

/* Styly tlačítek */
.btn-primary { background: #007bff; color: white; }
.btn-primary:hover { background: #0056b3; }

.btn-danger { background: #f44336; color: white; }
.btn-danger:hover { background: #d32f2f; }

.btn-secondary { background: #e0e0e0; color: #333; }
.btn-secondary:hover { background: #d5d5d5; }

/* Styly pro typy oken (Chyba) */
.popup-type-error #popup-title { color: #d32f2f; }

.popup-window {
    overflow: visible !important;
}

.custom-scrollbar-track {
    position: absolute;
    top: 80px;
    bottom: 10px;
    right: -50px;
    width: 40px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    cursor: pointer;
    z-index: 99999999;
    touch-action: none;
    display: block !important;
}

.custom-scrollbar-thumb {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    /* Výchozí stav */
    height: 100%;
    background-color: #eaeaea;
    border-radius: 20px;
    cursor: grab;
    opacity: 0.9;
    transition: background-color 0.2s, opacity 0.2s;
}

.custom-scrollbar-thumb:active {
    background-color: #a6a6a6;
    cursor: grabbing;
}