:root {
  color-scheme: light;
  --bg: #f8f7ff;
  --bg-accent: #f2f7ff;
  --ink: #1b1736;
  --muted: #5b5875;
  --panel: #ffffff;
  --panel-edge: #e1deff;
  --accent: #4b1cff;
  --accent-strong: #3512c7;
  --accent-soft: #e8e1ff;
  --shadow: 0 18px 40px rgba(20, 16, 60, 0.12);
  --tooltip-bg: #1b1736;
  --tooltip-ink: #f6f4ff;
  --tooltip-shadow: 0 16px 32px rgba(20, 16, 60, 0.28);
  --page-bg: radial-gradient(circle at top left, #ffffff 0%, #f5f2ff 45%, #e8f5ff 100%);
  --radius: 16px;
  --mono: "IBM Plex Mono", "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;
  --sans: "Space Grotesk", "Sora", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--page-bg);
  background-attachment: fixed;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ff3ea5 0%, #7c4dff 55%, #4be0ff 100%);
  box-shadow: 0 10px 24px rgba(124, 77, 255, 0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.subtle-icon {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.subtle-icon:hover {
  border-color: var(--panel-edge);
  background: var(--panel);
}

.modal-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  text-decoration: none;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

a.btn {
  font-weight: 600;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(31, 29, 26, 0.12);
}

.tutorial-tooltip {
  position: fixed;
  z-index: 2000;
  max-width: 280px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--tooltip-bg);
  color: var(--tooltip-ink);
  box-shadow: var(--tooltip-shadow);
  font-size: 13px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.tutorial-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.tutorial-tooltip-title {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 6px;
  opacity: 0.85;
}

.tutorial-highlight {
  outline: 2px solid rgba(75, 28, 255, 0.35);
  outline-offset: 3px;
  border-radius: 12px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-strong);
}

.current-project {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 0;
  border-radius: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  min-width: 0;
}

.current-project-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.current-project-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}

.current-project-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meta-btn {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.meta-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.project-manager {
  position: relative;
}

.manager-panel {
  position: absolute;
  top: calc(100% + 14px);
  right: 0;
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 10;
}

.manager-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
}

.manager-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.manager-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.manager-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.manager-input {
  flex: 1 1 180px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 12px;
  font-family: var(--sans);
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.project-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--bg-accent);
}

.project-item.active {
  border-color: var(--accent);
}

.project-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
}

.project-name {
  font-weight: 600;
}

.project-updated {
  font-size: 11px;
  color: var(--muted);
}

.project-action {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.project-action.danger {
  border-color: rgba(210, 72, 60, 0.4);
  color: #b1261c;
}

.project-action:disabled {
  opacity: 0.6;
  cursor: default;
}

.workspace {
  position: relative;
  display: flex;
  gap: 20px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-edge);
  font-weight: 600;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.mode-btn {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  width: 30px;
  height: 30px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  transition: stroke 0.15s ease, transform 0.15s ease;
}

.icon-btn.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(75, 28, 255, 0.18);
}

.icon-btn.pulse {
  animation: pulse-ring 1.6s ease-out 2;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(75, 28, 255, 0.18);
}

@keyframes pulse-ring {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(75, 28, 255, 0.28);
  }
  80% {
    transform: scale(1.025);
    box-shadow: 0 0 0 14px rgba(75, 28, 255, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(75, 28, 255, 0);
  }
}

.icon-btn:hover,
.meta-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(31, 29, 26, 0.12);
}

.icon-btn:hover svg,
.meta-btn:hover svg {
  stroke: var(--accent);
  transform: scale(1.05);
}


.file-panel {
  width: 240px;
  flex: 0 0 240px;
  min-width: 200px;
}

.editor-panel {
  flex: 1 1 55%;
  min-width: 320px;
}

.preview-panel {
  flex: 1 1 45%;
  min-width: 280px;
}

.splitter {
  width: 10px;
  min-width: 10px;
  flex: 0 0 10px;
  border-radius: 999px;
  background: rgba(75, 28, 255, 0.12);
  cursor: col-resize;
  align-self: stretch;
  transition: background 0.2s ease;
  touch-action: none;
}

.splitter:hover,
.resizing .splitter {
  background: rgba(75, 28, 255, 0.35);
}

.workspace.file-collapsed .file-panel {
  display: none;
}

 

.file-tree {
  padding: 12px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 13px;
}

.file-item {
  padding: 6px 8px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-folder {
  background: rgba(75, 28, 255, 0.06);
}

.file-folder .file-item-actions {
  margin-left: auto;
}

.file-item.drag-over {
  border: 1px dashed var(--accent);
}

.file-tree.drag-root {
  outline: 1px dashed var(--accent);
  outline-offset: -6px;
}

.file-item.active {
  background: var(--accent-soft);
  border: 1px solid rgba(214, 90, 49, 0.3);
}

.file-item span {
  flex: 1;
  word-break: break-all;
}

.file-item-actions {
  display: flex;
  gap: 6px;
}

.file-item .icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1;
}

.editor-wrap {
  position: relative;
  flex: 1;
  display: flex;
}

.editor {
  flex: 1;
  border: none;
  padding: 18px;
  font-family: var(--mono);
  font-size: 14px;
  background: transparent;
  resize: none;
  outline: none;
}

.CodeMirror {
  flex: 1;
  height: 100%;
  font-family: var(--mono);
  font-size: 14px;
  border-radius: 0 0 var(--radius) var(--radius);
}

:root[data-editor-theme="dark"] .CodeMirror {
  background: #1b1736;
  color: #f6f5ff;
}

:root[data-editor-theme="dark"] .CodeMirror-gutters {
  background: #231f47;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.binary-notice {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: rgba(255, 250, 242, 0.95);
  font-weight: 600;
}

