:root {
    /* Dark theme (default) - neutral greys, no blue tint */
    --bg-primary: #222222;
    --bg-secondary: #2c2c2c;
    --bg-header: #282828;
    --text-primary: #d4d4d4;
    --text-secondary: #909090;
    --border-color: #3a3a3a;
    --note-default: #6e6e6e;
    --note-text: #1a1a1a;
    --tab-default: #3a3a3a;
    --tab-active-ring: rgba(255, 255, 255, 0.2);
    --modal-bg: #2c2c2c;
    --modal-shadow: rgba(0, 0, 0, 0.5);
    --overlay-bg: rgba(0, 0, 0, 0.4);
    --btn-primary: #5a6abf;
    --btn-primary-hover: #6b7bd0;
    --btn-danger: #bf5a5a;
    --btn-danger-hover: #d06b6b;
    --btn-secondary: #444444;
    --btn-secondary-hover: #555555;
    --input-bg: #222222;
    --input-border: #444444;
    --scrollbar-thumb: #444444;
    --selection-border: #5a6abf;
    --layout-box-bg: rgba(50, 50, 50, 0.4);
    --notification-bg: #333333;
    --canvas-dot: rgba(255, 255, 255, 0.06);
    --tab-brand-color: rgba(212, 212, 212, 0.28);
}

[data-theme="light"] {
    --bg-primary: #e8e8e8;
    --bg-secondary: #f0f0f0;
    --bg-header: #ebebeb;
    --text-primary: #2a2a2a;
    --text-secondary: #6a6a6a;
    --border-color: #d0d0d0;
    --note-default: #b8b8b8;
    --note-text: #1a1a1a;
    --tab-default: #c0c0c0;
    --tab-active-ring: rgba(0, 0, 0, 0.15);
    --modal-bg: #f0f0f0;
    --modal-shadow: rgba(0, 0, 0, 0.2);
    --overlay-bg: rgba(0, 0, 0, 0.25);
    --btn-primary: #5a6abf;
    --btn-primary-hover: #4a5aaf;
    --btn-danger: #c05050;
    --btn-danger-hover: #d06060;
    --btn-secondary: #d0d0d0;
    --btn-secondary-hover: #c0c0c0;
    --input-bg: #e8e8e8;
    --input-border: #d0d0d0;
    --scrollbar-thumb: #c0c0c0;
    --selection-border: #5a6abf;
    --layout-box-bg: rgba(180, 180, 180, 0.3);
    --notification-bg: #f0f0f0;
    --canvas-dot: rgba(0, 0, 0, 0.06);
    --tab-brand-color: rgba(42, 42, 42, 0.22);
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    user-select: none;
    -webkit-user-select: none;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

/* ---- Header ---- */
#header {
    display: flex;
    align-items: center;
    height: 48px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 100;
    padding: 0 8px;
    gap: 4px;
}

.header-left {
    position: relative;
    flex-shrink: 0;
}

/* ---- Hamburger Button ---- */
.hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    padding: 8px 6px;
    transition: background 0.15s;
}

.hamburger-btn:hover {
    background: var(--bg-secondary);
}

.hamburger-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: background 0.15s;
}

/* ---- Hamburger Menu Dropdown ---- */
.hamburger-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--modal-shadow);
    padding: 6px 0;
    z-index: 200;
}

.hamburger-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.1s;
}

.hamburger-menu button:hover {
    background: var(--bg-primary);
}

.hamburger-menu hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 4px 0;
}

.theme-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 8px 16px;
}

.hamburger-menu .theme-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    width: auto;
    text-align: center;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.theme-btn:first-child {
    border-radius: 6px 0 0 6px;
}

.theme-btn:last-child {
    border-radius: 0 6px 6px 0;
}

.theme-btn:not(:first-child) {
    border-left: none;
}

.hamburger-menu .theme-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.hamburger-menu .theme-btn.active {
    background: var(--btn-secondary-hover);
    border-color: var(--btn-secondary-hover);
    color: var(--text-primary);
}

.theme-btn.active + .theme-btn {
    border-left: none;
}

.menu-version {
    padding: 6px 16px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* ---- Tab Bar ---- */
.tab-bar {
    display: flex;
    align-items: center;
    gap: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    flex: 1;
    height: 100%;
    padding: 6px 0;
    scrollbar-width: thin;
    position: relative;
    z-index: 2;
}

.tab-bar-brand {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 28px;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: var(--tab-brand-color);
    pointer-events: none;
    user-select: none;
    z-index: 1;
    white-space: nowrap;
}

.tab {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    min-width: 60px;
    max-width: 160px;
    padding: 0 14px;
    border: none;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: filter 0.15s, box-shadow 0.15s;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    position: relative;
}

.tab:hover {
    filter: brightness(1.1);
}

.tab.active {
    box-shadow: 0 -3px 0 0 rgba(255, 255, 255, 0.6) inset, 0 2px 8px rgba(0, 0, 0, 0.3);
    filter: brightness(1.25);
    transform: translateY(-1px);
}

.tab.tab-add {
    min-width: 36px;
    max-width: 36px;
    padding: 0;
    font-size: 18px;
    font-weight: 300;
    background: var(--btn-secondary);
    color: var(--text-primary);
    text-shadow: none;
}

.tab.tab-add:hover {
    background: var(--btn-secondary-hover);
}

.tab.tab-recycle {
    min-width: 40px;
    max-width: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--btn-secondary);
    color: var(--text-primary);
}

.tab.tab-recycle:hover {
    background: var(--btn-secondary-hover);
}

