@font-face {
    font-family: "CommitMono";
    src: url("https://cdn.jsdelivr.net/npm/commit-mono@1.0.0/fonts/CommitMono-400-Regular.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

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

:root {
    --text: #111;
    --bg: #aaa;
    --middle: #555;
    --border: #111;
    font-size: 16px;
}

::selection {
    color: var(--text);
    background-color: var(--middle);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "CommitMono", monospace;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 0.75rem;
    line-height: 1rem;
    min-height: 100vh;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    padding: 1rem 4ch 0 4ch;
    margin-bottom: 0;
}

@media (max-width: 1000px) {
    header {
        padding: 1rem 2ch 0 2ch;
    }
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 2rem;
}

h1 {
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: normal;
    width: fit-content;
}

h2 {
    font-size: 0.875rem;
    line-height: 1.5rem;
    font-weight: 300;
    width: fit-content;
    margin-bottom: 1rem;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 4ch 1rem 4ch;
    overflow: hidden;
}

@media (max-width: 1000px) {
    main {
        padding: 0 2ch 1rem 2ch;
    }
}

.auth-buttons {
    display: flex;
    gap: 1ch;
    flex-wrap: wrap;
}

/* Key Button Style (wie data-key-code) */
.key-button {
    background: var(--bg);
    color: var(--text);
    font-family: "CommitMono", monospace;
    font-size: 0.75rem;
    line-height: 1rem;
    border: 1px solid var(--border);
    padding: 0.25rem 1ch;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: none;
}

.key-button:hover {
    background: repeating-conic-gradient(transparent 0% 25%, var(--text) 0% 100%) 1px 0.5px / 2px 2px;
    color: var(--bg);
}

.key-button:active {
    background: repeating-conic-gradient(var(--text) 0% 25%, transparent 0% 50%, var(--text) 0% 75%, transparent 0% 100%) 1px 0.5px / 2px 2px;
    color: var(--bg);
}

.key-button:focus {
    outline: none;
    background: var(--text);
    color: var(--bg);
}

/* Editor */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    font-size: 0.75rem;
    line-height: 1.33;
}

.line-numbers {
    font-family: "CommitMono", monospace;
    font-size: inherit;
    line-height: inherit;
    color: var(--middle);
    text-align: right;
    padding-right: 2ch;
    user-select: none;
    white-space: pre;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    align-self: stretch;
}

.line-numbers::-webkit-scrollbar {
    display: none;
}

#editor {
    font-family: "CommitMono", monospace;
    font-size: inherit;
    line-height: inherit;
    border: none;
    padding: 0;
    flex: 1;
    background: var(--bg);
    color: var(--text);
    outline: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow-y: auto;
}

#editor:empty:before {
    content: attr(data-placeholder);
    color: var(--middle);
    pointer-events: none;
}

#editor:focus:before {
    content: none;
}

/* File Thumbnails inline im Editor */
.file-thumb {
    display: inline;
    border: 1px solid var(--border);
    padding: 0 1ch;
    cursor: pointer;
    background: var(--bg);
    max-width: 30ch;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: "CommitMono", monospace;
    font-size: 0.75rem;
    line-height: 1rem;
}

.file-thumb:hover {
    background: repeating-conic-gradient(var(--text) 0% 25%, transparent 0% 100%) 1px 0.5px / 2px 2px;
    color: var(--bg);
}

/* File List */
.file-list {
    position: fixed;
    bottom: 4rem;
    left: 4ch;
    right: 4ch;
    background: var(--bg);
    border: 1px solid var(--border);
    max-height: 15rem;
    overflow-y: auto;
    padding: 0.5rem 1ch;
    display: none;
}

.file-list:not(:empty) {
    display: block;
}

@media (max-width: 1000px) {
    .file-list {
        left: 2ch;
        right: 2ch;
    }
}

.file-item {
    display: flex;
    gap: 1ch;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    line-height: 1rem;
}

.file-item:last-child {
    border-bottom: none;
}

.file-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.file-item-name:hover {
    text-decoration: underline;
}

.file-item-remove {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    font-family: "CommitMono", monospace;
    font-size: 0.75rem;
    text-decoration: underline;
}

.file-item-remove:hover {
    text-decoration: none;
}

/* Action Section - fixed at bottom */
.action-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 4ch;
    flex-wrap: wrap;
    padding: 1rem 4ch;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.button-group {
    display: flex;
    gap: 1ch;
}

.button-group:last-child {
    margin-left: auto;
}

