/* Noka Viewer v1.6.3 — unified styling for Markdown + CSS viewers */

/* ---------- THEME VARIABLES ---------- */
:root {
  --bg: #f5f5f5;
  --text: #111111;
  --accent: #5eead4;
  --accent-hover: #2dd4bf;
  --border: #e5e7eb;
  --surface: #ffffff;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --text: #f1f5f9;
  --accent: #5eead4;
  --accent-hover: #2dd4bf;
  --border: #1e293b;
  --surface: #1e293b;
}

/* ---------- GLOBAL LAYOUT ---------- */
html, body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  scroll-behavior: smooth;
  line-height: 1.6;
}

button, select, input, textarea {
  font: inherit;
  color: inherit;
  background: none;
  outline: none;
}

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

/* ---------- COMPONENTS ---------- */
header {
  transition: background 0.3s ease, color 0.3s ease;
}

textarea {
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

button {
  transition: all 0.25s ease;
  cursor: pointer;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- MARKDOWN RENDERED AREA ---------- */
.prose {
  color: var(--text);
  max-width: none;
  line-height: 1.7;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  color: var(--accent);
  font-weight: 600;
  margin-top: 1.5em;
  margin-bottom: 0.6em;
}

.prose h1 {
  font-size: 1.8rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3em;
}

.prose h2 {
  font-size: 1.4rem;
  margin-top: 1.3em;
}

.prose h3 {
  font-size: 1.2rem;
}

.prose p {
  margin-bottom: 0.9em;
}

.prose ul,
.prose ol {
  margin-left: 1.2em;
  margin-bottom: 1em;
}

.prose li {
  margin-bottom: 0.3em;
}

.prose code {
  background: rgba(148, 163, 184, 0.15);
  border-radius: 4px;
  padding: 0.2em 0.4em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95em;
}

.prose pre {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.8em 1em;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1.2em;
}

.prose pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 0.9em;
}

/* Highlight.js syntax */
.hljs {
  background: transparent !important;
  color: inherit;
}

/* ---------- FORMS & CONTROLS ---------- */
input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 2px var(--accent-hover)40;
}

/* ---------- HEADER / TOOLBAR ---------- */
header .h-1 {
  background-image: linear-gradient(
    to right,
    var(--accent),
    var(--accent-hover)
  );
}

header button svg {
  width: 18px;
  height: 18px;
}

/* ---------- SCROLLBARS ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background-color: var(--accent-hover);
  border-radius: 6px;
}

/* ---------- RESPONSIVE LAYOUT ---------- */
@media (max-width: 1024px) {
  main {
    grid-template-columns: 1fr !important;
  }

  textarea, iframe, #md-rendered {
    height: 60vh !important;
  }

  header > div:last-child {
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
  }
}

/* ---------- MARKDOWN SPACING IMPROVEMENTS ---------- */
#md-rendered {
  line-height: 1.7;
  padding: 1.2rem;
  border-radius: 10px;
}

#md-rendered hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

#md-rendered table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1em;
}

#md-rendered th,
#md-rendered td {
  border: 1px solid var(--border);
  padding: 0.4em 0.8em;
}

#md-rendered blockquote {
  border-left: 3px solid var(--accent-hover);
  margin: 0.8em 0;
  padding-left: 1em;
  opacity: 0.9;
}

mark.md-match {
  background: var(--accent-hover);
  color: var(--text);
  border-radius: 3px;
  padding: 0 2px;
}

mark.md-match-active {
  outline: 2px solid #5eead4;
  outline-offset: 2px;
  background: #5eead4;
  color: #111;
}

[data-theme='light'] .search-counter {
  background: rgba(255, 255, 255, 0.8);
  color: #111;
  border: 1px solid rgba(0, 0, 0, 0.1);
}
[data-theme='dark'] .search-counter {
  background: rgba(0, 0, 0, 0.6);
  color: #f1f5f9;
}

/* ---------- FOOTER ---------- */
footer {
  border-top: 1px solid var(--border);
  margin-top: auto;
  background: var(--surface);
  color: var(--text);
}

/* ---------- COLLAPSE EDITOR TOGGLE ---------- */
.collapse-icon {
  display: none;
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: transform 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.collapse-icon:hover {
  color: var(--accent-hover);
  background: var(--accent-hover)/10;
  transform: scale(1.1);
}

/* ---------- MOBILE RESPONSIVE MARKDOWN VIEWER (v1.6.3) ---------- */
@media (max-width: 768px) {
  /* Show collapse toggle on mobile */
  .collapse-icon {
    display: inline-block;
  }

  body {
    overflow-x: hidden;
  }

  main {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0.75rem !important;
    max-width: 100vw;
    box-sizing: border-box;
  }

  /* Editor section with smooth slide animation */
  #editor-section {
    max-height: 80vh;
    overflow: hidden;
    opacity: 1;
    transform: translateY(0);
    transition: max-height 200ms ease, opacity 200ms ease, transform 200ms ease, margin 200ms ease;
    width: 100%;
    box-sizing: border-box;
  }

  /* Collapsed state */
  body.collapsed #editor-section {
    max-height: 0;
    opacity: 0;
    transform: translateY(-10px);
    margin: 0;
    padding: 0;
  }

  /* Hide editor buttons when collapsed */
  body.collapsed #editor-buttons {
    display: none;
  }

  /* Preview section takes full width when collapsed */
  body.collapsed #preview-section {
    width: 100%;
  }

  #md-source,
  #md-rendered {
    width: 100% !important;
    max-width: 100%;
    min-height: 280px;
    height: auto;
    box-sizing: border-box;
    resize: vertical;
    overflow-x: auto;
    overflow-y: auto;
  }

  #md-source {
    font-size: 0.85rem;
    padding: 0.75rem;
  }

  body.collapsed #md-rendered {
    min-height: 70vh;
  }

  #md-tools {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  #md-tools select,
  #md-tools button,
  #md-search {
    flex: 1 1 45%;
    min-width: 100px;
    font-size: 0.85rem;
  }

  section {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* ---------- CSS VIEWER RESPONSIVE ---------- */
@media (max-width: 768px) {
  #css-viewer main {
    grid-template-columns: 1fr;
  }

  #css-editor,
  #css-preview {
    height: 50vh !important;
  }

  #preview-editor {
    width: 100%;
  }
}
