*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #020617;
  --bg-elevated: #0f172a;
  --fg: #e5e7eb;
  --fg-muted: #9ca3af;
  --accent: #38bdf8;
  --border-subtle: #1f2937;
  --code-bg: #111827;
  --danger: #f97373;
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.45);
  --radius-lg: 14px;
  --radius-md: 10px;
}

body.light {
  color-scheme: light;
  --bg: #f3f4f6;
  --bg-elevated: #ffffff;
  --fg: #111827;
  --fg-muted: #6b7280;
  --accent: #2563eb;
  --border-subtle: #e5e7eb;
  --code-bg: #f9fafb;
  --danger: #b91c1c;
  --shadow-soft: 0 16px 30px rgba(15, 23, 42, 0.12);
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background-color: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(to bottom, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.9));
  backdrop-filter: blur(18px);
}

body.light .app-header {
  background: linear-gradient(to bottom, rgba(249, 250, 251, 0.9), rgba(249, 250, 251, 0.86));
}

.app-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 20%, #38bdf8, #1d4ed8);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 1.25rem;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.65);
}

.app-text h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.app-text p {
  margin: 0;
  margin-top: 0.1rem;
  font-size: 0.8rem;
  color: var(--fg-muted);
}

.app-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.file-input {
  display: none;
}

.action-button {
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  padding: 0.3rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    transform 120ms ease;
}

.action-button:hover {
  background-color: rgba(56, 189, 248, 0.08);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.action-button:active {
  transform: translateY(0);
}

.icon-button {
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.7);
  color: var(--fg-muted);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    transform 120ms ease;
}

body.light .icon-button {
  background: rgba(255, 255, 255, 0.85);
}

.icon-button:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.icon-button:active {
  transform: translateY(0);
}

/* Main layout */

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto 0.75rem;
}

.pane {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-elevated);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(15, 23, 42, 0.7);
  box-shadow: var(--shadow-soft);
  min-height: 0;
}

.pane-header {
  padding: 0.75rem 0.9rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.7);
}

.pane-header h2 {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--fg-muted);
}

.pane-hint {
  font-size: 0.75rem;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pane-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pane-body {
  flex: 1;
  padding: 0.8rem 0.9rem 0.9rem;
  min-height: 0;
}

/* Editor */

#editor {
  width: 100%;
  height: 100%;
  min-height: 260px;
  resize: none;
  border-radius: var(--radius-md);
  border: 1px solid rgba(15, 23, 42, 0.9);
  background-color: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 0.8rem 0.85rem;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

body.light #editor {
  border-color: rgba(209, 213, 219, 0.9);
}

#editor::placeholder {
  color: var(--fg-muted);
}

#editor:focus {
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px rgba(56, 189, 248, 0.75),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Preview */

.pane-preview .pane-body {
  overflow: visible;
}

#preview {
  min-height: 260px;
  padding: 1rem 1.25rem;
}

.preview-wrapper {
  display: none;
  justify-content: center;
}

.cm-live-root {
  min-height: calc(100vh - 180px);
  border-radius: 8px;
  background-color: var(--bg-elevated);
  max-width: 900px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 45vh;
}

.live-block-shell {
  position: relative;
  border-radius: 6px;
  margin: 0.15rem 0;
  padding: 0.1rem 2.8rem 0.1rem 0.15rem;
  cursor: text;
  transition:
    background-color 140ms ease,
    box-shadow 140ms ease;
}

.live-block-shell:hover,
.live-block-shell:focus {
  background-color: rgba(56, 189, 248, 0.08);
  box-shadow: inset 2px 0 0 rgba(56, 189, 248, 0.65);
  outline: none;
}

.live-block-shell.active {
  background-color: rgba(2, 6, 23, 0.35);
  padding-right: 0.15rem;
}

body.light .live-block-shell.active {
  background-color: rgba(243, 244, 246, 0.8);
}

.live-block {
  cursor: text;
  max-width: none;
  min-height: 1.35rem;
  padding: 0.05rem 0.2rem;
}

.live-block:focus {
  outline: 1px solid rgba(56, 189, 248, 0.45);
  outline-offset: 2px;
}

.live-edit-button {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  opacity: 0;
  pointer-events: none;
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 5px;
  background-color: rgba(15, 23, 42, 0.92);
  color: var(--accent);
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.3rem 0.42rem;
  cursor: pointer;
  transition:
    opacity 120ms ease,
    background-color 120ms ease;
}

.live-block-shell:hover .live-edit-button,
.live-block-shell:focus .live-edit-button,
.live-edit-button:focus {
  opacity: 1;
  pointer-events: auto;
}