@media (max-width: 1000px) {
    .action-section {
        padding: 1rem 2ch;
    }
}

/* File Preview Overlay */
.file-preview-overlay {
    position: fixed;
    top: 0;
    right: 0;
    width: 50%;
    height: 100vh;
    background: var(--bg);
    border-left: 1px solid var(--border);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease;
}

.file-preview-overlay.hidden {
    transform: translateX(100%);
}

@media (max-width: 1000px) {
    .file-preview-overlay {
        width: 100%;
    }
}

.file-preview-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1rem 2ch;
}

.preview-header {
    margin-bottom: 1rem;
}

.preview-content {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--border);
    padding: 1rem 1ch;
}

.preview-content img {
    max-width: 100%;
    height: auto;
    display: block;
}

.preview-content pre {
    font-family: "CommitMono", monospace;
    font-size: 0.75rem;
    line-height: 1rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Drag and Drop */
#editor.drag-over {
    background: repeating-conic-gradient(var(--text) 0% 25%, transparent 0% 100%) 1px 0.5px / 2px 2px;
}

/* Code Input Section */
.code-input-section {
    display: flex;
    gap: 1ch;
    align-items: center;
    margin-bottom: 2rem;
}

#codeInput {
    font-family: "CommitMono", monospace;
    font-size: 0.75rem;
    line-height: 1rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.25rem 1ch;
    width: 10ch;
    text-transform: uppercase;
    letter-spacing: 0.2ch;
}

#codeInput:focus {
    outline: none;
    background: var(--text);
    color: var(--bg);
}

#codeInput::placeholder {
    color: var(--middle);
    text-transform: none;
    letter-spacing: normal;
}

/* Share Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(17, 17, 17, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 2rem;
    max-width: 30ch;
    text-align: center;
}

.modal-content h3 {
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: normal;
    margin-bottom: 1rem;
}

.modal-content p {
    font-size: 0.75rem;
    line-height: 1rem;
    margin-bottom: 0.5rem;
}

.code-display {
    display: flex;
    gap: 1ch;
    align-items: center;
    justify-content: center;
    margin: 1rem 0;
}

.code-display span {
    font-family: "CommitMono", monospace;
    font-size: 1.5rem;
    line-height: 2rem;
    letter-spacing: 0.3ch;
    font-weight: bold;
    padding: 0.5rem 1ch;
    border: 1px solid var(--border);
    background: var(--text);
    color: var(--bg);
}

.code-hint {
    color: var(--middle);
    margin-bottom: 1rem;
}

.expiry-info {
    color: var(--middle);
    font-size: 0.65rem;
    margin-bottom: 1.5rem;
}

#closeModal {
    margin-top: 1rem;
}

/* Loading Indicator */
.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 1rem 2ch;
    z-index: 3000;
}

.loading.hidden {
    display: none;
}

.loading p {
    font-family: "CommitMono", monospace;
    font-size: 0.75rem;
    line-height: 1rem;
}

.loading p::after {
    content: "...";
    animation: 500ms forwards infinite loading_animation;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

@keyframes loading_animation {
    0% { content: ""; }
    25% { content: "."; }
    50% { content: ".."; }
    75% { content: "..."; }
    100% { content: ""; }
}

/* ========================================
   iOS & Mobile Fixes - No Zoom, App-like
   ======================================== */

html, body {
    /* Prevent zoom on touch/pinch */
    touch-action: pan-y;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Mobile-specific optimizations */
@media (max-width: 768px) {
    /* Force 16px minimum to prevent iOS auto-zoom */
    #editor {
        font-size: 16px !important;
    }

    input, textarea, #codeInput {
        font-size: 16px !important;
    }

    /* Larger touch targets for buttons */
    button {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 16px;
    }

    .key-button {
        min-height: 44px;
        padding: 12px 24px;
    }

    /* File thumbs easier to tap */
    .file-thumb {
        padding: 8px 12px;
        font-size: 14px;
        margin: 0 4px;
    }

    /* Mobile layout adjustments */
    header {
        padding: 1rem 2ch 0 2ch;
    }

    main {
        padding: 0 2ch 4ch 2ch;
    }

    /* Code input full width on mobile */
    .code-input-section {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    #codeInput {
        flex: 1;
        min-width: 150px;
    }

    /* Action buttons stack on very small screens */
    @media (max-width: 480px) {
        .action-buttons {
            flex-direction: column;
            gap: 0.5rem;
        }

        .action-buttons button {
            width: 100%;
        }
    }
}