body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.header {
  height: 7vh;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.2rem;
  font-weight: bold;
  padding: 0 1vw;
  backdrop-filter: blur(1vh);
  box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.4);
}

.header .logo-link {
  text-decoration: none;
  color: inherit;
  transition: opacity 0.3s;
}

.header .logo-link:hover {
  opacity: 0.7;
}

.header .header-buttons {
  display: flex;
  align-items: center;
  gap: 1vw;
  position: relative;
}

#login-button {
  padding: 8px 16px;
  background-color: #007bff;
  color: white;
  border-radius: 4px;
  cursor: pointer;
}

.tabs {
  display: flex;
  z-index: 1000;
  padding: 1vh 2vw;
  align-items: center;
  backdrop-filter: blur(0.8vh);
  justify-content: space-between;
}

.tab-buttons {
  display: flex;
  text-align: center;
  gap: 0.5vw;
}

.tab {
  cursor: pointer;
  border-radius: 0.6vh;
  padding: 1vh 2vw;
  transition: background 0.3s;
  font-size: clamp(0.75rem, 1.2vw, 1rem);
  min-width: 3.5rem;
  text-align: center;
  position: relative;
  padding-right: 2.5vw;
}

.tab-text {
  display: inline-block;
}

.rename-icon {
  position: absolute;
  top: 0.5vh;
  right: 0.5vw;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.3s;
  padding: 0.2rem;
}

.rename-icon:hover {
  opacity: 1;
}

.rename-icon img {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.controls {
  gap: 1vh;
  display: flex;
}

.controls button,
.show-more-btn {
  border: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
  font-size: 1rem;
  padding: 1vh 1vw;
  border-radius: 0.6vh;
  transition: all 0.3s;
  box-shadow: 0 0.3vh 0.8vh rgba(0, 0, 0, 0.3);
}
.show-more-btn {
  height: 100%;
}

.controls button:hover,
.show-more-btn:hover {
  transform: scale(1.05);
}

.editor-container {
  flex: 1;
  gap: 1vh;
  padding: 1vh;
  display: flex;
  overflow: hidden;
  height: calc(100vh - 7vh);
}

.editor-panel,
.output-panel {
  display: flex;
  overflow: hidden;
  border-radius: 1vh;
  flex-direction: column;
  backdrop-filter: blur(1vh);
  box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.3);
}

.editor-panel {
  flex: 6;
}

.output-panel {
  flex: 4;
}

.editor {
  flex: 1;
  display: none;
  flex-direction: column;
}

.editor.active {
  display: flex;
}

/* .code-wrapper textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
} */

.output-panel iframe {
  flex: 1;
  border: none;
}

.output-panel {
  position: relative;
}

#openNewTabBtn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 10;
  padding: 4px;
  transition: transform 0.2s;
}

#openNewTabBtn:hover {
  transform: scale(1.1);
}

.output {
  flex: 3;
  display: flex;
  flex-direction: column;
}

.console {
  padding: 0.5vh;
  height: 20%;
  overflow-y: auto;
  font-size: 0.85rem;
  font-family: monospace;
}

.code-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.show-more-container {
  z-index: 9999;
  position: relative;
  display: inline-block;
}

.show-more-menu {
  right: 0;
  top: 4vh;
  z-index: 10000;
  display: none;
  overflow: hidden;
  border-radius: 1vh;
  position: absolute;
  box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.2);
}

.show-more-menu button {
  width: 100%;
  border: none;
  display: block;
  cursor: pointer;
  background: none;
  text-align: center;
  padding: 1vh 2vw;
}

#theme-toggle {
  height: 6vh;
  width: 6vh;
  padding: 0;
  border-radius: 50%;
  background-color: var(--base-varient);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.light-icon {
  display: block;
  fill: #102c57;
}

.dark-icon {
  display: none;
}

.dark-mode .light-icon {
  display: none;
}

.dark-mode .dark-icon {
  display: block;
}

/* ================================
   MOBILE PANEL TOGGLE BAR
   Hidden on desktop, shown on mobile
   ================================ */
.mobile-panel-toggle {
  display: none;
}

/* ================================
   MOBILE RESPONSIVE STYLES
   ================================ */