.tab.tab-recycle.active {
    background: var(--btn-secondary-hover);
    box-shadow: 0 -3px 0 0 rgba(255, 255, 255, 0.6) inset, 0 2px 8px rgba(0, 0, 0, 0.3);
    filter: brightness(1.25);
    transform: translateY(-1px);
}

.tab.drag-over {
    box-shadow: 0 0 0 2px #fff, 0 0 8px rgba(255, 255, 255, 0.3);
    filter: brightness(1.3);
}

/* ---- Canvas ---- */
.canvas {
    position: relative;
    width: 100%;
    height: calc(100vh - 48px);
    overflow: auto;
    background: radial-gradient(circle, var(--canvas-dot) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg-primary);
}

/* ---- Layout Boxes ---- */
.layout-container {
    display: flex;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    gap: 0;
    z-index: 0;
    pointer-events: auto;
}

.layout-box {
    flex: 1;
    position: relative;
    border-right: 1px solid var(--border-color);
    min-height: 100%;
    overflow: visible;
}

.layout-box:last-child {
    border-right: none;
}

.layout-box-header {
    position: sticky;
    top: 0;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: inherit;
    z-index: 2;
    border-bottom: 1px solid var(--border-color);
}

/* Four-split layout */
.layout-container.four-split {
    flex-wrap: wrap;
}

.layout-container.four-split .layout-box {
    flex: 0 0 50%;
    min-height: 50%;
    max-height: 50%;
    border-bottom: 1px solid var(--border-color);
}

.layout-container.four-split .layout-box:nth-child(2) {
    border-right: none;
}

.layout-container.four-split .layout-box:nth-child(4) {
    border-right: none;
}

.layout-container.four-split .layout-box:nth-child(3),
.layout-container.four-split .layout-box:nth-child(4) {
    border-bottom: none;
}

/* ---- Sticky Note ---- */
.note {
    position: absolute;
    width: 200px;
    min-height: 60px;
    padding: 10px 12px;
    border-radius: 4px;
    cursor: grab;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.15s;
    z-index: 1;
    color: var(--note-text);
}

.note:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.note.dragging {
    cursor: grabbing;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    opacity: 0.9;
}

.note.selected {
    outline: 2px solid var(--selection-border);
    outline-offset: 2px;
}

.note.editing {
    cursor: default;
    z-index: 50;
}

.note .note-content {
    white-space: pre-wrap;
    min-height: 20px;
}

.note textarea {
    width: 100%;
    min-height: 40px;
    border: none;
    background: rgba(0, 0, 0, 0.07);
    border-radius: 3px;
    color: inherit;
    font: inherit;
    resize: vertical;
    outline: none;
    padding: 4px 6px;
}

.note .note-color-bar {
    display: none;
    gap: 4px;
    padding-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.note.editing .note-color-bar {
    display: flex;
}

.note .note-color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
    flex-shrink: 0;
}

.note .note-color-swatch:hover {
    transform: scale(1.2);
}

.note .note-color-swatch.active {
    border-color: rgba(0, 0, 0, 0.6);
    transform: scale(1.15);
}

/* Recycled notes (masonry-like) */
.recycle-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px;
    align-content: flex-start;
}

.recycle-container .note {
    position: relative;
    flex-shrink: 0;
}

.recycle-container .note .recycle-date {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 6px;
}

/* ---- Selection Box ---- */
.selection-box {
    position: absolute;
    border: 1px dashed var(--selection-border);
    background: rgba(90, 106, 191, 0.1);
    z-index: 500;
    pointer-events: none;
}

/* ---- Modals ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 900;
}

.modal {
    position: fixed;
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 12px 40px var(--modal-shadow);
    z-index: 1000;
    max-height: 80vh;
    overflow-y: auto;
    width: 90%;
    max-width: 480px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

#howToModal {
    max-width: 580px;
}

.modal.tab-settings-modal {
    top: 56px;
    transform: translateX(-50%);
    max-height: calc(100vh - 70px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.1s;
}

.modal-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.modal-body {
    padding: 18px;
}

.modal-body h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 16px 0 8px 0;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body ul {
    list-style: none;
    padding: 0;
}

.modal-body li {
    padding: 4px 0;
    font-size: 13px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 18px;
}

.modal-drag-handle {
    cursor: move;
}

/* ---- Form Elements ---- */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 8px 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--btn-primary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    text-transform: none;
    letter-spacing: normal;
    font-weight: normal;
    line-height: 1;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--btn-primary);
    vertical-align: middle;
}

/* ---- Color Grid ---- */
.color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.15s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

/* ---- Layout Box Settings ---- */
.layout-box-settings {
    margin-top: 14px;
}

.layout-box-settings h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.box-setting-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.box-setting-row input[type="text"] {
    flex: 1;
    padding: 6px 8px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.box-setting-row input[type="text"]:focus {
    border-color: var(--btn-primary);
}

.box-color-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s;
    position: relative;
}

.box-color-btn:hover {
    transform: scale(1.1);
}

.box-color-picker {
    position: absolute;
    top: 100%;
    right: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px var(--modal-shadow);
    z-index: 10;
    width: 180px;
}

.box-color-picker .color-swatch {
    width: 22px;
    height: 22px;
}

/* ---- Buttons ---- */
.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

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

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

.btn-danger {
    background: var(--btn-danger);
    color: #fff;
}

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

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

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

/* ---- Notification ---- */
.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    background: var(--notification-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px var(--modal-shadow);
    font-size: 14px;
    z-index: 2000;
    transition: opacity 0.3s;
}

.notification.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ---- Utility ---- */
.hidden {
    display: none !important;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .modal {
        width: 95%;
        max-width: none;
    }

    .note {
        width: 160px;
        font-size: 13px;
    }
}
