body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#controller-view {
    overflow-y: auto !important;
    background: #f0f2f5;
}

/* --- World View Background & Animation --- */
#world-view {
    /* Day-Night Cycle Animation possible, stick to Vibrant Day for now */
    background: linear-gradient(to bottom, #87CEEB, #E0F7FA);
    position: relative;
}

#scene-container {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 0;
    /* Behind canvas */
    overflow: hidden;
}

/* Sky */
.sky-layer {
    position: absolute;
    width: 100%;
    height: 50%;
    top: 0;
}

.sun {
    width: 80px;
    height: 80px;
    background: #FFD700;
    border-radius: 50%;
    position: absolute;
    top: 40px;
    right: 40px;
    box-shadow: 0 0 40px #FFD700;
    animation: pulse 4s infinite alternate;
}

.cloud {
    position: absolute;
    font-size: 4rem;
    opacity: 0.8;
    filter: drop-shadow(2px 2px 5px rgba(0, 0, 0, 0.1));
}

.c1 {
    top: 10%;
    left: -10%;
    animation: floatCloud 25s linear infinite;
}

.c2 {
    top: 20%;
    left: -10%;
    animation: floatCloud 35s linear infinite;
    animation-delay: 5s;
}

.c3 {
    top: 5%;
    left: -10%;
    animation: floatCloud 45s linear infinite;
    animation-delay: 15s;
}

/* Mountains */
.mountain-layer {
    position: absolute;
    width: 100%;
    height: 60%;
    bottom: 0;
    z-index: 1;
}

.mountain {
    position: absolute;
    bottom: 20%;
    /* Behind ground */
    width: 0;
    height: 0;
    border-left: 150px solid transparent;
    border-right: 150px solid transparent;
    border-bottom: 300px solid #7986CB;
    /* Muted blue-purple */
}

.m1 {
    left: 10%;
    bottom: 15%;
    transform: scale(1.2);
    border-bottom-color: #5C6BC0;
}

.m2 {
    left: 40%;
    bottom: 10%;
    transform: scale(1.5);
    border-bottom-color: #3F51B5;
}

.m3 {
    left: 70%;
    bottom: 15%;
    transform: scale(1.1);
}

/* Ground */
.ground-layer {
    position: absolute;
    width: 100%;
    height: 40%;
    bottom: 0;
    z-index: 2;
}

.hill {
    position: absolute;
    background: #66BB6A;
    border-radius: 100% 100% 0 0;
    bottom: 0;
}

.h1 {
    width: 70%;
    height: 100%;
    left: -10%;
    background: #4CAF50;
}

.h2 {
    width: 80%;
    height: 80%;
    right: -20%;
    background: #81C784;
}

.castle {
    position: absolute;
    bottom: 60%;
    left: 15%;
    font-size: 8rem;
    z-index: 3;
    filter: drop-shadow(5px 5px 10px rgba(0, 0, 0, 0.3));
}

.forest {
    position: absolute;
    font-size: 4rem;
    bottom: 60%;
}

.f1 {
    left: 5%;
}

.f2 {
    right: 10%;
    bottom: 56%;
}

/* Water */
.water-layer {
    position: absolute;
    width: 100%;
    height: 25%;
    bottom: 0;
    z-index: 3;
    overflow: hidden;
}

.river {
    position: absolute;
    width: 120%;
    height: 100%;
    left: -10%;
    background: linear-gradient(to bottom, #29B6F6, #0288D1);
    opacity: 0.8;
    transform: perspective(500px) rotateX(20deg);
    animation: drift 10s infinite alternate;
}

.bridge {
    position: absolute;
    bottom: 50%;
    right: 25%;
    font-size: 6rem;
    z-index: 4;
}

.boat {
    position: absolute;
    bottom: 20%;
    left: -10%;
    font-size: 4rem;
    animation: sail 20s linear infinite;
    z-index: 4;
}

/* Foreground */
.foreground-layer {
    position: absolute;
    width: 100%;
    height: 15%;
    bottom: 0;
    z-index: 4;
    pointer-events: none;
}

.rocks {
    position: absolute;
    bottom: 10px;
    left: 20%;
    font-size: 3rem;
}

.flowers {
    position: absolute;
    bottom: 5px;
    right: 30%;
    font-size: 2rem;
    animation: sway 3s ease-in-out infinite alternate;
}


/* Animations */
@keyframes floatCloud {
    from {
        left: -20%;
    }

    to {
        left: 120%;
    }
}

@keyframes pulse {
    from {
        transform: scale(1);
        box-shadow: 0 0 40px #FFD700;
    }

    to {
        transform: scale(1.1);
        box-shadow: 0 0 60px #FFD700;
    }
}

@keyframes sail {
    from {
        left: -10%;
        transform: rotate(5deg);
    }

    to {
        left: 110%;
        transform: rotate(-5deg);
    }
}

@keyframes sway {
    from {
        transform: rotate(-5deg);
    }

    to {
        transform: rotate(5deg);
    }
}

@keyframes blink {
    0% {
        opacity: 0.2;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.2;
    }
}

/* --- UI Overlay --- */
#world-ui {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
    background: rgba(255, 255, 255, 0.85);
    padding: 10px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* gap: 10px; */
    pointer-events: auto;
    /* Allow interaction if needed, though scan is primary */
}

