/* ── Theme variables ────────────────────────────────────────────────────── */
:root {
    --bg:               #282a36;
    --fg:               #f8f8f2;
    --border:           #44475a;
    --muted:            #b8b9c2;
    --subtle:           #6c757d;
    --link:             #8be9fd;
    --link-hover:       #6ad4eb;
    --accent:           #bd93f9;
    --code-fg:          #ff79c6;
    --code-bg:          #383a4a;
    --surface:          #383a4a;
    --surface-deep:     #1e1f29;
    --form-text:        #6272a4;
    --export-sep:       #2e3040;
    --check-a:          #3a3c4a;
    --check-b:          #2a2c38;
    --btn-bg:           #343a40;
    --btn-hover-bg:     #23272b;
    --btn-hover-border: #1d2124;
    --drop-overlay-bg:  rgba(40, 42, 54, 0.92);
    --select-arrow:     url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23b8b9c2' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
}

[data-theme="light"] {
    --bg:               #fafafa;
    --fg:               #282a36;
    --border:           #d0d0dc;
    --muted:            #5a5b6a;
    --subtle:           #888899;
    --link:             #005f8a;
    --link-hover:       #003d5c;
    --accent:           #7c5cbf;
    --code-fg:          #c0392b;
    --code-bg:          #eeecf5;
    --surface:          #ffffff;
    --surface-deep:     #f0eff7;
    --form-text:        #5a6a8a;
    --export-sep:       #e0dff0;
    --check-a:          #e8e7f2;
    --check-b:          #d8d7ea;
    --btn-bg:           #5a5b6a;
    --btn-hover-bg:     #44475a;
    --btn-hover-border: #383a4a;
    --drop-overlay-bg:  rgba(250, 250, 250, 0.92);
    --select-arrow:     url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235a5b6a' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
}

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    margin: 0;
    padding: 0;
    font-size: 1rem;
    line-height: 1.5;
    transition: background-color 0.2s ease, color 0.2s ease;
}

a {
    color: var(--link);
}

a:hover {
    color: var(--link-hover);
}

/* Display utilities */
.d-none  { display: none  !important; }
.d-block { display: block !important; }

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin-right: auto;
    margin-left: auto;
    padding-right: 1.5rem;
    padding-left: 1.5rem;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -15px;
    margin-left: -15px;
}

[class*="col-"] {
    position: relative;
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
}

@media (min-width: 768px) {
    .col-md-12 { flex: 0 0 100%; max-width: 100%; }
    .col-md-6  { flex: 0 0 50%;  max-width: 50%;  }
    .col-md-3  { flex: 0 0 25%;  max-width: 25%;  }
}

@media (min-width: 992px) {
    .col-lg-4  { flex: 0 0 33.333%; max-width: 33.333%; }
    .col-lg-12 { flex: 0 0 100%;    max-width: 100%;    }
}

/* Page sections */
.page-header {
    /* Use clamp() for more fluid spacing on small screens */
    padding-top: clamp(0.75rem, 2.5vw, 1.5rem);
    margin-bottom: clamp(1rem, 4vw, 2rem);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: clamp(0.5rem, 2vw, 1rem);
}

.page-header .app-icon {
    /* Slightly scale the icon on narrow viewports */
    width: clamp(40px, 6vw, 48px);
    height: clamp(40px, 6vw, 48px);
    border-radius: 8px;
    object-fit: cover;
    /* margin-right: 0.75rem; */
    flex-shrink: 0;
}

.page-header-text {
    flex: 1;
}

.page-header h1 {
    margin-bottom: 1rem;
}

.page-header p {
    max-width: 72ch;
    color: var(--muted);
    margin-bottom: 0.75rem;
}

.page-header .btn {
    margin-top: 1.25rem;
}

.page-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    padding-bottom: 2rem;
}

.page-footer .footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

