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

:root {
    --ink: #1a1a18;
    --ink-2: #6b6b67;
    --ink-3: #a8a8a4;
    --rule: #e5e5e3;
    --paper: #ffffff;
    --paper-2: #f7f7f6;
    --paper-3: #f0f0ee;
    --r: 4px;
    --mono: 'DM Mono', monospace;
    --sans: 'Inter', system-ui, sans-serif;
}

body {
    font-family: var(--sans);
    background: var(--paper);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ─── header ─── */
header {
    border-bottom: 1px solid var(--rule);
    padding: 0 2rem;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.wordmark {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 10px;
}

.wordmark-sep {
    width: 1px;
    height: 14px;
    background: var(--rule);
}

.wordmark-sub {
    color: var(--ink-3);
    font-weight: 400;
}

.header-meta {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-3);
    letter-spacing: 0.04em;
}

/* ─── layout ─── */
.app {
    display: grid;
    grid-template-columns: 340px 1fr;
    height: calc(100vh - 52px);
}

/* ─── sidebar ─── */
.sidebar {
    border-right: 1px solid var(--rule);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-section {
    border-bottom: 1px solid var(--rule);
    padding: 1.25rem 1.5rem;
}

.sidebar-section:last-child {
    border-bottom: none;
}

.section-label {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    color: var(--ink-3);
    text-transform: uppercase;
    margin-bottom: 1rem;
}

/* ─── upload ─── */
.upload-area {
    position: relative;
    cursor: pointer;
}

.upload-area input[type=file] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.upload-placeholder {
    border: 1px solid var(--rule);
    border-radius: var(--r);
    padding: 2rem 1rem;
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
    background: var(--paper-2);
}

.upload-area:hover .upload-placeholder,
.upload-area.drag-over .upload-placeholder {
    border-color: var(--ink-3);
    background: var(--paper-3);
}

.upload-glyph {
    font-family: var(--mono);
    font-size: 2.5rem;
    font-weight: 500;
    color: var(--rule);
    display: block;
    margin-bottom: 0.75rem;
    letter-spacing: -0.05em;
    line-height: 1;
}

.upload-text {
    font-size: 13px;
    color: var(--ink-2);
    display: block;
    margin-bottom: 0.25rem;
}

.upload-hint {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-3);
}

#preview-img {
    display: none;
    width: 100%;
    border-radius: var(--r);
    border: 1px solid var(--rule);
    max-height: 180px;
    object-fit: contain;
    background: var(--paper-2);
}

.replace-btn {
    margin-top: 0.5rem;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-3);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: none;
}

.replace-btn:hover {
    color: var(--ink);
}

/* ─── fields ─── */
.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 0.875rem;
}

.field:last-child {
    margin-bottom: 0;
}

.field label {
    font-size: 12px;
    color: var(--ink-2);
}

.field input,
.field select {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--r);
    padding: 0.45rem 0.6rem;
    outline: none;
    transition: border-color 0.12s;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}

.field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a8a8a4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 2rem;
}

.field input:focus,
.field select:focus {
    border-color: var(--ink-2);
}

.field input[type="range"] {
    padding: 0;
    border: none;
    background: none;
    accent-color: var(--accent);
    cursor: pointer;
}

/* ─── toggle row ─── */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.375rem 0;
    font-size: 13px;
    color: var(--ink-2);
}

.toggle-row+.toggle-row {
    border-top: 1px solid var(--rule);
}

.toggle {
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: var(--paper-3);
    border: 1px solid var(--rule);
    position: relative;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.toggle.on {
    background: var(--ink);
    border-color: var(--ink);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--ink-3);
    transition: left 0.15s, background 0.15s;
}

.toggle.on::after {
    left: 16px;
    background: white;
}

/* ─── generate button ─── */
.btn-generate {
    width: 100%;
    padding: 0.625rem 1rem;
    background: var(--ink);
    color: white;
    border: none;
    border-radius: var(--r);
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.12s;
    letter-spacing: 0.01em;
}

.btn-generate:hover {
    opacity: 0.85;
}

.btn-generate:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ─── main panel ─── */
.main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── toolbar ─── */
.toolbar {
    border-bottom: 1px solid var(--rule);
    padding: 0 1.5rem;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
}

.tab-btn {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    color: var(--ink-3);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 1rem;
    height: 44px;
    border-bottom: 1px solid transparent;
    margin-bottom: -1px;
    transition: color 0.12s, border-color 0.12s;
}

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

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

.toolbar-right {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.btn-sm {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-2);
    background: none;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    padding: 0.25rem 0.75rem;
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s;
    white-space: nowrap;
}

.btn-sm:hover {
    border-color: var(--ink-3);
    color: var(--ink);
}

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

.btn-sm.primary:hover {
    opacity: 0.8;
}

/* ─── content area ─── */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* ─── empty state ─── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.empty-glyph-row {
    font-family: var(--mono);
    font-size: 4rem;
    font-weight: 500;
    color: var(--rule);
    letter-spacing: 0.15em;
    line-height: 1;
    margin-bottom: 1.5rem;
    user-select: none;
}

.empty-label {
    font-size: 13px;
    color: var(--ink-3);
}

/* ─── progress ─── */
.progress-wrap {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1.5rem;
}

.progress-track {
    width: 240px;
    height: 1px;
    background: var(--rule);
    position: relative;
    overflow: hidden;
}

.progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: var(--ink);
    transition: width 0.4s ease;
    width: 0%;
}

.progress-label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-3);
    letter-spacing: 0.04em;
}

/* ─── glyph grid ─── */
.glyph-section {
    margin-bottom: 2rem;
}

