:root {
  color-scheme: dark;
  --paper: #ffffff;
  --accent: #f05a5a;
  --accent-strong: #d21e1e;
  --accent-deep: #b30e0e;
  --accent-dark: #9e0000;
  --accent-shadow: #620505;
  --surface-1: #42464b;
  --surface-2: #2b2f35;
  --surface-3: #1e2124;
  --surface-4: #161718;
  --surface-5: #0d0d0d;
  --ink: #000000;
}

/* General page styles */
body {
    display: flex;
    flex-direction: row;
    margin: 0;
    font-family: 'Noto Sans', sans-serif;
    background-color: var(--surface-5);
    color: var(--paper);
    height: 100vh;
}

.monospace {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
    font-size: 18px;
    letter-spacing: 0;
    white-space: pre-wrap;
    word-wrap: normal;
    display: inline;
    line-height: 1.0;
}

/* Toolbar styles */
#toolbar {
    display: flex;
    /*align-items: flex-start;*/
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    background: linear-gradient(180deg, var(--surface-3), var(--surface-4));
    border-right: 1px solid var(--surface-2);
    color: var(--paper);
    width: 280px;
    box-sizing: border-box;
}

/* Editor styles */
#editor {
    flex: 6; /* Increased flex for more width */
    padding: 15px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    font-family: monospace;
    background-color: var(--surface-4);
    color: var(--paper);
    border-right: 1px solid var(--surface-2);
    height: 100vh;
    box-sizing: border-box;
    resize: none;
}

/* Render container and wrapper styles */
#render-container {
    flex: 3; /* Adjusted flex to balance space */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

#render-wrapper {
    display: inline-block;
    margin-bottom: 20px;
}

#render {
    width: 520px;
    min-height: 724px;
    padding: 20px;
    background-color: var(--paper);
    font-family: 'Noto Sans', sans-serif;
    font-size: 16px;
    font-weight: 300;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.35;
    overflow-wrap: break-word;
    box-sizing: border-box;
    border-radius: 40px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--ink);
    font-variant-ligatures: none;
    letter-spacing: 0;
    text-rendering: geometricPrecision;
    font-kerning: none;
}

/* Force underscores to use monospace font to maintain width */
.underscore-normal {
    font-family: 'Courier New', monospace !important;
    font-style: normal !important;
    display: inline;
}

#color-picker {
    position: absolute;
    top: 100px; /* Adjust as needed */
    left: 200px; /* Adjust as needed */
    background-color: var(--surface-3);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    padding: 10px;
    z-index: 1000;
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); /* Creates rows with 30px boxes */
    gap: 5px;
    width: 200px; /* Increase the width */
    max-height: 300px; /* Adjust max height */
    overflow-y: auto; /* Scrollable if needed */
}

.color-box {
    width: 30px;
    height: 30px;
    cursor: pointer;
    border: 1px solid var(--surface-1);
    border-radius: 5px; /* Rounded corners for a ss14 look */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); /* Subtle shadow */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.color-box:hover {
    transform: scale(1.1); /* Enlarge slightly on hover */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Stronger shadow on hover */
}

/* Proper styling for HTML b and i elements */
#render b {
    font-weight: 600;
}

#render i {
    font-style: italic;
}

/* Handle bolditalic (nested b i tags) */
#render b i, #render i b {
    font-weight: 600;
    font-style: italic;
}

/* Headers should lose boldness when italic */
#render i span[style*="font-weight:bold"] {
    font-weight: normal !important;
    font-style: italic !important;
}

/* Image container now positioned below render */
.image-container {
    width: 100%; /* Match render width */
    max-width: 540px;
    text-align: center;
    margin-top: 20px; /* Add spacing */
}

.image-container img {
    max-width: 100%;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 10px;
}

.image-text {
    font-size: 0.9em;
    color: var(--paper);
}

/* Modern flat button styles */
button {
    background-color: var(--surface-2); /* Flat color */
    border: 1px solid var(--surface-1); /* Subtle border */
    color: var(--paper); /* Dark text for readability */
    font-size: 14px;
    font-weight: bold;
    border-radius: 5px;
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: none; /* Flat, no shadow */
    width: 100%;
}

button:hover {
    background-color: var(--surface-1); /* Slightly darker on hover */
    color: var(--paper); /* Darker text for hover */
}

.multiple-buttons {
    display: flex;
    gap: 5px;
}

#template-picker {
    display: none;
    flex: 1 1 auto;
    position: static;
    min-width: 220px;
    min-height: 280px;
    overflow: auto;
    border: 2px solid var(--accent-strong);
    background: linear-gradient(135deg, var(--surface-3) 0%, var(--surface-4) 100%);
    box-shadow: rgba(0, 0, 0, 0.35) 0px 8px 24px;
    z-index: 1001;
    font-family: "Segoe UI", sans-serif;
    font-size: 13px;
    backdrop-filter: blur(10px); top: 10px; left: 160px;
}

.template-folder-group {
    padding:4px 0;
    /*there is also a margin tag, but thats dependent on 'level' from the loop in logic.js*/
}

.template-folder-group:hover {
    background: rgba(242, 90, 90, 0.12);
}

.template-folder-title {
    font-weight:bold;
    color: var(--paper);
    font-size:14px;
    cursor: pointer;
    user-select: none;
}

.template-folder-title:hover {
    background: rgba(242, 90, 90, 0.18);
}

.template-entry {
    cursor:pointer;
    padding:4px 8px;
    margin:2px 0;
    border-radius:4px;
    transition:all 0.2s;
    background: rgba(255, 255, 255, 0.04);
    color: var(--paper);
}

.template-entry:hover {
    background: rgba(242, 90, 90, 0.18);
}

.template-entry-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    margin-right: 4px;
    object-fit: contain;
}

.button-formatting {
    background-color: var(--surface-2) !important;
    color: var(--paper) !important;
}

.button-formatting:hover {
    background-color: var(--surface-1) !important;
}

.button-headers {
    background-color: var(--surface-1) !important;
    color: var(--paper) !important;
}

.button-headers:hover {
    background-color: var(--surface-2) !important;
}

.button-colors {
    background-color: var(--accent-strong) !important;
    color: var(--paper) !important;
}

.button-colors:hover {
    background-color: var(--accent) !important;
}

.button-templates {
    background-color: var(--surface-2) !important;
    color: var(--paper) !important;
}

/* Collapsible folder logic */
.collapsed > div:not(.template-folder-title) {
    display: none !important;
}
