:root {
    --goblin-green: #39ff14;
    --dark-green: #0f380f;
    --black: #050505;
    --board-light: #9cac9c;
    --board-dark: #306230;
    --highlight: #ffff00;
}

html, body {
    margin: 0;
    padding: 0;
    background-color: var(--black);
    color: var(--goblin-green);
    font-family: 'VT323', monospace;
    height: 100%;
    width: 100%;
    /* Prevent bounce scrolling on mobile */
    overscroll-behavior: none; 
}

/* CRT Scanline Effect - lighter opacity for mobile visibility */
.scanlines {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,0) 50%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.1));
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 99;
}

.main-container {
    display: flex;
    flex-direction: column; /* Stack vertically on mobile */
    height: 100vh;
    box-sizing: border-box;
    padding: 10px;
    gap: 10px;
    max-width: 600px; /* Prevent stretching too wide on tablets */
    margin: 0 auto;
}

/* --- TOP PANEL: GOBLIN --- */
.side-panel {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.goblin-header {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: center;
}

#goblin-container {
    width: 80px; /* Smaller on mobile to save space */
    height: 80px;
    border: 2px solid var(--dark-green);
    background: #111;
}

.goblin-info {
    text-align: left;
}

.goblin-name {
    font-size: 1.5rem;
    line-height: 1;
}

#turn-indicator {
    color: #fff;
    font-size: 1.2rem;
}

.chat-box {
    width: 100%;
    height: 60px; /* Short chat box for mobile */
    border: 1px solid var(--goblin-green);
    padding: 5px;
    overflow-y: auto;
    font-size: 1rem;
    background: #0a0a0a;
    box-sizing: border-box;
}
.chat-box p { margin: 2px 0; }
.goblin-msg { color: #ff5555; }

/* --- MIDDLE: BOARD --- */
.board-container {
    flex: 1; /* Take up available space */
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.chess-board {
    display: grid;
    /* This is the magic: 8 columns of equal width */
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 2px solid var(--goblin-green);
    
    /* Make board responsive but keep it square */
    width: 100%; 
    aspect-ratio: 1 / 1; 
    max-height: 80vh;
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    /* Improve touch response */
    touch-action: manipulation; 
}

.square.light { background-color: var(--board-light); }
.square.dark { background-color: var(--board-dark); }
.square.selected { background-color: var(--highlight) !important; }

/* Little dot for possible moves */
.square.possible::after {
    content: '';
    position: absolute;
    width: 20%;
    height: 20%;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
}

.piece svg {
    width: 85%; /* Scale relative to square size */
    height: 85%;
    filter: drop-shadow(1px 1px 0px rgba(0,0,0,0.5));
}

/* --- BOTTOM: CONTROLS --- */
.controls-panel {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 10px;
}

.control-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

select {
    flex: 1;
    padding: 10px;
    background: var(--black);
    color: var(--goblin-green);
    border: 1px solid var(--goblin-green);
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
}

.status-log {
    font-size: 1.2rem;
    white-space: nowrap;
}

.retro-btn {
    background: var(--black);
    color: var(--goblin-green);
    border: 2px solid var(--goblin-green);
    padding: 12px; /* Larger tap target */
    font-family: 'VT323', monospace;
    font-size: 1.5rem;
    width: 100%;
    touch-action: manipulation;
}

.retro-btn:active { background: var(--goblin-green); color: var(--black); }
.retro-btn:disabled { border-color: #333; color: #333; }

/* Animation */
.bounce { animation: bounce 0.5s infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* Desktop Landscape Override */
@media (min-width: 800px) {
    .main-container {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        max-width: 1200px;
    }
    .side-panel { width: 250px; align-items: center; }
    .goblin-header { flex-direction: column; }
    #goblin-container { width: 200px; height: 200px; }
    .chat-box { height: 300px; }
    .board-container { width: auto; }
    .chess-board { width: 500px; height: 500px; }
    .controls-panel { width: 250px; }
    .control-row { flex-direction: column; align-items: stretch; }
}