.glyph-section-title {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    color: var(--ink-3);
    text-transform: uppercase;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--rule);
}

.glyph-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    border-radius: var(--r);
    overflow: hidden;
}

.glyph-cell {
    aspect-ratio: 1;
    background: var(--paper);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px 4px;
    cursor: default;
    transition: background 0.1s;
    position: relative;
}

.glyph-cell:hover {
    background: var(--paper-2);
}

.glyph-cell svg {
    width: 52%;
    height: 52%;
    flex-shrink: 0;
}

.glyph-char {
    font-family: var(--mono);
    font-size: 9px;
    color: var(--ink-3);
    margin-top: auto;
    line-height: 1;
}

.glyph-char-input {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
    margin-top: auto;
    line-height: 1;
    width: 24px;
    text-align: center;
    border: 1px solid var(--rule);
    border-radius: 3px;
    background: var(--paper-2);
    padding: 2px 0;
    transition: border-color 0.1s;
}

.glyph-char-input:focus {
    border-color: var(--ink-2);
    outline: none;
}

/* ─── preview tab ─── */
.preview-input-area {
    border: 1px solid var(--rule);
    border-radius: var(--r);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.preview-input-area input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: var(--sans);
    font-size: 14px;
    color: var(--ink);
    background: var(--paper-2);
    border: none;
    border-bottom: 1px solid var(--rule);
    outline: none;
}

.preview-render {
    padding: 2rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px;
    min-height: 120px;
}

.preview-render .char-svg-wrap svg {
    height: 1em;
    width: auto;
    display: block;
}

.preview-render .space {
    width: 0.4em;
    display: inline-block;
}

.preview-render .fallback {
    font-size: 1em;
    color: var(--rule);
    line-height: 1;
    font-family: var(--mono);
}

/* ─── preview tab controls ─── */
.preview-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.875rem 1rem;
    background: var(--paper-2);
    border: 1px solid var(--rule);
    border-radius: var(--r);
    margin-bottom: 1rem;
    align-items: center;
}

.preview-controls .control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 130px;
}

.preview-controls .control-group.color-group {
    flex: 0 0 70px;
    min-width: 70px;
}

.preview-controls label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-2);
    display: flex;
    justify-content: space-between;
}

.preview-controls input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
}

.preview-controls input[type="color"] {
    border: 1px solid var(--rule);
    border-radius: 4px;
    width: 100%;
    height: 28px;
    cursor: pointer;
    padding: 0;
    background: none;
}

.preview-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1rem;
}

.preset-label {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--ink-3);
    margin-right: 4px;
}

.btn-preset {
    font-family: var(--mono);
    font-size: 11px;
    padding: 4px 8px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--r);
    color: var(--ink-2);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-preset:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--paper-2);
}

#preview-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    font-family: var(--sans);
    font-size: 14px;
    margin-bottom: 1rem;
    resize: vertical;
    background: var(--paper);
    color: var(--ink);
}

.preview-render-wrapper {
    padding: 1.5rem;
    border: 1px solid var(--rule);
    border-radius: var(--r);
    background: #ffffff;
    overflow-x: auto;
    min-height: 150px;
}

/* ─── info tab ─── */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    border-radius: var(--r);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.info-cell {
    background: var(--paper);
    padding: 0.875rem 1rem;
}

.info-cell-label {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.info-cell-value {
    font-size: 15px;
    font-weight: 500;
    color: var(--ink);
}

.analysis-note {
    font-size: 13px;
    color: var(--ink-2);
    line-height: 1.6;
    padding: 1rem;
    background: var(--paper-2);
    border-radius: var(--r);
    border: 1px solid var(--rule);
}

/* ─── Loading Overlay ─── */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 26, 24, 0.85);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-family: var(--sans);
    font-size: 16px;
    font-weight: 500;
    color: white;
    text-align: center;
}

.loading-progress {
    font-family: var(--mono);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.04em;
}

/* ─── error ─── */
.error-note {
    font-family: var(--mono);
    font-size: 11px;
    color: #c0392b;
    margin-top: 0.75rem;
    display: none;
    padding: 0.5rem 0.75rem;
    background: #fdf2f2;
    border-radius: var(--r);
    border: 1px solid #f5c6c6;
}

.style-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.style-tab {
    font-family: var(--mono);
    font-size: 11px;
    padding: 6px 10px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--r);
    color: var(--ink-2);
    cursor: pointer;
}

.style-tab.has-image {
    border-color: var(--ink-2);
    color: var(--ink);
}

.style-tab.active {
    background: var(--ink);
    color: white;
    border-color: var(--ink);
}

#editor-canvas-wrap {
    overflow: auto;
    height: 70vh;
    /* tinggi tetap, bukan max-height saja */
    max-height: 70vh;
    border: 1px solid #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    background-image:
        linear-gradient(45deg, #eaeaea 25%, transparent 25%),
        linear-gradient(-45deg, #eaeaea 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #eaeaea 75%),
        linear-gradient(-45deg, transparent 75%, #eaeaea 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

#editor-canvas {
    display: block;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    width: fit-content;
    margin-bottom: 8px;
}

.zoom-controls button {
    width: 30px;
    height: 30px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #f8f8f8;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.zoom-controls button:hover {
    background: #e3f2fd;
    border-color: #90caf9;
}

.zoom-controls button:active {
    background: #bbdefb;
}

#zoom-level-label {
    min-width: 48px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    user-select: none;
}

.zoom-controls .zoom-sep {
    width: 1px;
    height: 20px;
    background: #ddd;
    margin: 0 4px;
}