@media (max-width: 575px) {
    .page-footer .footer-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* Footer link styling: remove underlines on all states */
.page-footer a {
    text-decoration: none !important;
}
.page-footer a:hover,
.page-footer a:focus,
.page-footer a:active {
    text-decoration: none !important;
}

/* Version text after the author name */
.footer-version {
    color: var(--subtle);
    font-size: 0.9rem;
    margin-left: 0.35rem;
}

/* Spacing */
.mb-0 { margin-bottom: 0     !important; }
.mb-2 { margin-bottom: .5rem  !important; }
.mb-4 { margin-bottom: 1.5rem !important; }

/* Typography */
.h2 {
    font-size: 2rem;
    font-weight: 500;
    margin-top: 0;
    margin-bottom: 0.5rem;
    display: block;
}

/* Header-specific title scaling for small viewports */
.page-header .h2 {
    font-size: clamp(1.25rem, 4.5vw, 2rem);
    margin-bottom: clamp(0.35rem, 1.2vw, 0.5rem);
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875em;
    color: var(--code-fg);
    background-color: var(--code-bg);
    padding: 0.1em 0.35em;
    border-radius: 3px;
}

.text-muted           { color: var(--subtle)  !important; }
.text-decoration-none { text-decoration: none !important; }

/* Borders */
.border     { border: 1px solid var(--border)     !important; }
.border-top { border-top: 1px solid var(--border) !important; }

/* Images */
.img-fluid {
    max-width: 100%;
    height: auto;
}

/* Install section card */
.install-section {
    margin-top: 1.5rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--accent, #7b61ff);
    padding: 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 8px 22px rgba(0,0,0,0.25);
}

/* Install instructions definition list */
.install-instructions {
    margin: 0;
}
.install-instructions dt {
    font-weight: 600;
    margin-top: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.install-instructions dt:first-child {
    margin-top: 0;
}
.install-instructions dd {
    margin-left: 1.25rem;
    margin-bottom: 0;
    opacity: 0.85;
}

/* Author block: avatar beside bio using flex layout */
.author-section {
    margin-top: 1.5rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--code-fg, #7b61ff);
    padding: 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 8px 22px rgba(0,0,0,0.25);
}

/* Inner body holds avatar + bio using flex */
.author-body {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.author-avatar {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

@media (max-width: 575px) {
    .author-body {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .author-avatar {
        width: 56px;
        height: 56px;
    }
}

/* Slightly lift the box on hover for affordance */
.author-section:hover {
    transform: translateY(-2px);
    transition: transform 0.12s ease;
}

.author-section h3 {
    margin: 0 0 0.5rem 0;
    color: var(--fg);
}

/* Canvas preview display sizes
   The width/height HTML attributes define the actual render resolution.
   These CSS rules only affect how large the canvas is displayed on screen. */
.canvas-512,
.canvas-256,
.canvas-192,
.canvas-180,
.canvas-152,
.canvas-144,
.canvas-128,
.canvas-96,
.canvas-64,
.canvas-48,
.canvas-32,
.canvas-16 {
    height: auto; /* maintain aspect ratio when width is constrained */
    max-width: 100%;
}

.canvas-512 { width: 280px; }
.canvas-256 { width: 220px; }
.canvas-192 { width: 175px; }
.canvas-180 { width: 160px; }
.canvas-152 { width: 152px; }
.canvas-144 { width: 144px; }
.canvas-128 { width: 128px; }
.canvas-96  { width:  96px; }
.canvas-64  { width:  64px; }
.canvas-48  { width:  48px; }
.canvas-32  { width:  32px; }
.canvas-16  { width:  16px; }

/* Small previews grid (128 / 64 / 32 / 16) */
.small-previews-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
}

@media (min-width: 992px) {
    .small-previews-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.25rem;
    }
}

/* Checkered background for transparency preview */
.bg-check {
    background-color: var(--check-a);
    background-image:
        linear-gradient(45deg,  var(--check-b) 25%, transparent 25%),
        linear-gradient(-45deg, var(--check-b) 25%, transparent 25%),
        linear-gradient(45deg,  transparent 75%, var(--check-b) 75%),
        linear-gradient(-45deg, transparent 75%, var(--check-b) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

/* Buttons */
.btn {
    display: inline-block;
    font-weight: 400;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    user-select: none;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 0.25rem;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.btn-dark {
    color: #fff;
    background-color: var(--btn-bg);
    border-color: var(--btn-bg);
}

.btn-dark:hover {
    color: #fff;
    background-color: var(--btn-hover-bg);
    border-color: var(--btn-hover-border);
}

.btn-dark:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: auto;
}

/* Toast notifications */
.notify-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.notify-toast {
    min-width: 260px;
    padding: 0.75rem 1rem;
    border-radius: 0.25rem;
    color: #fff;
    font-size: 0.9rem;
    opacity: 1;
    transition: opacity 0.4s ease;
}

.notify-toast strong {
    display: block;
    margin-bottom: 0.2rem;
}

.notify-toast.danger  { background-color: #dc3545; }
.notify-toast.success { background-color: #28a745; }
.notify-toast.info    { background-color: #17a2b8; }

/* Tabs */
.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    font-family: inherit;
    padding: 0.75rem 1.25rem;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
    color: var(--fg);
}

.tab-btn.active {
    color: var(--fg);
    border-bottom-color: var(--accent);
}

.tab-btn--right {
    margin-left: auto;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: tab-in 0.25s ease;
}

@keyframes tab-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Forms */
.mb-3 { margin-bottom: 1rem !important; }

.form-label {
    display: block;
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.form-text {
    display: block;
    font-size: 0.8rem;
    color: var(--form-text);
    margin-top: 0.3rem;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.4rem 0.7rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--fg);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
    box-sizing: border-box;
}

.form-control:focus {
    border-color: var(--accent);
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

select.form-control {
    appearance: none;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px;
    padding-right: 2.25rem;
    cursor: pointer;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

@media (max-width: 575px) {
    .form-grid { grid-template-columns: 1fr; }
}

.color-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.color-input-group input[type="color"] {
    width: 2.5rem;
    height: 2.35rem;
    padding: 0.15rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    background: var(--surface);
    cursor: pointer;
    flex-shrink: 0;
}

.color-input-group .form-control {
    flex: 1;
}

/* Manifest JSON preview */
.manifest-preview {
    background-color: var(--surface-deep);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    padding: 1rem 1.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
    color: var(--fg);
    overflow-x: auto;
    white-space: pre;
    margin: 0;
    line-height: 1.6;
}

/* Export file list */
.export-file-list {
    background-color: var(--surface-deep);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    padding: 0.5rem 0;
}

.export-file-item {
    padding: 0.4rem 1rem;
    font-size: 0.9rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    user-select: none;
}

.export-file-item:hover {
    color: var(--fg);
}

.export-file-item input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.export-badge {
    font-size: 0.75rem;
    color: var(--subtle);
    background-color: var(--surface-deep);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.05em 0.4em;
    margin-left: 0.15rem;
}

.export-file-item + .export-file-item {
    border-top: 1px solid var(--export-sep);
}

/* Drag-and-drop overlay for the icons pane */
#tab-icons {
    position: relative;
}

.drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background-color: var(--drop-overlay-bg);
    border: 3px dashed var(--accent);
    border-radius: 0.5rem;
    z-index: 10;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    pointer-events: none;
}

.drop-overlay.active {
    display: flex;
}

.drop-overlay-content {
    color: var(--accent);
    pointer-events: none;
}

.drop-overlay-content i {
    font-size: 3.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

.drop-overlay-content p {
    font-size: 1.25rem;
    margin: 0;
    font-weight: 500;
}

.drop-hint {
    display: inline-block;
    margin-left: 1rem;
    font-size: 0.875rem;
    color: var(--subtle);
    vertical-align: middle;
}

/* ── Theme toggle button ─────────────────────────────────────────────────── */
.btn-theme {
    background: none;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.4rem 0.55rem;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.btn-theme:hover {
    color: var(--fg);
    border-color: var(--muted);
    background-color: var(--surface);
}

/* Active state for toggle buttons */
.btn-dark.btn-active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-dark.btn-active:hover {
    filter: brightness(0.9);
}

/* Button label: icon-only on small screens, show label on medium+ */
.btn-label {
    display: none;
}

@media (min-width: 768px) {
    .btn-label {
        display: inline;
    }
}

/* Tab pane title: shown only on small screens (when tab labels are hidden) */
.tab-pane-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 1rem;
}

@media (min-width: 768px) {
    .tab-pane-title {
        display: none;
    }
}

/* Icons toolbar */
.icons-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.icons-toolbar .drop-hint {
    margin-left: 0.5rem;
}

/* Safe zone button group (Safe Zone + info button joined) */
.safe-zone-btn-group {
    position: relative;
    display: inline-flex;
}

.safe-zone-btn-group #btn-safe-zone {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.btn-safe-zone-info {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding-left: 0.55rem;
    padding-right: 0.55rem;
}

/* Safe zone popover */
.safe-zone-popover {
    display: none;
    position: absolute;
    top: calc(100% + 0.6rem);
    left: 0;
    z-index: 200;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    padding: 1rem 1.1rem 0.85rem;
    width: 320px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.25);
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--fg);
}

.safe-zone-popover.open {
    display: block;
    animation: tab-in 0.18s ease;
}

/* small arrow */
.safe-zone-popover::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 1rem;
    width: 10px;
    height: 10px;
    background-color: var(--surface);
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
    transform: rotate(45deg);
}

.safe-zone-popover p {
    margin: 0 0 0.6rem;
}

.safe-zone-popover p:last-child {
    margin-bottom: 0;
}

.safe-zone-popover-heading {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.65rem !important;
}

.safe-zone-popover-note {
    color: var(--muted);
    font-style: italic;
}

.safe-zone-popover-when {
    display: flex;
    gap: 0.45rem;
    padding: 0.4rem 0.6rem;
    border-radius: 0.25rem;
    background-color: rgba(80, 200, 120, 0.1);
    color: var(--fg);
}

.safe-zone-popover-when i {
    color: #50c878;
    flex-shrink: 0;
    margin-top: 0.15rem;
}

.safe-zone-popover-when--low {
    background-color: rgba(184, 185, 194, 0.1);
}

.safe-zone-popover-when--low i {
    color: var(--muted);
}

.safe-zone-popover-close {
    position: absolute;
    top: 0.4rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.1rem 0.2rem;
}

.safe-zone-popover-close:hover {
    color: var(--fg);
}

/* ── Edit shape dropdown ─────────────────────────────────────────────────── */
.edit-dropdown-group {
    position: relative;
    display: inline-block;
}

.edit-caret {
    font-size: 0.65em;
    margin-left: 0.1rem;
    opacity: 0.75;
}

.edit-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 150;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    min-width: 175px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.22);
    padding: 0.3rem 0;
}

.edit-dropdown-menu.open {
    display: block;
    animation: tab-in 0.15s ease;
}

.edit-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    background: none;
    border: none;
    padding: 0.45rem 1rem;
    font-size: 0.9rem;
    color: var(--fg);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    line-height: 1.4;
}

.edit-dropdown-item:hover:not(:disabled) {
    background-color: var(--surface-deep);
}

.edit-dropdown-item:disabled {
    color: var(--subtle);
    cursor: default;
    opacity: 0.6;
}

.edit-dropdown-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.3rem 0;
}