#world-ui h1 {
    font-size: 1.2rem;
    margin: 0;
    color: #333;
    font-weight: bold;
}

#world-ui p {
    font-size: 0.9rem;
    margin: 0;
    color: #666;
}

#world-ui #qrcode-container {
    padding: 10px;
    background: white;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

#world-ui #qrcode img {
    display: block;
    width: 100px;
    height: 100px;
}

#worldCanvas {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: block;
}

/* --- Controller View Styles --- */
#controller-view {
    background-color: #f5f5f5;
    color: #333;
    overflow-y: auto;
}

.controller-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
}

.upload-btn {
    display: inline-block;
    background-color: #007bff;
    color: white;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1.2rem;
    cursor: pointer;
    margin-top: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

.upload-btn:active {
    transform: scale(0.95);
}

.upload-btn input {
    display: none;
}

#previewArea {
    margin-top: 30px;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#previewCanvas {
    max-width: 100%;
    height: auto;
    border: 1px dashed #ccc;
    background: url('data:image/svg+xml;utf8,<svg width="20" height="20" xmlns="http://www.w3.org/2000/svg"><rect width="10" height="10" fill="%23eee"/><rect x="10" y="10" width="10" height="10" fill="%23eee"/></svg>');
}

.actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
}

#add-btn {
    background-color: #28a745;
    color: white;
}

.secondary {
    background-color: #6c757d;
    color: white;
}

.category-selection {
    margin: 15px 0;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
}

.category-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}

.cat-btn {
    flex: 1;
    padding: 10px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.cat-btn.selected {
    border-color: #007bff;
    background: #e7f3ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.2);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;

}

.editor-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 15px;
    padding: 15px;
    background: #eee;
    border-radius: 8px;
    text-align: left;
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-group label {
    font-size: 0.8rem;
    font-weight: bold;
    margin-bottom: 5px;
}

#apply-edit-btn {
    grid-column: span 2;
    background-color: #007bff;
    color: white;
    margin-top: 10px;
}

#cropping-wrapper {
    max-height: 400px;
    overflow: hidden;
    position: relative;
    background: #000;
    border-radius: 8px;
}

#edit-img {
    max-width: 100%;
}

/* --- QR Code Section --- */
#qrcode-container {
    /* margin: 20px auto; */
    padding: 20px;
    background: white;
    border-radius: 12px;
    display: inline-block;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

#qrcode {
    padding: 10px;
}

#qrcode img {
    margin: 0 auto;
}

/* --- Editor & Drawing Tools --- */
.editor-actions {
    display: flex;
    gap: 10px;
    grid-column: span 2;
    margin-top: 10px;
}

.editor-actions button {
    flex: 1;
}

.upload-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ai-btn {
    background: linear-gradient(135deg, #6e8efb, #a777e3);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(110, 142, 251, 0.3);
}

#drawing-tools {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid #e9ecef;
}

.tool-header {
    font-weight: bold;
    margin-bottom: 12px;
    color: #495057;
    font-size: 0.9rem;
}

.brush-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.color-palette {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px;
}

.tool-btn {
    padding: 8px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: #f0f0f0;
    border-color: #bbb;
}

.tool-btn.selected {
    background: #e7f3ff;
    border-color: #007bff;
    color: #007bff;
}

.color-selector-main {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 5px 15px;
    border-radius: 30px;
    border: 1px solid #ddd;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.color-selector-main input[type="color"] {
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    cursor: pointer;
    padding: 0;
}

.color-selector-main label {
    font-size: 0.9rem;
    font-weight: bold;
    color: #555;
}

