: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 */
}

#exampleSelector {
    appearance: none;
    padding: 9px 36px 9px 14px !important;
    border-radius: 5px !important;
    border: none !important;
    cursor: pointer;
    background-color: #6f42c1;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    background-image:
      linear-gradient(45deg, transparent 50%, #fff 50%),
      linear-gradient(135deg, #fff 50%, transparent 50%);
    background-position:
      calc(100% - 18px) 50%,
      calc(100% - 12px) 50%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

#exampleSelector:hover {
    background-color: #5a32a3;
}

#exampleSelector:active {
    transform: translateY(1px);
}

/* 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;
    }
}

/* --- TOP NAVIGATION USAGE METER --- */
.usage-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(30, 41, 59, 0.5); /* Dark slate background */
    padding: 6px 12px;
    border-radius: 50px;
    border: 1px solid #334155;
    margin-left: auto; /* Pushes it to the right */
    margin-right: 15px;
}
.plan-badge {
    background: #475569;
    color: #f8fafc;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 12px;
    text-transform: uppercase;
}
.usage-track {
    width: 80px;
    height: 6px;
    background: #0f172a;
    border-radius: 10px;
    overflow: hidden;
}
.usage-fill {
    height: 100%;
    width: 0%;
    background: #22d3ee; /* Cyan default */
    transition: width 0.5s ease-out, background-color 0.3s ease;
}
/* Color states for the progress bar */
.usage-fill.warning { background: #fbbf24; /* Yellow */ }
.usage-fill.danger { background: #ef4444; /* Red */ }

.usage-text {
    font-size: 0.8rem;
    color: #cbd5e1;
    font-weight: 600;
    min-width: 45px;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.upgrade-nav-btn {
    background: transparent;
    color: #22d3ee;
    border: 1px solid #22d3ee;
    padding: 4px 10px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}
.upgrade-nav-btn:hover {
    background: #22d3ee;
    color: #0f172a;
    box-shadow: 0 0 10px rgba(34,211,238,0.4);
}

.account-panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    border: 1px solid rgba(34, 211, 238, 0.25);
    border-radius: 8px;
    background: rgba(34, 211, 238, 0.07);
    font-size: 0.83rem;
    line-height: 1.35;
}

.account-panel strong {
    color: #e0faff;
}

.account-panel span {
    color: #cbd5e1;
}

.account-packets-link {
    color: #22d3ee;
    font-weight: 700;
    text-decoration: none;
}

.account-packets-link:hover {
    text-decoration: underline;
}

.account-login-btn,
.affiliate-pop-btn,
.account-pref-toggle-button {
    border: 1px solid #22d3ee;
    background: transparent;
    color: #22d3ee;
    border-radius: 8px;
    padding: 8px 10px;
    font-weight: 700;
    cursor: pointer;
}

.account-pref-toggle-button {
    margin-top: 4px;
    width: 100%;
}

.affiliate-hidden-notice {
    padding: 10px;
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 8px;
    background: rgba(34, 197, 94, 0.08);
    color: #bbf7d0;
    font-size: 0.82rem;
    line-height: 1.35;
}

.account-login-btn:hover,
.affiliate-pop-btn:hover,
.account-pref-toggle-button:hover {
    background: #22d3ee;
    color: #0f172a;
}

.pkg-offer {
    margin-top: 14px;
    padding: 18px;
    border: 1px solid #334155;
    border-radius: 18px;
    background: #0f172a;
    color: #e2e8f0;
    white-space: normal;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    box-shadow: 0 12px 28px rgba(0,0,0,0.32);
}

.px-modal-content {
    max-width: 1180px !important;
}

.pkg-offer h3 {
    margin: 0 0 6px 0;
    color: #f8fafc;
    font-size: 1.05rem;
}

.pkg-offer p {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.9rem;
    line-height: 1.45;
}

.pkg-current {
    margin-top: 8px;
    color: #93c5fd;
    font-size: 0.82rem;
}

.pkg-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-top: 16px;
}

.pkg-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: center;
    text-align: center;
    min-height: 360px;
    padding: 24px;
    border: 1px solid #334155;
    border-radius: 24px;
    background: #1e293b;
    color: #e2e8f0;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(0,0,0,0.42);
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.pkg-card:hover {
    transform: translateY(-5px);
    border-color: #22d3ee;
}

.pkg-card.popular {
    border: 2px solid #22d3ee;
    transform: scale(1.05);
}

.pkg-card.popular:hover {
    transform: scale(1.05) translateY(-5px);
}

.pkg-card.active {
    outline: 2px solid rgba(34, 211, 238, 0.45);
}

.pkg-card.free {
    opacity: 0.72;
    background: #111827;
    border-color: #1f2937;
    box-shadow: none;
    cursor: default;
}

.pkg-card.free:hover {
    transform: none;
    border-color: #1f2937;
}

.pkg-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 2px;
    padding: 4px 12px;
    border-radius: 999px;
    background: #22d3ee;
    color: #0f172a;
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    white-space: nowrap;
}

