:root {
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --panel-bg: #f5f2f0;
  --panel-header-bg: #f8f9fa;
  --output-bg: white;
  --header-bg: rgba(255, 255, 255, 0.1);
  --text-color: #333;
  --border-color: #dee2e6;
  --header-text: white;
  --btn-bg: #007bff;
  --btn-hover: #0056b3;
  --shadow: 0 4px 20px rgba(0,0,0,0.1);
  --caret-color: black;
  --console-btn-bg: #e9ecef;
  --console-btn-hover: #dee2e6;
  --selection-bg: #007bff;
}

.app {
  font-family:'Segoe UI',Tahoma,Geneva,Verdana,sans-serif;
  background:var(--bg-gradient);
  display:flex;
  flex-direction:column;
  color:var(--text-color);
  transition:all 0.3s ease;
}

.app.dark {
  --bg-gradient: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  --panel-bg: #2d2d30;
  --panel-header-bg: #3d3d40;
  --output-bg: #1e1e1e;
  --header-bg: rgba(0,0,0,0.2);
  --text-color: #d4d4d4;
  --border-color: #444;
  --header-text: #d4d4d4;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --caret-color: #d4d4d4;
  --selection-bg: #3399ff;
  --console-btn-bg: #333;
  --console-btn-hover: #555;
}

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

.header {
  background:var(--header-bg);
  backdrop-filter:blur(10px);
  padding:20px;
  text-align:center;
  color:var(--header-text);
  box-shadow:var(--shadow);
  display:flex;
  align-items:center;
  justify-content:center;
  position:relative;
  flex-wrap:wrap;
}

.header-title{flex:1;text-align:left;}
.header h1{font-size:2em;margin-bottom:0;}
.header p{margin:5px 0 0;}
.header-controls{
  position:absolute;
  left:50%;
  transform:translateX(-50%);
  display:flex;
  gap:10px;
  align-items:center;
  margin-top: 50px;
}

.theme-select {
  background: var(--btn-bg);
  color: var(--header-text);
  border: none;
  padding: 5px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.3s;
  width: 70%;
}

.theme-select:hover {background: var(--btn-hover);}

.theme-toggle,.readonly-toggle, .layout-toggle{
  background:var(--btn-bg);
  color:var(--header-text);
  border:none;
  padding:10px;
  border-radius:50%;
  cursor:pointer;
  font-size:16px;
  transition:all 0.3s;
}

.theme-toggle:hover,.readonly-toggle:hover, .layout-toggle:hover{
  background:var(--btn-hover);
  transform:scale(1.1);
}

.container{
  display:flex;
  flex:1;
  padding:20px;
  gap:20px;
  max-width:1400px;
  margin:0 auto;
  width:100%;
}

/* Editor Panel */
.editor-panel{
  flex:1;
  display:flex;
  flex-direction:column;
  background:var(--panel-bg);
  border-radius:10px;
  overflow:hidden;
  box-shadow:var(--shadow);
  transition:all 0.3s;
  position:relative;
  min-height:300px;
  max-height:300px;
}

#tabbed-panel {
  max-height: none;
  min-height: 600px;
}

.panel-header{
  background:var(--panel-header-bg);
  padding:10px 15px;
  font-weight:bold;
  border-bottom:1px solid var(--border-color);
  display:flex;
  justify-content:space-between;
  align-items:center;
  color:var(--text-color);
}

#tabbed-panel .panel-header {
  flex-direction: column;
  align-items: stretch;
  padding: 10px 15px 5px;
  border-bottom: 1px solid var(--border-color);
  gap: 5px;
}

#tabbed-panel .tabs {
  display: flex;
  gap: 2px;
  flex: none;
  margin: 0;
  border-bottom: none;
}

#tabbed-panel .icons {
  display: flex;
  gap: 3px;
  align-items: center;
  justify-content: flex-end;
  overflow-x: auto;
  white-space: nowrap;
  padding-right: 0;
}

.tab-btn {
  flex: 1;
  background: var(--panel-header-bg);
  color: var(--text-color);
  border: none;
  padding: 12px 8px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 8px 8px 0 0;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-bottom: 3px solid transparent;
  position: relative;
  min-width: 90px;
}

.tab-btn.active {
  background: var(--btn-bg);
  color: white;
  border-bottom-color: var(--btn-bg);
  border-radius: 8px 8px 0 0;
  z-index: 1;
}

.tab-btn:hover:not(.active) {
  background: var(--console-btn-hover);
}

.panel-header .icons{
  display:flex;
  gap:5px;
  align-items:center;
  overflow-x: auto;
  white-space: nowrap;
  padding-right: 10px; /* Add some padding for scrollbar */
}

#tabbed-panel .icons button {
  padding: 8px 8px;
  font-size: 12px;
  border-radius: 4px;
}