.hidden {
  display: none;
}

.preview-wrap {
  flex: 1;
  padding: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  background: #fff;
}

.warnings {
  padding: 8px 18px 0;
  font-size: 12px;
  color: #7a1f0d;
}

.warnings:empty {
  display: none;
}

.status {
  font-size: 12px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 10, 26, 0.45);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.checkbox-row input {
  accent-color: var(--accent);
}

.modal-input,
.modal-textarea {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 12px;
  font-family: var(--sans);
}

.modal-textarea {
  min-height: 96px;
  resize: vertical;
}

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

.modal-text {
  margin: 0;
  color: var(--muted);
}

.modal-version {
  color: var(--ink);
}

#loginError {
  color: #b00020;
  font-weight: 600;
}

.login-spacer {
  height: 10px;
}

#accountModal .modal-panel {
  text-align: center;
}

#accountModal .modal-body {
  align-items: center;
  gap: 14px;
}

#accountModal .modal-actions {
  justify-content: center;
}

#accountModal .modal-input {
  width: min(320px, 100%);
}

#accountModal .modal-label {
  align-self: flex-start;
  width: min(320px, 100%);
}

#loginPanel,
#accountPanel {
  width: 100%;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

#loginPanel:not(.hidden),
#accountPanel:not(.hidden) {
  display: flex;
}

.modal-url {
  font-family: var(--mono);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--panel-edge);
  background: var(--bg-accent);
  word-break: break-all;
}

.modal-password {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (max-width: 1100px) {
  .workspace {
    flex-direction: column;
  }

  .panel {
    min-height: 320px;
  }

  .file-panel,
  .editor-panel,
  .preview-panel {
    width: 100%;
    flex: 1 1 auto;
  }

  .splitter {
    display: none;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .manager-panel {
    position: static;
    width: 100%;
  }

  .current-project {
    width: 100%;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1020;
  --bg-accent: #1b1a33;
  --ink: #f1f1ff;
  --muted: #c2bddf;
  --panel: #151326;
  --panel-edge: #3a3563;
  --accent: #7b6bff;
  --accent-strong: #5141d7;
  --accent-soft: #2b2552;
  --shadow: 0 18px 40px rgba(6, 6, 14, 0.5);
  --tooltip-bg: #f6f4ff;
  --tooltip-ink: #1b1736;
  --tooltip-shadow: 0 18px 36px rgba(6, 6, 14, 0.45);
  --page-bg: radial-gradient(circle at top left, #1a1733 0%, #0f0f1f 55%, #0b0b17 100%);
}

:root[data-theme="dark"] .btn:hover {
  box-shadow: 0 6px 16px rgba(10, 10, 20, 0.45);
}

:root[data-theme="dark"] .modal-backdrop {
  background: rgba(6, 6, 14, 0.7);
}

:root[data-theme="dark"] .modal-panel {
  background: #1d1a36;
  border-color: #4a4580;
  box-shadow: 0 24px 60px rgba(6, 6, 14, 0.6);
}

:root[data-theme="dark"] .manager-panel {
  background: #1d1a36;
  border-color: #4a4580;
  box-shadow: 0 24px 60px rgba(6, 6, 14, 0.6);
}

:root[data-theme="dark"] .splitter {
  background: rgba(123, 107, 255, 0.35);
}

:root[data-theme="dark"] .splitter:hover,
:root[data-theme="dark"] .resizing .splitter {
  background: rgba(123, 107, 255, 0.65);
}

:root[data-theme="dark"] .file-item.active {
  border-color: rgba(146, 128, 255, 0.4);
}

:root[data-theme="dark"] .binary-notice {
  background: rgba(24, 21, 40, 0.96);
  color: var(--ink);
}

:root[data-theme="dark"] #previewFrame {
  background: #0f0f1c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0f1020;
    --bg-accent: #1b1a33;
    --ink: #f1f1ff;
    --muted: #c2bddf;
    --panel: #151326;
    --panel-edge: #3a3563;
    --accent: #7b6bff;
    --accent-strong: #5141d7;
    --accent-soft: #2b2552;
    --shadow: 0 18px 40px rgba(6, 6, 14, 0.5);
    --tooltip-bg: #f6f4ff;
    --tooltip-ink: #1b1736;
    --tooltip-shadow: 0 18px 36px rgba(6, 6, 14, 0.45);
    --page-bg: radial-gradient(circle at top left, #1a1733 0%, #0f0f1f 55%, #0b0b17 100%);
  }

  :root:not([data-theme]) .btn:hover {
    box-shadow: 0 6px 16px rgba(10, 10, 20, 0.45);
  }

  :root:not([data-theme]) .modal-backdrop {
    background: rgba(6, 6, 14, 0.7);
  }

  :root:not([data-theme]) .modal-panel {
    background: #1d1a36;
    border-color: #4a4580;
    box-shadow: 0 24px 60px rgba(6, 6, 14, 0.6);
  }

  :root:not([data-theme]) .manager-panel {
    background: #1d1a36;
    border-color: #4a4580;
    box-shadow: 0 24px 60px rgba(6, 6, 14, 0.6);
  }

  :root:not([data-theme]) .splitter {
    background: rgba(123, 107, 255, 0.35);
  }

  :root:not([data-theme]) .splitter:hover,
  :root:not([data-theme]) .resizing .splitter {
    background: rgba(123, 107, 255, 0.65);
  }

  :root:not([data-theme]) .file-item.active {
    border-color: rgba(146, 128, 255, 0.4);
  }

  :root:not([data-theme]) .binary-notice {
    background: rgba(24, 21, 40, 0.96);
    color: var(--ink);
  }

  :root:not([data-theme]) #previewFrame {
    background: #0f0f1c;
  }
}