.pkg-name {
    font-weight: 800;
    color: #fff;
    font-size: 1.25rem;
    margin: 0 0 5px 0;
}

.pkg-price {
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    line-height: 1;
    margin: 0;
}

.pkg-card.popular .pkg-price {
    color: #22d3ee;
}

.pkg-card.free .pkg-price {
    color: #94a3b8;
}

.pkg-sub,
.pkg-meta,
.pkg-summary {
    font-size: 0.8rem;
    line-height: 1.3;
    color: #cbd5e1;
}

.pkg-sub {
    color: #94a3b8;
    font-size: 0.75rem;
    margin: 5px 0 0 0;
}

.pkg-summary {
    color: #94a3b8;
    font-size: 0.85rem;
    margin: 0 0 15px 0;
    min-height: 34px;
}

.pkg-features {
    list-style: none;
    padding: 0;
    margin: 18px 0 22px 0;
    width: 100%;
    text-align: left;
    color: #cbd5e1;
    font-size: 0.85rem;
    line-height: 1.5;
}

.pkg-features li {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    margin-bottom: 9px;
}

.pkg-features li.muted {
    opacity: 0.68;
}

.pkg-feature-icon {
    flex: 0 0 auto;
    width: 22px;
    text-align: center;
    color: #22c55e;
    font-weight: 900;
    font-size: 0.9rem;
}

