:root {
  /* Global Colors */
  --bg: #1e1e1e;
  --fg: #ddd;
  --panel: #252526;
  --border: #444;
  --input-bg: #333;
  --input-fg: #fff;
  --output-color: #0f0;

  /* Button Colors */
  --btn-bg: #0078d7;
  --btn-hover: #005fa3;
}

body.light {
  /* Global Colors - Light Mode */
  --bg: #f5f5f5;
  --fg: #111;
  --panel: #fff;
  --border: #ccc;
  --input-bg: #fff;
  --input-fg: #000;
  --output-color: #070;

  /* Button Colors - Light Mode */
  --btn-bg: #333;
  --btn-hover: #111;
}

body {
  margin: 0; padding: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  transition: all 0.3s ease;
}

/* Layout */
.container { display: flex; flex-direction: row; min-height: 100vh; }
.side-lang-buttons { display: flex; flex-direction: column; gap: 10px; width: 100px; padding: 20px; background: var(--panel); border-right: 1px solid var(--border); }
.main-compiler { flex: 1; padding: 20px; background: var(--panel); margin-left: 0; }

/* Language buttons */
.lang-btn-small { border-radius: 8px; padding: 8px; text-align: center; cursor: pointer; background: var(--panel); color: var(--fg); border: 1px solid var(--border); transition: 0.2s; }
.lang-btn-small img { width: 36px; height: 36px; }
.lang-btn-small div { font-size: 12px; font-weight: 600; margin-top: 4px; }
.lang-btn-small:hover { background: var(--btn-bg); color: #fff; transform: translateX(2px); border-color: var(--btn-bg); }

/* Topbar */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.home-btn { text-decoration: none; font-weight: bold; font-size: 18px; color: var(--btn-bg); border: 1px solid var(--btn-bg); padding: 5px 10px; border-radius: 6px; margin-right: 30px}
.home-btn:hover { background: var(--btn-hover); color: #fff; }
.theme-toggle { background: none; border: none; color: var(--fg); font-size: 22px; cursor: pointer; transition: transform 0.2s; }
.theme-toggle:hover { transform: rotate(20deg); }

/* Editor */
.CodeMirror {
  width: 100%;
  min-height: 200px;
  /* Max height handled by JS, but safe limit here */
  max-height: 80vh; 
  border-radius: 6px; 
  font-size: 15px; 
  border: 1px solid var(--border); 
  margin-bottom: 10px; 
}

/* Buttons */
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
/*.actions button {
  background: var(--btn-bg);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: bold;
  transition: background 0.3s ease;
}
.actions button:hover { background: var(--btn-hover); }*/

/* =========================================
   ACTION BUTTONS (Specific Colors & Hover)
   ========================================= */

/* Base Styles for all action buttons */
.actions button {
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

/* Click Effect */
.actions button:active {
    transform: translateY(1px);
}

/* =========================================
   SPECIFIC BUTTON COLORS & HOVER EFFECTS
   ========================================= */

/* 1. RUN BUTTON (Green) */
#runBtn {
  background-color: #28a745 !important;
  color: white;
}
#runBtn:hover {
  background-color: #218838 !important; /* Darker Green */
}

/* 2. RESET BUTTON (Red) */
#resetBtn {
  background-color: #dc3545 !important;
  color: white;
}
#resetBtn:hover {
  background-color: #c82333 !important; /* Darker Red */
}

/* 3. SAVE BUTTON (Blue) */
#downloadBtn {
  background-color: #007bff !important;
  color: white;
}
#downloadBtn:hover {
  background-color: #0069d9 !important; /* Darker Blue */
}

/* 4. SHARE BUTTON (Teal/Cyan) */
#shareBtn {
  background-color: #17a2b8 !important;
  color: white;
}
#shareBtn:hover {
  background-color: #138496 !important; /* Darker Teal */
}

/* Run Button Generic */
/*#runBtn {
  background: var(--btn-bg);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: bold;
}
#runBtn:hover { background: var(--btn-hover); }*/

/* Inputs & Outputs */
.input-section { margin-bottom: 10px; display: none; } /* Default hidden */
.input-section textarea { width: 100%; border-radius: 6px; padding: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--input-fg); resize: vertical; }

#output { 
  background: var(--panel); 
  color: var(--output-color); 
  padding: 15px; 
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 100px;
  white-space: pre-wrap;
  font-family: 'Consolas', 'Courier New', monospace;
  transition: all 0.3s ease;
}

/* --- ERROR STATE (CRITICAL FIX) --- */
.error-output {
  color: #ff5555 !important;
  border-color: #ff5555 !important;
  background-color: rgba(255, 85, 85, 0.1) !important;
}