/* Canvas wrapper for safe-zone overlay */
.canvas-wrap {
    position: relative;
    display: block;
    width: fit-content;
    line-height: 0;
}

.safe-zone-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.safe-zone-active .safe-zone-svg {
    opacity: 1;
}

/* Shape previews section */
.shape-previews-section {
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
    margin-top: 0.5rem;
}

.shape-previews-title {
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 1rem;
    margin-top: 0;
}

.shape-previews-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-start;
}

.shape-preview-item {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.shape-preview-canvas {
    display: block;
    width: 160px;
    height: 160px;
}

/* Clickable icon canvases */
.canvas-wrap canvas {
    cursor: pointer;
}

/* ── Per-icon context menu ───────────────────────────────────────────────── */
.icon-ctx-menu {
    display: none;
    position: absolute;
    z-index: 300;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    min-width: 145px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.22);
    padding: 0.3rem 0;
}

.icon-ctx-menu.open {
    display: block;
    animation: tab-in 0.15s ease;
}

.icon-ctx-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    background: none;
    border: none;
    padding: 0.45rem 1rem;
    font-size: 0.9rem;
    color: var(--fg);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    line-height: 1.4;
}

.icon-ctx-item:hover {
    background-color: var(--surface-deep);
}

.icon-ctx-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.3rem 0;
}