.panel-header button{
  background:var(--btn-bg);
  color:white;
  border:none;
  padding:8px 12px;
  border-radius:5px;
  cursor:pointer;
  font-size:12px;
  display:flex;
  align-items:center;
  gap:5px;
  transition:all 0.3s;
  flex-shrink: 0; /* Prevent buttons from shrinking */
  white-space: nowrap;
}

.panel-header button:hover{background:var(--btn-hover);}

/* Editor Wrapper for Ace */
.editor-wrapper{
  flex:1;
  position:relative;
  overflow:hidden;
  display: none;
}

.editor-wrapper.active {
  display: block;
}

.editor{
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
}

.ace_editor {
  height: 100% !important;
  width: 100% !important;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'Courier New', monospace !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
  letter-spacing: 0 !important; /* Fix for cursor misalignment in Chrome/GitHub */
}

.ace_editor, .ace_editor * {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'Courier New', monospace !important;
  letter-spacing: 0 !important;
}

/* Output */
#output{
  flex:2;
  border:none;
  background:var(--output-bg);
  border-radius:10px;
  overflow:hidden;
  box-shadow:var(--shadow);
  position:relative;
  min-height:500px;
}

#output-header{
  background:var(--panel-header-bg);
  padding:10px 15px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  border-bottom:1px solid var(--border-color);
  color:var(--text-color);
}

#output-frame{
  width:100%;
  height:calc(100% - 45px);
  border:none;
  background:var(--output-bg);
}

.fullscreen-output{
  position:fixed;
  top:0;
  left:0;
  width:100vw;
  height:100vh;
  background:var(--output-bg);
  z-index:10000;
  display:none;
}

.fullscreen-output.active{display:block;}

.fullscreen-header{
  background:var(--panel-header-bg);
  padding:10px 20px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  color:var(--text-color);
  height:50px;
  box-sizing:border-box;
}

.fullscreen-header div{display:flex;gap:10px;align-items:center;}

.fullscreen-icon,.compress-icon{
  background:var(--btn-bg);
  color:white;
  border:none;
  padding:10px;
  border-radius:50%;
  cursor:pointer;
  font-size:14px;
  transition:all 0.3s;
}

.fullscreen-icon:hover,.compress-icon:hover{
  background:var(--btn-hover);
  transform:scale(1.1);
}

#fullscreen-frame{
  width:100%;
  height:calc(100% - 50px);
  border:none;
  background:var(--output-bg);
}

/* Console */
#console-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 300px;
  background: #f8f9fa;
  color: #333;
  font-family: monospace;
  font-size: 13px;
  overflow: hidden;
  border-top: 2px solid var(--border-color);
  display: none;
  z-index: 9999;
  padding: 10px;
  transition: all 0.3s;
}

.app.dark #console-panel {
  background: #111;
  color: #0f0;
  border-top: 2px solid #333;
}

#console-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  color: #333;
}

.app.dark #console-header {
  color: #0f0;
}

#console-header button {
  background: var(--console-btn-bg);
  color: var(--text-color);
  border: none;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  border-radius: 3px;
  transition: all 0.3s;
}

.app.dark #console-header button {
  background: #333;
  color: #0f0;
}

#console-header button:hover {
  background: var(--console-btn-hover);
}

.app.dark #console-header button:hover {
  background: #555;
}

#console-output {
  overflow-y: auto;
  height: calc(100% - 40px);
}

#console-output div {
  white-space: pre-line;
  margin-bottom: 6px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  line-height: 1.3;
}

.app.dark #console-output div {
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

/* Usage Section */
.usage-section {
  background: var(--panel-bg);
  border-radius: 10px;
  margin: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
  transition: all 0.3s;
}

.app.dark .usage-section {background: var(--panel-bg);}
.usage-section h2 {color: var(--text-color);margin-bottom: 15px;font-size: 1.5em;}
.usage-section ul {list-style-type: none;padding-left: 0;}
.usage-section li {margin-bottom: 10px;padding-left: 20px;position: relative;color: var(--text-color);}
.usage-section li:before {content: "▶";position: absolute;left: 0;color: var(--btn-bg);}

@media (max-width:768px){
  .header {flex-direction: column;gap: 10px;}
  .header-title {flex: none;text-align: center;order: 1;}
  .header-controls {position: static;transform: none;order: 2;}
  .container{flex-direction:column;}
  .editor-panel{height:300px;max-height:300px;}
  #tabbed-panel {height: 400px; min-height: 400px;}
  #output{height:400px;}
  .tab-btn { min-width: 70px; padding: 10px 4px; font-size: 12px; }
  #tabbed-panel .panel-header { padding: 5px 10px; }
  #tabbed-panel .icons { justify-content: center; }
}