body.light .error-output {
  color: #d32f2f !important;
  border-color: #d32f2f !important;
  background-color: rgba(211, 47, 47, 0.1) !important;
}

  /* =========================================
     MAIN AREA
     ========================================= */
  .main-compiler { flex-grow: 1; padding: 20px 30px; max-width: 1400px; margin: 0 auto;}

  /* =========================================
     SIDEBAR ACTIVE STATE
     ========================================= */
  /* This highlights the selected language */
  /* ACTIVE STATE (LIGHT MODE) */
  .lang-btn-small.active {
      background-color: #0f0;      /* Light Grey */
      border: 1px solid #adb5bd;      /* Subtle Border */
      box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); /* Inner shadow for depth */
      font-weight: bold; /* Bold text */
      transform: translateY(1px); /* Slight "pressed" offset */
  }

 /* Input Section - FORCE VISIBLE */
  .input-section { margin-top: 15px; width: 100%; display: block !important; }
  .input-section label { font-weight: bold; display: block; margin-bottom: 5px; }
  #input {
      width: 100%;
      /*background: #f8f9fa;*/
      /*border: 1px solid #ddd;*/
      border-radius: 4px;
      padding: 10px;
      font-family: monospace;
      min-height: 20px;
      box-sizing: border-box;
      display: block !important;
  }
  #input:focus { outline: 1px solid #007bff;}

/* =========================================
     EDITOR ENHANCEMENTS
     ========================================= */
  /* This makes the active line visible */
  .CodeMirror-activeline-background {
      background: rgba(0, 0, 0, 0.05);
  }

  body.dark-mode .CodeMirror-activeline-background { background: rgba(255, 255, 255, 0.05); }

  /* =========================================
   6. TABLET / IPAD MINI (768px - 1024px)
   ========================================= */
@media screen and (min-width: 768px) and (max-width: 1024px) {
    
    .container {
        flex-direction: row; /* Keep Layout Side-by-Side */
    }

    /* Sidebar slightly wider for touch */
    .side-lang-buttons {
        width: 100% !important;
        min-width: 100%;
        height: auto;
    }
    .lang-btn-small {
        width: 70px;
        padding: 12px 0; /* Larger touch target */
    }

    /* 3. Resize Layout for Screen Width */
    .main-compiler { 
        padding: 10px; /* Reduce padding to give content space */
        width: 100vw;  /* Force Viewport Width */
        box-sizing: border-box;
    }

    /* Editor optimization */
    .CodeMirror {
        height: 60vh; /* Use plenty of height */
        font-size: 15px; /* Readable text */
    }

    /* Buttons */
    .actions button, #runBtn {
        padding: 12px 20px; /* Easier to tap */
    }
}

/* =========================================
   6. MOBILE RESPONSIVE (THE FIX)
   ========================================= */
@media screen and (max-width: 768px) {

    /* 1. Stack Layout Vertically */
    .container { flex-direction: column; }

    /* 2. Top Scroll Menu (Language Bar) */
    .side-lang-buttons {
        width: 100% !important;
        min-width: 100%;
        height: auto;
        
        /* Flex Logic for Scrolling */
        display: flex;
        flex-direction: row;       
        flex-wrap: nowrap;         /* No wrapping */
        overflow-x: auto;          /* Scrollable */
        overflow-y: hidden;        
        
        padding: 10px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        
        -webkit-overflow-scrolling: touch; 
        scrollbar-width: none; 
    }
    
    .side-lang-buttons::-webkit-scrollbar { display: none; }

    .lang-btn-small {
        margin-bottom: 0;
        margin-right: 12px;
        min-width: 65px; 
        width: 65px;
        flex-shrink: 0; 
    }

    /* 3. Resize Layout for Screen Width */
    .main-compiler { 
        padding: 10px; /* Reduce padding to give content space */
        width: 100vw;  /* Force Viewport Width */
        box-sizing: border-box;
    }

    .topbar h2 { font-size: 1.1rem; } 
    
    /* 4. BUTTONS 2x2 GRID (Fits perfectly) */
    .actions {
        display: grid;
        grid-template-columns: 1fr 1fr; /* Two equal columns */
        gap: 8px;
        width: 100%;
    }
    
    .actions button, #runBtn {
        width: 100%;
        padding: 10px 5px;
        font-size: 13px;
        text-align: center;
        margin: 0;
    }

    /* On Mobile, reduce height slightly to fit keyboard */
    .CodeMirror {
        /*height: 55vh; /* 55% of screen height on phone */
        font-size: 11px;
        max-width: 100%; 
    }
    
    .CodeMirror-scroll {
        overflow-x: auto !important; /* Allow code scanning */
    }

    #input, #output {
        max-width: 100%;
        width: 100% !important;
        box-sizing: border-box;
        font-size: 13px;
    }
}