:root {
  --spacing: 20px;
  --radius-outer: 10px;
  --radius-inner: 5px;
  --color-accent: #4a4f7d;
  --bg-color-body: #f5f5f7;
  --text-body: #333333;
  --text-muted: #666666;
  --border-top-menu: #e0e0e0;
  --bg-wrapper: #ffffff;
  --bg-inner-container: #eeeeee;
  --bg-inputs: #ffffff;
  --bg-titles: linear-gradient(0deg, #f9f9f9 0%, #ffffff 100%);
  --header-bg: radial-gradient(circle, #ffffff 0%, #f0f0f0 100%);
  --footer-bg: #eeeeee;
  --white-005: rgba(0, 0, 0, 0.05);
  --white-015: rgba(0, 0, 0, 0.1);
  --black-050: rgba(0, 0, 0, 0.1);
  --topbar-height: 64px;
  --footer-height: 40px;
  --cm-gutter-border: #ddd;
  --cm-selected: rgba(0, 0, 0, 0.1);
  --logo-text: #4a4f7d;
  --button-text: #444;
}

[data-theme='dark'] {
  --spacing: 20px;
  --radius-outer: 10px;
  --radius-inner: 5px;
  --color-accent: #585e94;
  --bg-color-body: #0A0A0A;
  --text-body: #bbbbbb;
  --text-muted: #848484;
  --border-top-menu: #292929;
  --bg-wrapper: #131313;
  --bg-inner-container: #0a0a0a;
  --bg-inputs: #1C1C1C;
  --bg-titles: linear-gradient(0deg, #212121 0%, #171717 100%);
  --header-bg: radial-gradient(circle, #1a1a19 0%, #0f0e0e 100%);
  --footer-bg: #0f0e0e;
  --white-005: rgba(255, 255, 255, 0.05);
  --white-015: rgba(255, 255, 255, 0.15);
  --black-050: rgba(0, 0, 0, 0.50);
  --topbar-height: 64px;
  --footer-height: 40px;
  --cm-gutter-border: var(--white-005);
  --cm-selected: rgba(255, 255, 255, 0.1);
  --logo-text: #F0E4E1;
  --button-text: #EEE;
}

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

body,
html {
  height: 100%;
  background: var(--bg-color-body);
  color: var(--text-body);
  font-family: 'Google Sans', sans-serif;
  font-size: 13px;
  overflow: hidden;
}

.ph-bold:not(> #footer) {
  margin-right: 10px;
}

.CodeMirror {
  height: 100% !important;
  font-family: 'Google Sans Code', monospace;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.CodeMirror-gutters {
  border-right: 1px solid var(--cm-gutter-border) !important;
  white-space: nowrap;
}

.CodeMirror-linenumber {
  padding-right: 12px !important;
  padding-left: 8px !important;
  font-family: inherit !important;
  font-size: 12px !important;
  line-height: 1.5 !important;
}

.CodeMirror-line {
  line-height: 1.5 !important;
}

.cm-s-dracula.CodeMirror {
  background: var(--bg-inputs) !important;
  box-shadow: inset 2px 0 5px rgba(0, 0, 0, 0.2);
}

.cm-s-dracula .CodeMirror-gutters {
  background: var(--bg-inputs) !important;
  border-right: 1px solid var(--cm-gutter-border) !important;
}

.cm-s-dracula div.CodeMirror-selected {
  background: var(--cm-selected) !important;
}

.cm-s-neo .CodeMirror-linenumber {
  color: #888 !important;
}

.cm-s-neo .CodeMirror-gutters {
  background-color: #f7f7f7 !important;
  border-right: 1px solid #eee !important;
}

.cm-s-neo div.CodeMirror-selected {
  background: var(--cm-selected) !important;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-color-body);
}

::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 4px;
}

body.is-dragging {
  user-select: none !important;
  -webkit-user-select: none !important;
}

.header {
  height: var(--topbar-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-top-menu);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 100;
  box-shadow: inset 0 -1px 2px var(--white-005);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo span {
  font-family: 'Crimson Pro', serif;
  font-weight: 800;
  font-size: 24px;
  color: var(--logo-text);
  letter-spacing: -0.5px;
}

.logo i {
  font-size: 18px;
  color: var(--color-accent);
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.button {
  background: var(--bg-titles);
  border: 1px solid transparent;
  box-shadow: inset 0 -1px 2px var(--white-005);
  color: var(--button-text);
  padding: 8px 16px;
  border-radius: var(--radius-inner);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.button:hover {
  color: var(--color-accent);
  border-color: var(--white-015);
}

.button.active {
  border: 1px solid var(--white-015);
  background: var(--color-accent);
  color: white;
}

#main-wrapper {
  display: flex;
  height: calc(100vh - var(--topbar-height) - var(--footer-height));
  width: 100%;
  background: var(--bg-inner-container);
  position: relative;
}

#main-wrapper.vertical {
  flex-direction: column;
}

#main-wrapper.vertical #editor-pane {
  flex: 0 0 50%;
}

.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#editor-pane {
  flex: 1;
  background: var(--bg-inputs);
  opacity: 0;
  z-index: 1;
  overflow: hidden;
  position: relative;
}

.editor-toolbar {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 20;
  pointer-events: none;
}

.font-controls {
  background: var(--bg-wrapper);
  border: 1px solid var(--border-top-menu);
  border-radius: var(--radius-inner);
  padding: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px var(--black-050);
  pointer-events: auto;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.tool-button {
  background: var(--bg-titles);
  border: 1px solid var(--border-top-menu);
  color: var(--button-text);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-button:hover {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}

.tool-button i {
  font-size: 10px;
  margin: 0 !important;
}

#font-size-display {
  font-size: 11px;
  font-weight: 700;
  min-width: 32px;
  text-align: center;
  color: var(--text-muted);
}

#editor-pane.ready {
  opacity: 1;
}

#preview-pane {
  flex: 1;
  background: var(--bg-wrapper);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing);
  position: relative;
  z-index: 10;
  overflow: visible;
}

