:root {
  --bg-color: #f8fafc;
  --bg-panel: #ffffff;
  --bg-header: #0f172a;
  
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-inverse: #f8fafc;
  
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  
  --border-color: #e2e8f0;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

/* Disable ligatures globally for code elements */
code, pre, .font-mono {
  font-variant-ligatures: none;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header & Navigation */
.app-header {
  background-color: var(--bg-header);
  color: var(--text-inverse);
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0 1.5rem;
  height: 60px;
  flex-shrink: 0;
}

.logo {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.05em;
  margin-right: 3rem;
  display: flex;
  align-items: center;
}

.main-nav {
  display: flex;
  gap: 1rem;
  height: 100%;
}

.nav-btn {
  background: none;
  border: none;
  color: #94a3b8;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0 1rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

.nav-btn:hover {
  color: var(--text-inverse);
  background: rgba(255, 255, 255, 0.05);
}

.nav-btn.active {
  color: var(--text-inverse);
  background: rgba(255, 255, 255, 0.1);
  border-bottom: 3px solid var(--primary-color);
}

/* App Content Area */
.app-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.view {
  display: none;
  height: 100%;
  width: 100%;
}

.view.active-view {
  display: flex;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Playground Layout */
.pg-layout {
  display: grid;
  grid-template-columns: 280px 1fr 1fr;
  width: 100%;
  height: 100%;
  gap: 2px;
  background: var(--border-color);
}

.pg-layout.sidebar-collapsed {
  grid-template-columns: 1fr 1fr;
}

.pg-sidebar {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 65px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-header h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 0;
}

.pg-sidebar.collapsed {
  display: none;
}

.pg-editor {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
}

.pg-preview {
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
}

/* Sidebar Elements (Asset Loading) */
.sidebar-content-scroll {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.sidebar-section {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-section:first-child {
  border-bottom: 1px solid var(--border-color);
}

.sidebar-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.asset-list {
  list-style: none;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0;
}

.asset-list li {
  background: var(--bg-color);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
}

.btn-delete, .btn-delete-image {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.25rem;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-delete:hover, .btn-delete-image:hover {
  opacity: 1;
  color: #e53e3e;
}

.asset-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.asset-form input {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
}

.btn-secondary:hover {
  background: #eff6ff;
}

.btn-cancel {
  background: #e2e8f0;
  color: var(--text-primary);
}

.btn-cancel:hover {
  background: #cbd5e1;
}

.panel-icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  line-height: 1;
}

.panel-icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.empty-state {
  background: #f1f5f9;
  border-radius: 6px;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 0;
}

/* Editor Panel */
.error-alert {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #fecaca;
}

.error-alert i {
  font-size: 1.1rem;
}

/* Template Bar */
.template-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.5rem;
  height: 65px;
  background: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  flex-shrink: 0;
}

.template-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.template-btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.template-btn:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.template-btn.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
}

textarea#dmd-input {
  flex: 1;
  width: 100%;
  border: none;
  padding: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
  resize: none;
  background: transparent;
  outline: none;
}

/* Preview Panel */
#pdf-viewer {
  width: 100%;
  height: 100%;
  border: none;
  background-color: #525659; /* PDF.js typical grey background */
}

/* Generic Split Layout for Tutorials & Reference */
.split-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
  height: 100%;
  gap: 1px;
  background: var(--border-color);
}

.toc-sidebar {
  background: var(--bg-panel);
  padding: 2rem 1.5rem;
  overflow-y: auto;
}

.toc-sidebar h3 {
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toc-list a {
  display: block;
  text-decoration: none;
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.toc-list a:hover {
  background: var(--bg-color);
  color: var(--text-primary);
}

.toc-list a.active {
  background: #eff6ff;
  color: var(--primary-color);
  font-weight: 500;
}

.content-scroll-area {
  background: var(--bg-panel);
  overflow-y: auto;
  width: 100%;
}

.content-area {
  padding: 3rem 4rem;
  max-width: 900px;
  margin: 0 auto;
}

.content-area h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.content-area p {
  color: var(--text-secondary);
  line-height: 1.7;
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
}

.content-area h3 {
  font-size: 1.25rem;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.content-area h4 {
  font-size: 1rem;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.content-area pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre;
  word-wrap: normal;
}

.content-area code {
  font-family: var(--font-mono);
  background: #f1f5f9;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9em;
  color: #0f172a;
  font-variant-ligatures: none;
}

.content-area pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-variant-ligatures: none;
}

.content-area ul {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

.content-area ul li {
  margin-bottom: 0.35rem;
}

/* Reference Tables */
.ref-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.ref-table th,
.ref-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.ref-table th {
  background: var(--bg-color);
  font-weight: 600;
  color: var(--text-primary);
}

.ref-table td {
  color: var(--text-secondary);
}

.ref-table code {
  background: #f1f5f9;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  font-variant-ligatures: none;
}

/* Example Action Buttons */
.example-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
}

pre.dmd-example:hover .example-actions {
  opacity: 1;
}

.example-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s;
}

.example-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.example-btn svg {
  flex-shrink: 0;
}

/* Font List Items */
.content-area ul.font-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.5rem;
  list-style: none;
  padding-left: 0;
  margin-bottom: 1.5rem;
}

.font-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.font-item:hover {
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.font-name {
  font-size: 1.15rem;
  color: var(--text-primary);
}

.font-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* Copy Toast */
.copy-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-header);
  color: var(--text-inverse);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
}

.copy-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