.pkg-feature-icon.credit { color: #67e8f9; }
.pkg-feature-icon.cpu { color: #fbbf24; }
.pkg-feature-icon.timeout { color: #fb7185; }
.pkg-feature-icon.slowdown { color: #a78bfa; }
.pkg-feature-icon.adfree { color: #22c55e; }
.pkg-feature-icon.ai { color: #c084fc; }
.pkg-feature-icon.ai-off,
.pkg-feature-icon.adfree-off {
    color: #94a3b8;
}

.pkg-divider {
    display: block !important;
    border-top: 1px solid #334155;
    margin: 12px 0 !important;
    height: 0;
}

.pkg-cta {
    margin-top: auto;
    display: block;
    width: 100%;
    box-sizing: border-box;
    color: #fff;
    background: #334155;
    border-radius: 12px;
    padding: 12px;
    font-size: 0.9rem;
    font-weight: 800;
    transition: background 0.2s;
}

.pkg-card:hover .pkg-cta {
    background: #475569;
}

.pkg-card.popular .pkg-cta {
    background: #22d3ee;
    color: #0f172a;
    box-shadow: 0 0 15px rgba(34,211,238,0.4);
}

.pkg-card.popular:hover .pkg-cta {
    background: #67e8f9;
}

.pkg-card.free .pkg-cta,
.pkg-card.free:hover .pkg-cta {
    background: #1f2937;
    color: #94a3b8;
    box-shadow: none;
}

.pkg-legal-link {
    display: inline-block;
    margin-top: 10px;
    color: #94a3b8;
    font-size: 0.75rem;
    text-decoration: underline;
}

.pkg-offer.compact .pkg-grid {
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
}

.pkg-offer.compact .pkg-card {
    min-height: 320px;
    padding: 18px 14px;
}

.pkg-offer.compact .pkg-summary {
    min-height: 0;
    margin-bottom: 10px;
}

.pkg-offer.compact .pkg-features {
    font-size: 0.78rem;
}

#output .pkg-offer {
    color: #e2e8f0 !important;
}

body.light .pkg-offer {
    background: #f8fafc;
    color: #0f172a;
}

body.light .pkg-offer h3,
body.light .pkg-card .pkg-name {
    color: #0f172a;
}

body.light .pkg-offer p,
body.light .pkg-summary,
body.light .pkg-meta,
body.light .pkg-sub {
    color: #334155;
}

body.light .pkg-card {
    background: #fff;
    color: #0f172a;
}

body.light .pkg-card.free {
    background: #f1f5f9;
}

body.light .pkg-features {
    color: #334155;
}

body.light .account-panel {
    background: #f0f9ff;
}

body.light .account-panel strong,
body.light .account-panel span {
    color: #0f172a;
}

@media screen and (max-width: 768px) {
    .pkg-grid {
        grid-template-columns: 1fr;
    }
}

@media screen and (min-width: 769px) and (max-width: 1180px) {
    .pkg-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

#aiHelpBtn {
    background-color: #7c3aed !important;
    color: white;
}

#aiHelpBtn:hover {
    background-color: #6d28d9 !important;
}

.ai-help-box {
    margin-top: 14px;
    padding: 14px 16px;
    border-left: 5px solid #7c3aed;
    border-radius: 6px;
    background: rgba(124, 58, 237, 0.12);
    color: #f5f3ff;
    font-family: "Segoe UI", Arial, sans-serif;
    white-space: normal;
}

.ai-help-box strong {
    color: #c4b5fd;
}

.ai-help-box pre {
    white-space: pre-wrap;
    color: #f5f3ff;
    font-family: "Consolas", "Courier New", monospace;
    margin: 8px 0 0 0;
}
.ai-help-license {
    margin-top: 8px;
    font-size: 0.8rem;
    color: #cbd5e1;
}

.ai-help-license a {
    color: #c4b5fd;
    text-decoration: underline;
}


/* =========================================================
   Persistent Right Resource Panel
========================================================= */

#persistentResourcePanel {
    width: 280px;
    min-width: 280px;
    padding: 20px;
    background: var(--panel);
    color: var(--fg);
    border-left: 1px solid var(--border);
    box-sizing: border-box;

    display: flex;
    flex-direction: column;
    gap: 10px;

    max-height: 100vh;
    overflow-y: auto;
}

#persistentResourcePanel h3 {
    margin: 0 0 8px 0;
    color: #22d3ee;
    font-size: 1rem;
}

#persistentResourcePanel .persistent-resource-link {
    display: block;
    padding: 10px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    color: var(--fg) !important;
    text-decoration: none !important;
    font-size: 0.85rem;
    line-height: 1.35;
    border: 1px solid var(--border);
}

#persistentResourcePanel .persistent-resource-link:hover {
    background: rgba(34,211,238,0.12);
    color: #22d3ee !important;
}

#persistentResourcePanel .persistent-resource-note {
    margin-top: 8px;
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.35;
    text-align: center;
}

body.light #persistentResourcePanel .persistent-resource-link {
    background: #f4f4f4;
}

/* Tablet/mobile: behave like language panel: horizontal scroll bar */
@media screen and (max-width: 1024px) {
    .container {
        flex-direction: column;
    }

    #persistentResourcePanel {
        order: 2;
        width: 100%;
        min-width: 100%;
        max-height: none;

        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;

        border-left: none;
        border-top: 1px solid var(--border);

        padding: 10px;

        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    #persistentResourcePanel::-webkit-scrollbar {
        display: none;
    }

    #persistentResourcePanel h3 {
        min-width: 160px;
        margin: 0;
        align-self: center;
    }

    #persistentResourcePanel .persistent-resource-link {
        min-width: 220px;
        flex-shrink: 0;
        margin: 0;
    }

    #persistentResourcePanel .persistent-resource-note {
        min-width: 220px;
        align-self: center;
    }
}