.preview-window-container {
  width: 100%;
  height: 100%;
  background: transparent;
  box-shadow: 0 10px 40px var(--black-050);
  border-radius: var(--radius-outer);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-top-menu);
  isolation: isolate;
  -webkit-mask-image: -webkit-radial-gradient(white, black);
  mask-image: -webkit-radial-gradient(white, black);
}

.window-bar {
  background: var(--bg-titles);
  border-bottom: 1px solid var(--white-005);
  box-shadow: inset 0 -1px 2px var(--white-005);
  padding: 10px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
}

#preview-iframe {
  width: 100%;
  flex: 1;
  border: none;
  background: transparent;
  opacity: 0;
}

#preview-iframe.loaded {
  opacity: 1;
}

.resizer {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 32px;
  z-index: 1000;
  margin-left: -16px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#main-wrapper.vertical .resizer {
  width: 100%;
  height: 32px;
  top: 0;
  left: 0;
  margin-left: 0;
  margin-top: -16px;
}

.drag-handle-button {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: var(--bg-titles);
  border: 1px solid var(--border-top-menu);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--button-text);
  box-shadow: 0 2px 8px var(--black-050);
  cursor: grab;
  transition: all 0.2s ease;
  pointer-events: auto;
  touch-action: none;
  z-index: 1001;
}

.drag-handle-button:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
  transform: scale(1.1);
}

body.is-dragging .drag-handle-button {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
  cursor: grabbing;
}

.drag-handle-button i {
  margin: 0 !important;
  font-size: 16px;
}

.vertical-icon,
#main-wrapper.vertical .horizontal-icon {
  display: none;
}

#main-wrapper.vertical .vertical-icon {
  display: flex;
}

.footer {
  height: var(--footer-height);
  background: var(--footer-bg);
  border-top: 1px solid var(--border-top-menu);
  justify-content: center;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  font-size: 11px;
  color: var(--text-muted);
}

.footer .links {
  display: flex;
  gap: 10px;
  margin-left: 30px;
}

.footer a {
  color: var(--text-body);
  text-decoration: none;
}

#theme-toggle {
  background: transparent;
  border: 0;
  color: var(--button-text);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 30px;
}

#theme-toggle:hover {
  transform: scale(1.1);
  border-color: var(--color-accent);
}

@media (max-width: 1200px) {
  .button:not(.active) .label {
    display: none;
  }

  .button:not(.active) .ph-bold {
    margin-right: 0;
  }

  .button.desktop-only[onclick="downloadCode()"] {
    margin-left: 8px !important;
  }
}

@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }

  .CodeMirror {
    touch-action: manipulation;
  }

  .CodeMirror textarea, 
  .CodeMirror-code {
    font-size: 16px !important;
  }
}

.search-replace-box {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 400px;
  background: var(--bg-wrapper);
  border: 1px solid var(--border-top-menu);
  border-radius: var(--radius-inner);
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px var(--black-050);
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px;
  gap: 8px;
  transform: translateY(-10px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-replace-box.active {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.search-row,
.replace-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-input-wrapper,
.replace-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-inputs);
  border: 1px solid var(--border-top-menu);
  border-radius: 4px;
  padding: 0;
  height: 30px;
  cursor: text;
  transition: border-color 0.2s ease;
}

.search-input-wrapper:hover,
.replace-input-wrapper:hover {
  border-color: var(--color-accent);
}

.search-input-wrapper input,
.replace-input-wrapper input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-body);
  font-family: 'Google Sans', sans-serif;
  font-size: 11px;
  padding: 0 12px;
  width: 100%;
  height: 100%;
}

.search-results-info {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 12px 0 8px;
  white-space: nowrap;
  border-left: 1px solid var(--border-top-menu);
  height: 100%;
  display: flex;
  align-items: center;
}

.search-actions,
.replace-actions {
  display: flex;
  gap: 4px;
}

.action-button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-button:hover {
  background: var(--white-015);
  color: var(--text-body);
}

.action-button.active {
  background: var(--color-accent);
  color: white;
}

.action-button i {
  font-size: 14px;
  margin: 0 !important;
}

.replace-row {
  display: none;
  border-top: 1px solid var(--border-top-menu);
  padding-top: 8px;
}

.replace-row.show {
  display: flex;
}

.search-replace-toggle {
  width: 20px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
}

.search-replace-toggle i {
  font-size: 12px;
  margin: 0 !important;
  transition: transform 0.2s ease;
}

.search-replace-toggle.active i {
  transform: rotate(90deg);
}

.cm-search-marker {
  background: rgba(255, 255, 0, 0.2);
  border-bottom: 2px solid rgba(255, 255, 0, 0.4);
}

[data-theme='dark'] .cm-search-marker {
  background: rgba(255, 255, 255, 0.1);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.cm-search-marker-current {
  background: rgba(255, 165, 0, 0.4) !important;
  border-bottom: 2px solid rgba(255, 165, 0, 0.8) !important;
  box-shadow: 0 0 10px rgba(255, 165, 0, 0.2);
}

.search-replace-box.no-results {
  border-color: rgba(255, 85, 85, 0.5);
}

.search-replace-box.no-results #search-results-info {
  color: #ff5555;
}