@media (max-width: 768px) {
  body,
  html {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
  }

  /* --- COMPACT HEADER --- */
  .header {
    height: auto;
    min-height: 44px;
    padding: 6px 10px;
    gap: 8px;
  }

  .header h2 {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header .header-buttons {
    gap: 6px;
    flex-shrink: 0;
  }

  /* Hide Projects and Save text on mobile, move to overflow */
  #my-projects-btn,
  #save-project-btn {
    display: none;
  }

  #login-button {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  #theme-toggle {
    height: 36px;
    width: 36px;
  }

  /* --- TABS BAR --- */
  .tabs {
    padding: 4px 8px;
    gap: 4px;
    flex-wrap: nowrap;
  }

  .tab-buttons {
    flex: 1;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px;
  }

  .tab-buttons::-webkit-scrollbar {
    display: none;
  }

  .tab {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: auto;
    padding-right: 24px;
  }

  .controls {
    gap: 4px;
    flex-shrink: 0;
  }

  .controls button,
  .show-more-btn {
    padding: 4px 10px;
    font-size: 0.8rem;
    min-height: 30px;
  }

  #newPageBtn {
    display: none;
  }

  /* --- EDITOR CONTAINER: FULL PANEL MODE --- */
  .editor-container {
    flex-direction: column;
    height: calc(100vh - 44px - 38px - 48px); /* header + tabs + toggle bar */
    padding: 0;
    gap: 0;
  }

  .editor-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    border-radius: 0;
    flex: 1;
  }

  .editor-panel.mobile-hidden {
    display: none !important;
  }

  .output-panel {
    width: 100%;
    height: 100%;
    border-radius: 0;
    flex: 1;
  }

  .output-panel.mobile-hidden {
    display: none !important;
  }

  .editor {
    flex: 1;
    display: none;
  }

  .editor.active {
    display: flex;
    flex-direction: column;
  }

  .code-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
    flex: 1;
  }

  #preview {
    width: 100%;
    height: 100%;
    flex: 1;
    border: none;
  }

  .console {
    height: 200px;
    min-height: 80px;
    max-height: 220px;
    overflow-y: auto;
    font-size: 0.8rem;
    padding: 8px 10px;
    padding-bottom: 12px;
    display: block;
    border-top: 2px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
  }

  /* Ensure output-panel reserves space above toggle bar */
  .output-panel {
    padding-bottom: 0;
  }

  .output-panel #preview {
    flex: 1;
  }

  .output-panel .output-header {
    flex-shrink: 0;
  }

  /* --- MOBILE PANEL TOGGLE BAR --- */
  .mobile-panel-toggle {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1500;
    padding: 0;
    gap: 0;
    height: 48px;
  }

  .panel-toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
    padding: 10px;
    min-height: 48px;
  }

  .panel-toggle-btn svg {
    flex-shrink: 0;
  }

  /* --- SIDEBAR & MODAL --- */
  .projects-sidebar {
    width: 100%;
    right: -100%;
  }

  .modal-content {
    min-width: auto;
    width: 90%;
    margin: 20px;
    padding: 20px;
  }

  /* --- SHOW MORE MENU --- */
  .show-more-menu {
    right: 0;
    top: 100%;
    min-width: 160px;
  }

  .show-more-menu button {
    padding: 12px 16px;
    font-size: 0.9rem;
    min-height: 44px;
  }
}

/* Projects Sidebar */
.projects-sidebar {
  position: fixed;
  top: 0;
  right: -450px;
  width: 450px;
  height: 100vh;
  background: #1e293b;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
  transition: right 0.3s ease;
  z-index: 2000;
  display: flex;
  flex-direction: column;
}

.projects-sidebar.open {
  right: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: #0f172a;
  border-bottom: 1px solid var(--base-varient);
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.close-sidebar {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--text);
  line-height: 1;
  padding: 0;
  width: 30px;
  height: 30px;
}

.projects-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background: rgba(0, 0, 0, 0.8);
}

.project-item {
  padding: 15px;
  margin: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.project-item:hover {
  transform: translateX(-5px);
  background: rgba(0, 0, 0, 0.4);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.project-info {
  flex: 1;
}

.project-name {
  font-weight: bold;
  margin-bottom: 5px;
}

.project-date {
  font-size: 0.85rem;
  opacity: 0.7;
}

.delete-project {
  background: #dc3545;
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.delete-project:hover {
  background: #c82333;
}

.loading, .no-projects {
  text-align: center;
  padding: 20px;
  opacity: 0.7;
}

/* Save Project Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 3000;
  justify-content: center;
  align-items: center;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--base);
  padding: 30px;
  border-radius: 10px;
  min-width: 400px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
  margin-top: 0;
  margin-bottom: 20px;
}

.modal-content input {
  width: 100%;
  padding: 10px;
  margin-bottom: 20px;
  border: 1px solid var(--base-varient);
  border-radius: 5px;
  background: var(--base-varient);
  color: var(--text);
  font-size: 1rem;
  box-sizing: border-box;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}

.btn-primary {
  background: #007bff;
  color: white;
}

.btn-primary:hover {
  background: #0056b3;
}

.btn-secondary {
  background: var(--base-varient);
  color: var(--text);
}

.btn-secondary:hover {
  opacity: 0.8;
}

#my-projects-btn, #save-project-btn {
  padding: 8px 16px;
  background-color: transparent;
  border: 2px solid var(--base-varient);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--text);
  transition: all 0.3s;
  box-shadow: 0 0.3vh 0.8vh rgba(0, 0, 0, 0.3);
}

#my-projects-btn:hover, #save-project-btn:hover {
  transform: scale(1.05);
  background-color: var(--base-varient);
  box-shadow: 0 0.5vh 1vh rgba(0, 0, 0, 0.4);
}

@media (max-width: 768px) {
  .projects-sidebar {
    width: 100%;
    right: -100%;
  }
  
  .modal-content {
    min-width: 90%;
    margin: 20px;
  }
}
