:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --card-bg: #ffffff;
    --radius: 0.75rem;
}

body {
    font-family: 'Noto Sans TC', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
}

* {
    box-sizing: border-box;
}

.container {
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

.version-tag {
    position: absolute;
    bottom: -10px;
    /* Reduced gap */
    right: 0;
    font-size: 0.6rem;
    /* Slightly larger */
    color: #94a3b8;
    font-family: monospace;
    font-weight: normal;
    line-height: 1;
}

h1 {
    display: flex;
    justify-content: center;
}

h1 a {
    text-decoration: none;
    color: var(--text-color);
    position: relative;
    display: block;
    /* changed from inline-block to allow width control if needed, but flex item behaves like block */
    width: fit-content;
}

h3 {
    margin-block-start: 0.2em;
    margin-block-end: 0.5em;
}

.subtitle {
    color: #64748b;
}

.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 4rem;
    text-align: center;
    background: var(--card-bg);
    cursor: pointer;
    transition: all 0.2s;
}

.upload-zone:hover {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: #94a3b8;
    margin-bottom: 1rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

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

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

.btn-secondary {
    background-color: #e2e8f0;
    color: #475569;
}

/* Editor Layout */
.editor-container {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.editor-main {
    flex: 3;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.page-card {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

.page-image-wrapper {
    position: relative;
    width: 100%;
}

.page-image {
    width: 100%;
    display: block;
    height: auto;
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Bounding Boxes */
.bbox {
    position: absolute;
    border: 2px solid rgba(37, 99, 235, 0.5);
    background: rgba(37, 99, 235, 0.1);
    cursor: pointer;
    transition: all 0.1s;
}

.bbox:hover {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.2);
}

.bbox.selected {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.2);
    z-index: 10;
}

.sidebar {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 2rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

.edit-panel {
    background: var(--card-bg);
    padding: 0.5rem;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.analyze-btn-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.btn-analyze {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 1rem 2rem;
    border-radius: 2rem;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    backdrop-filter: blur(4px);
}

.btn-analyze:hover {
    background: rgba(0, 0, 0, 0.85);
}

.edit-controls {
    display: flex;
    flex-direction: column;
    margin: 0.5rem 0;
}

.control-group {
    display: flex;
    flex-direction: column;
    margin: 0.5rem 0;
}

.control-group label {
    font-size: 0.9rem;
    color: #475569;
}

.control-group select,
.control-group input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.style-toggles {
    display: flex;
    gap: 1rem;
    margin: 0.2rem 0 0 0;
}

.style-toggles .color-input {
    margin-left: auto;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #334155;
    min-height: 32px;
    flex-wrap: nowrap;
    /* Prevent wrapping */
}

.selected-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin: 0 0 0.5rem 0;
    /* Reduced top margin */
    font-family: inherit;
    resize: vertical;
}

.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Page Toolbar Buttons */
.page-toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-toolbar {
    padding: 0.25rem 0.5rem;
    /* Smaller padding */
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 0.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    transition: all 0.2s;
}

.btn-toolbar:hover {
    background: #f1f5f9;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-toolbar.active {
    background: #eff6ff;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-toolbar:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f1f5f9;
    color: #cbd5e1;
    border-color: var(--border-color);
}

.magnifier-lens {
    position: absolute;
    width: 200px;
    height: 200px;
    border: 2px solid var(--primary-color);
    border-radius: 50%;
    /* Circle */
    pointer-events: none;
    /* Let clicks pass through */
    display: none;
    z-index: 100;
    background-color: white;
    /* Fallback */
    background-repeat: no-repeat;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.selected-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.8rem;
    white-space: nowrap;
    /* Prevent wrapping */
}

.selected-header .selected-id {
    margin-bottom: 0;
}

.toggle-remove-text {
    font-size: 0.8rem;
    font-weight: normal;
    color: var(--text-color);
    /* Defaults to black/dark gray */
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

/* Cleanup Refactor */
.font-control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.checkbox-group-label {
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.control-row {
    display: flex;
    gap: 1rem;
}

.control-group.flex-grow {
    flex: 1;
}

.color-input {
    width: 38px;
    height: 38px;
    padding: 2px;
}

/* Refactored Utility Classes (Added) */
.control-group.no-margin-bottom {
    margin-bottom: 0;
}

.input-auto-width {
    flex: 1;
    width: auto;
}

.control-group.size-row {
    margin-top: 5px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.font-size-input {
    width: 65%;
    text-align: center;
}

.control-row.inpaint-settings {
    margin-bottom: 0px;
    gap: 8px;
    align-items: center;
}

.control-row.fillsize-settings {
    margin-bottom: 0.5rem;
    gap: 8px;
    align-items: center;
}

.label-small-gray {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 4px;
}

.full-width-select {
    width: 100%;
}

.control-row.simple-fill {
    margin-bottom: 10px;
    align-items: center;
    justify-content: space-between;
}

.label-small {
    font-size: 0.8em;
}