@font-face {
    font-family: 'Unifont';
    src: url('../unifont-16.0.04.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

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

body {
    font-family: 'Unifont', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #000;
    color: #f5f5f7;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
}

/* Logo */
#logo {
    position: absolute;
    left: 24px;
    top: 24px;
    width: 50px;
    height: auto;
    z-index: 100;
    cursor: pointer;
    transition: transform 0.2s;
}

#logo:hover {
    transform: scale(1.05);
}

/* 語言選擇器 */
#language-selector {
    position: absolute;
    right: 24px;
    top: 24px;
    z-index: 100;
}

#language-button {
    background: rgba(29, 29, 31, 0.75);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 8px 14px;
    color: #f5f5f7;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

#language-button:hover {
    background: rgba(29, 29, 31, 0.85);
    border-color: rgba(255, 255, 255, 0.15);
}

#language-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 8px;
    display: none;
    min-width: 140px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

#language-dropdown.show {
    display: block;
}

.language-option {
    padding: 10px 14px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.language-option:hover {
    background: rgba(255, 255, 255, 0.08);
}

.language-option.active {
    background: rgba(0, 122, 255, 0.15);
    color: #007aff;
}

.language-option .checkmark {
    opacity: 0;
    font-size: 14px;
}

.language-option.active .checkmark {
    opacity: 1;
}

/* 左側面板 */
#sidebar {
    position: absolute;
    left: 24px;
    bottom: 24px;
    width: 160px;
    background: rgba(29, 29, 31, 0.75);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.sidebar-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    opacity: 0.9;
}

.layer-selector {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.layer-option {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 12px;
}

.layer-option:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.layer-option.active {
    background: rgba(0, 122, 255, 0.15);
    border-color: #007aff;
    color: #007aff;
}

/* 主地圖區域 */
#map-container {
    flex: 1;
    position: relative;
    cursor: grab;
    overflow: hidden;
}

#map-container.dragging {
    cursor: grabbing;
}

#map-canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* 選取框 */
#selection-box {
    position: absolute;
    border: 2px solid #007aff;
    background: rgba(0, 122, 255, 0.1);
    pointer-events: none;
    display: none;
}

/* 座標標記 */
.coord-marker {
    position: absolute;
    pointer-events: none;
    z-index: 50;
}

.coord-marker::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: #007aff;
    border: 2px solid #fff;
    border-radius: 50%;
    top: -6px;
    left: -6px;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.5);
}


.coord-label {
    position: absolute;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-family: 'SF Mono', Monaco, monospace;
    color: #007aff;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* 區域標記框 */
.area-marker {
    position: absolute;
    border: 2px solid #007aff;
    background: rgba(0, 122, 255, 0.08);
    pointer-events: none;
    z-index: 50;
    box-shadow: 0 0 20px rgba(0, 122, 255, 0.3), inset 0 0 20px rgba(0, 122, 255, 0.1);
}

.area-label {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-family: 'SF Mono', Monaco, monospace;
    color: #007aff;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 8px;
}

.area-label-text {
    color: #007aff;
}

.area-label-buttons {
    display: flex;
    gap: 4px;
    margin-left: 4px;
}

.area-icon-button {
    width: 20px;
    height: 20px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    pointer-events: auto;
}

.area-icon-button:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.area-icon-button:active {
    transform: scale(0.95);
}

.area-icon-button svg {
    width: 12px;
    height: 12px;
    fill: #007aff;
}

.area-icon-button .tooltip {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.area-icon-button:hover .tooltip {
    opacity: 1;
}

/* 右下角信息 */
#info-panel {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: rgba(29, 29, 31, 0.75);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 200px;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.coords-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-family: 'SF Mono', Monaco, monospace;
}

.coord-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.coord-text-label {
    color: #86868b;
    font-size: 13px;
}

.coord-value {
    color: #f5f5f7;
    min-width: 40px;
}

.coord-input {
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #f5f5f7;
    font-size: 13px;
    outline: none;
    font-family: 'SF Mono', Monaco, monospace;
    width: 70px;
    line-height: 1.3;
}

.coord-input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: #007aff;
}

.coord-input.error {
    border-color: #ff3b30;
    background: rgba(255, 59, 48, 0.15);
}

.coord-buttons {
    display: flex;
    gap: 6px;
    margin-left: 16px;
}

.coord-button {
    padding: 3px 12px;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    line-height: 1.4;
}

.coord-button.go {
    background: #007aff;
}

.coord-button.go:hover {
    background: #0066cc;
}

.coord-button.cancel {
    background: rgba(255, 255, 255, 0.1);
}

.coord-button.cancel:hover {
    background: rgba(255, 255, 255, 0.15);
}

.coord-button:active {
    transform: scale(0.96);
}

.error-message {
    font-size: 11px;
    color: #ff3b30;
    margin-top: 4px;
    display: none;
}

.error-message.show {
    display: block;
}

/* 右鍵選單 */
#context-menu {
    position: absolute;
    background: rgba(29, 29, 31, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 8px;
    display: none;
    z-index: 1000;
    min-width: 180px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.context-menu-item {
    padding: 10px 14px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.2s;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.context-info {
    padding: 10px 14px;
    font-size: 12px;
    color: #86868b;
    font-family: 'SF Mono', Monaco, monospace;
}

/* 載入動畫 */
.loading {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(29, 29, 31, 0.9);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 12px 20px;
    font-size: 13px;
    z-index: 100;
    display: none;
}

.loading.active {
    display: block;
}

/* 全屏加載遮罩 */
#db-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    flex-direction: column;
    gap: 20px;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

#db-loading-overlay.fade-out {
    opacity: 0;
}

#db-loading-overlay.hidden {
    display: none;
}

.db-loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #007aff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.db-loading-text {
    font-size: 16px;
    color: #f5f5f7;
    opacity: 0.8;
}

.db-error-text {
    font-size: 18px;
    color: #ff3b30;
    font-weight: 600;
}

/* 手機版適配 */
@media (max-width: 768px) {
    #logo {
        width: 40px;
        left: 16px;
        top: 16px;
    }

    #language-selector {
        right: 16px;
        top: 16px;
    }

    #language-button {
        padding: 6px 10px;
        font-size: 12px;
    }

    .language-option {
        padding: 8px 12px;
        font-size: 12px;
    }

    #sidebar {
        left: auto;
        right: 16px;
        bottom: 80px;
        width: 140px;
        padding: 12px;
        gap: 8px;
    }

    .sidebar-title {
        font-size: 13px;
    }

    .layer-option {
        padding: 6px 10px;
        font-size: 11px;
    }

    #info-panel {
        position: fixed;
        bottom: 16px;
        right: 16px;
        padding: 10px 14px;
        min-width: 160px;
        width: auto;
    }

    .coords-line {
        font-size: 12px;
        gap: 6px;
        flex-wrap: nowrap;
        justify-content: space-between;
    }

    .coord-item {
        gap: 3px;
    }

    .coord-text-label {
        font-size: 12px;
    }

    .coord-value {
        font-size: 12px;
        min-width: 35px;
    }

    .coord-input {
        font-size: 12px;
        width: 60px;
        padding: 2px 4px;
    }

    .coord-button {
        padding: 3px 10px;
        font-size: 11px;
    }

    .area-label {
        font-size: 11px;
        padding: 5px 10px;
        top: -45px;
    }

    .coord-label {
        font-size: 11px;
        padding: 5px 10px;
    }
}

/* 處理手機瀏覽器工具欄 */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari */
    body {
        height: -webkit-fill-available;
    }
}
