* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    /* Safari mobile safe area */
    background: #0f3460;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

body {
    height: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    background-attachment: fixed;
    color: #fff;
    /* Safari mobile safe area for body */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

input, textarea, button, div[contenteditable] {
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    /* Safari safe area */
    padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
}

.header {
    text-align: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.header h1 {
    font-size: 2rem;
    margin-bottom: 4px;
    background: linear-gradient(90deg, #00d9ff, #00ff88);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #888;
    font-size: 0.9rem;
}

.expire-notice {
    display: none;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: calc(100dvh - 280px);
}

.textarea {
    width: 100%;
    flex: 1;
    min-height: 150px;
    /* Safari dynamic viewport height */
    max-height: calc(100dvh - 440px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 16px;
    border: 2px solid #333;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: #e8e8e8;
    font-size: 16px;
    line-height: 1.6;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    transition: border-color 0.3s, box-shadow 0.3s;
    /* Safari smooth scrolling */
    -webkit-overflow-scrolling: touch;
}

.textarea:focus {
    outline: none;
    border-color: #00d9ff;
    box-shadow: 0 0 20px rgba(0, 217, 255, 0.2);
}

.textarea:empty:before {
    content: attr(data-placeholder);
    color: #777;
    pointer-events: none;
}

.textarea a,
.textarea a:visited,
.textarea a:hover,
.textarea a:active {
    color: inherit;
    text-decoration: underline;
}

.url-bar {
    display: none;
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #333;
    font-size: 13px;
    line-height: 1.8;
    word-break: break-all;
    flex-shrink: 0;
}

.url-bar.show {
    display: block;
}

.url-bar a {
    color: #00d9ff;
    text-decoration: underline;
    margin-right: 16px;
    transition: color 0.2s;
}

.url-bar a:hover {
    color: #00ff88;
}

.textarea img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 8px 0;
    display: block;
}

.controls {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.code-input-group {
    display: flex;
    gap: 10px;
    flex: 1;
}

.code-input {
    flex: 0 0 90px;
    padding: 12px 8px;
    border: 2px solid #444;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #e8e8e8;
    font-size: 16px;
    font-family: 'Courier New', monospace;
    letter-spacing: 4px;
    text-transform: uppercase;
    text-align: center;
    transition: border-color 0.3s;
}

.code-input:focus {
    outline: none;
    border-color: #00ff88;
}

.code-input::placeholder {
    color: #777;
    letter-spacing: normal;
    font-family: inherit;
    font-size: 14px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #00d9ff, #00ff88);
    color: #1a1a2e;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 217, 255, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 2px solid #333;
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    border-color: #00ff88;
}

.btn-upload {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 2px solid #333;
    width: 54px;
    padding: 12px 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

.btn-upload:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    border-color: #00ff88;
}

.status {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    display: none;
    flex-shrink: 0;
}

.status.show {
    display: block;
    animation: fadeIn 0.3s ease;
}

.status.success {
    background: rgba(0, 255, 136, 0.1);
    border: 1px solid #00ff88;
    color: #00ff88;
}

.status.error {
    background: rgba(255, 87, 87, 0.1);
    border: 1px solid #ff5757;
    color: #ff5757;
}

.status.info {
    background: rgba(0, 217, 255, 0.1);
    border: 1px solid #00d9ff;
    color: #00d9ff;
}

.status .code {
    font-family: 'Courier New', monospace;
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 4px;
    margin: 8px 0;
    padding: 8px 16px;
    background: rgba(0, 217, 255, 0.1);
    border-radius: 8px;
    display: inline-block;
}

.btn-image-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: #00ff88;
    border: 1px solid rgba(0, 255, 136, 0.3);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.btn-image-action:active {
    transform: scale(0.95);
}

.btn-image-action:hover {
    background: rgba(0, 255, 136, 0.15);
    border-color: #00ff88;
}

.image-hint {
    color: #666;
    font-size: 11px;
    margin-left: 8px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: absolute;
    left: 20px;
    right: 20px;
    bottom: env(safe-area-inset-bottom);
    color: #555;
    font-size: 12px;
    z-index: 100;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.copyright {
    opacity: 0.7;
}

.wechat-link {
    display: inline-flex;
    opacity: 0.6;
    transition: opacity 0.3s;
}

.wechat-link:hover {
    opacity: 1;
}

.wechat-icon {
    width: 20px;
    height: 20px;
}

.wechat-id {
    opacity: 0.7;
}

.expire-tip {
    color: #fff;
    font-size: 11px;
    background: linear-gradient(135deg, rgba(0, 217, 255, 0.2), rgba(0, 255, 136, 0.2));
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid rgba(0, 217, 255, 0.3);
    text-align: center;
    min-width: 160px;
}

/* ========== 移动端优化 ========== */
@media (max-width: 600px) {
    .container {
        padding: calc(20px + env(safe-area-inset-top)) 15px calc(80px + env(safe-area-inset-bottom));
        overflow-y: auto;
        box-sizing: border-box;
        width: 100%;
        max-width: 100%;
    }

    .header {
        margin-bottom: 8px;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    .main {
        max-height: calc(100dvh - 260px);
    }

    .textarea {
        min-height: 80px;
        max-height: calc(100dvh - 340px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding: 12px;
        font-size: 16px;
    }

    .controls {
        flex-direction: column;
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .code-input-group {
        width: 100%;
        display: flex;
        gap: 8px;
    }

    .code-input-group .btn {
        width: auto;
        min-width: 80px;
        flex-shrink: 0;
    }

    .code-input {
        flex: 1;
        min-width: 0;
        padding: 10px 8px;
        font-size: 16px;
    }

    .btn {
        width: 100%;
        padding: 14px 20px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .status {
        font-size: 13px;
        padding: 10px 12px;
    }

    .status .code {
        font-size: 18px;
        padding: 6px 12px;
    }

    .footer {
        left: 15px;
        right: 15px;
        bottom: calc(15px + env(safe-area-inset-bottom));
        font-size: 11px;
        position: absolute;
    }

    .wechat-icon {
        width: 18px;
        height: 18px;
    }

    .expire-tip {
        font-size: 10px;
        padding: 5px 10px;
    }
}

/* ========== iPhone X+ Safe Area ========== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .container {
        min-height: -webkit-fill-available;
        min-height: fill-available;
    }

    .btn-primary:hover:not(:disabled),
    .btn-secondary:hover:not(:disabled) {
        transform: none;
    }

    .btn:active:not(:disabled) {
        transform: scale(0.98);
    }
}

/* ========== Safari 工具栏遮挡问题 ========== */
@supports (bottom: env(safe-area-inset-bottom)) {
    .textarea {
        /* 底部留出 safe area 空间 */
        margin-bottom: env(safe-area-inset-bottom);
    }

    .footer {
        /* footer 自动适配 */
        bottom: env(safe-area-inset-bottom);
    }
}

/* ========== 小屏幕优化 ========== */
@media (max-width: 380px) {
    .header h1 {
        font-size: 1.2rem;
    }

    .subtitle {
        font-size: 0.7rem;
    }

    .code-input {
        flex: 0 0 80px;
        font-size: 14px;
        letter-spacing: 2px;
    }

    .status .code {
        font-size: 16px;
        letter-spacing: 2px;
    }
}