.tool-group-drawing {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.clear-icon {
    font-size: 1.5rem;
    cursor: pointer;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.clear-icon:hover {
    background: #f8d7da;
    border-color: #f5c6cb;
}

.size-controls-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: center;
}

.size-controls-container label {
    font-size: 0.8rem;
    font-weight: bold;
    color: #666;
}

.size-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 8px 15px;
    border-radius: 30px;
    width: 100%;
    justify-content: space-between;
}

.size-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #007bff;
    background: white;
    color: #007bff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    padding: 0;
}

.size-btn:hover {
    background: #007bff;
    color: white;
}

.size-controls input {
    flex: 1;
}

#size-val {
    min-width: 45px;
    font-size: 0.8rem;
    font-weight: bold;
}

#previewCanvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

#sketch-stage {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 20px;
}

.sketch-result-container {
    background: #fff;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    text-align: center;
}

.sketch-hint {
    margin-top: 10px;
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

#remote-control-stage {
    padding: 20px;
    text-align: center;
}

.control-header h3 {
    margin: 0;
    color: #1a73e8;
}

.control-header p {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 30px;
}

.joystick-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
}

.joystick-row {
    display: flex;
    gap: 10px;
}

.joy-btn {
    width: 70px;
    height: 70px;
    border-radius: 12px;
    background: white;
    border: 2px solid #ddd;
    font-size: 1.5rem;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.joy-btn:active {
    transform: scale(0.92);
    background: #e7f3ff;
    border-color: #007bff;
    color: #007bff;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

.btn-up {
    margin-bottom: 5px;
}

#dashboard-view {
    background: #f0f2f5 !important;
    overflow-y: auto !important;
    color: #1c1e21;
}

.dashboard-container {
    max-width: 1000px;
    margin: 40px auto;
    padding: 20px;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    margin-bottom: 30px;
}

.header-content h1 {
    margin: 0;
    font-size: 1.8rem;
    color: #1a73e8;
}

.header-content p {
    margin: 5px 0 0 0;
    color: #5f6368;
}

.danger-btn {
    background: #dc3545;
    color: white;
    transition: background 0.2s;
}

.danger-btn:hover {
    background: #c82333;
}

.gallery-section {
    background: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

.section-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #4caf50;
    font-weight: bold;
}

.dot {
    width: 10px;
    height: 10px;
    background: #4caf50;
    border-radius: 50%;
    animation: blink 1.5s infinite;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
}

.image-card {
    background: #f8f9fa;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e9ecef;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.image-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.image-card img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: white;
}

.card-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-info span {
    font-weight: bold;
    text-transform: capitalize;
    color: #495057;
}

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.control-btn,
.remove-btn {
    flex: 1;
    padding: 8px;
    font-size: 0.8rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.control-btn {
    background: #e7f3ff;
    color: #1a73e8;
    border: 1px solid #cce4ff;
}

.control-btn:hover {
    background: #d4e9ff;
    transform: translateY(-2px);
}

.remove-btn {
    background: #fff5f5;
    color: #e03131;
    border: 1px solid #ffe3e3;
}

.remove-btn:hover {
    background: #ffe3e3;
}

.dashboard-nav {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.nav-link {
    text-decoration: none;
    color: #1a73e8;
    font-weight: bold;
    padding: 10px 20px;
    border: 2px solid #1a73e8;
    border-radius: 8px;
    transition: all 0.2s;
}

.nav-link:hover {
    background: #1a73e8;
    color: white;
}

.removing {
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s;
}

@keyframes blink {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

/* --- First-Person Game Mode (Controller) --- */
#remote-control-stage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 9999;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#firstPersonCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, #4facfe 0%, #00f2fe 100%);
}

.game-ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
    box-sizing: border-box;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.game-ui-overlay>* {
    pointer-events: auto;
}

.side-controls {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.side-controls.left {
    left: 40px;
}

.side-controls.right {
    right: 80px;
}

.game-ui-overlay .joy-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: white;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    transition: all 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.game-ui-overlay .joy-btn:active {
    background: rgba(255, 255, 255, 0.5);
    transform: scale(0.9);
}

.game-actions {
    position: absolute;
    top: 20px;
    right: 20px;
}

.mini {
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    opacity: 0.7;
}

.control-header h3 {
    margin: 0;
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#flight-status {
    margin: 5px 0;
    font-size: 0.8rem;
    opacity: 1;
    color: #ffd700;
}

.env-water #firstPersonCanvas {
    background: linear-gradient(to bottom, #1e3c72 0%, #2a5298 100%);
}

.env-nature #firstPersonCanvas {
    background: linear-gradient(to bottom, #96fbc4 0%, #f9f586 100%);
}