.live-edit-button:hover {
  background-color: rgba(56, 189, 248, 0.14);
}

body.light .live-edit-button {
  background-color: rgba(255, 255, 255, 0.96);
}

.live-block-editor {
  width: 100%;
  min-height: 2.3rem;
  resize: none;
  overflow: hidden;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 6px;
  background-color: rgba(2, 6, 23, 0.72);
  color: var(--fg);
  caret-color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95rem;
  line-height: 1.55;
  padding: 0.55rem 0.65rem;
  outline: none;
}

body.light .live-block-editor {
  background-color: #ffffff;
  border-color: rgba(37, 99, 235, 0.45);
}

/* Markdown content styling */

.markdown-body {
  font-size: 0.95rem;
  line-height: 1.65;
  max-width: 820px;
  margin: 0 auto;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.2em;
  margin-bottom: 0.4em;
  line-height: 1.3;
  font-weight: 600;
}

.markdown-body h1 {
  font-size: 1.6rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.3em;
}

.markdown-body h2 {
  font-size: 1.35rem;
}

.markdown-body h3 {
  font-size: 1.2rem;
}

.markdown-body p {
  margin-top: 0.4em;
  margin-bottom: 0.6em;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.4rem;
  margin: 0.3em 0 0.7em;
}

.markdown-body li {
  margin: 0.15em 0;
}

.markdown-body blockquote {
  border-left: 3px solid rgba(156, 163, 175, 0.8);
  margin: 0.9em 0;
  padding: 0.35rem 0.9rem;
  color: var(--fg-muted);
  background-color: rgba(15, 23, 42, 0.35);
  border-radius: 0 6px 6px 0;
}

body.light .markdown-body blockquote {
  background-color: rgba(243, 244, 246, 0.9);
}

.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85em;
  background-color: rgba(15, 23, 42, 0.85);
  border-radius: 4px;
  padding: 0.12em 0.35em;
}

body.light .markdown-body code {
  background-color: rgba(229, 231, 235, 0.9);
}

.markdown-body pre {
  position: relative;
  margin: 0.9em 0;
  padding: 1.65rem 1rem 0.9rem;
  border-radius: var(--radius-md);
  background-color: var(--code-bg);
  border: 1px solid rgba(75, 85, 99, 0.7);
  overflow-x: auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.markdown-body pre[data-language]::before {
  content: attr(data-language);
  position: absolute;
  top: 0.45rem;
  right: 0.65rem;
  color: #94a3b8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.68rem;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.84rem;
  line-height: 1.6;
}

.markdown-body pre code.hljs {
  display: block;
  color: #abb2bf;
  background: transparent;
  padding: 0;
}

.code-keyword {
  color: #ff7b72;
  font-weight: 600;
}

.code-string {
  color: #a5d6ff;
}

.code-number {
  color: #f2cc60;
}

.code-comment {
  color: #8b949e;
  font-style: italic;
}

.plantuml-diagram {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid rgba(75, 85, 99, 0.7);
  border-radius: var(--radius-md);
  background-color: #f8fafc;
  overflow-x: auto;
}

.plantuml-diagram img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

body.light .plantuml-diagram {
  border-color: rgba(209, 213, 219, 0.9);
  background-color: #ffffff;
}

/* Tables */

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.9em 0;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
}

.markdown-body th {
  background-color: rgba(15, 23, 42, 0.85);
  font-weight: 500;
}

body.light .markdown-body th {
  background-color: #f3f4f6;
}

/* Horizontal rule */

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: 1.2em 0;
}

.raw-section {
  margin: 0.6em 0;
  padding: 0.45rem 0.6rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9rem;
  background-color: rgba(15, 23, 42, 0.7);
  border-radius: 6px;
  border: 1px dashed rgba(148, 163, 184, 0.9);
}

body.light .raw-section {
  background-color: #f9fafb;
  border-color: rgba(148, 163, 184, 0.9);
}

/* MathJax tweaks */

.markdown-body mjx-container {
  font-size: 1em;
  line-height: 1.2;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.markdown-body mjx-container[display="true"] {
  margin: 0.8em 0 1em;
}

#MJX-SVG-global-cache,
svg[id^="MJX-SVG"] {
  display: none !important;
}

/* Footer */

.app-footer {
  padding: 0.35rem 1.25rem 0.75rem;
  font-size: 0.75rem;
  color: var(--fg-muted);
  border-top: 1px solid var(--border-subtle);
}

/* Responsive */

@media (max-width: 900px) {
  .app-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

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

  .pane-hint {
    white-space: normal;
  }
}

