@import url('https://fonts.googleapis.com/css2?family=Patrick+Hand&family=Gaegu:wght@400;700&family=Nunito:wght@400;600;700&display=swap');

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

:root {
    --ink: #7556c9;
    --ink-light: #9b82e6;
    --ink-faint: #d8cfff;
    --pink-ink: #ff5ca8;
    --pink-bg: #fff8fb;
    --paper: #fffaf0;
    --tape: #ffeaa7;
    --text: #3a3060;
    --muted: #9b94c4;
    --font-hand: 'Patrick Hand', 'Gaegu', cursive;
    --font-ui: 'Nunito', sans-serif;
}

html { font-size: 16px; }

body {
    height: 100vh;
    font-family: var(--font-ui);
    color: var(--text);
    overflow: hidden;
    background-color: var(--paper);
    background-image: url("assets/paper-grid-bg.svg");
    zoom: 1.5;
    height: calc(100vh / 1.5);
}

#app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 14px 18px 12px;
    gap: 14px;
}

/* ── header ───────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.header-title {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-title h1 {
    font-family: var(--font-hand);
    font-size: 30px;
    color: var(--ink);
    text-decoration: underline wavy var(--ink-light);
    text-underline-offset: 10px;
    text-decoration-skip-ink: none;
    letter-spacing: 0.02em;
    transform: rotate(-0.6deg);
    padding-bottom: 4px;
}

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

.pack-name-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    transform: rotate(0.3deg);
}

.pack-name-group label {
    font-family: var(--font-hand);
    font-size: 13px;
    color: var(--muted);
}

.pack-name-input {
    font-family: var(--font-hand);
    font-size: 16px;
    color: var(--ink);
    background: white;
    border: 2px solid var(--ink);
    border-radius: 14px 12px 16px 13px;
    padding: 4px 12px;
    outline: none;
    width: 150px;
    transition: border-color 0.15s, transform 0.15s;
}
.pack-name-input:focus {
    border-color: var(--pink-ink);
    transform: rotate(-0.5deg);
}

.icon-btn {
    width: 38px;
    height: 38px;
    background: white;
    border: 2px solid var(--ink);
    border-radius: 12px 14px 11px 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.15s;
    box-shadow: 2px 3px 0 rgba(117,86,201,.18);
}
.icon-btn:hover { transform: scale(1.1) rotate(-6deg); }
.icon-btn.has-icon { font-size: 22px; }

.icon-picker {
    position: absolute;
    top: 56px;
    right: 100px;
    z-index: 50;
    background: var(--paper);
    border: 2.5px solid var(--ink);
    border-radius: 18px 22px 20px 24px;
    box-shadow: 5px 6px 0 rgba(117,86,201,.18);
    padding: 12px;
    width: 280px;
    max-height: 320px;
    display: flex;
    flex-direction: column;
    transform: rotate(-0.4deg);
}

.icon-picker-title {
    font-family: var(--font-hand);
    font-size: 16px;
    color: var(--ink);
    margin-bottom: 8px;
    padding-left: 4px;
}

.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    overflow-y: auto;
    flex: 1;
}

.icon-picker-grid button {
    background: var(--paper);
    border: 1.5px solid var(--ink-faint);
    border-radius: 10px;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
    transition: transform 0.12s, border-color 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
}
.icon-picker-grid button img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}
.icon-picker-grid button:hover {
    transform: scale(1.2) rotate(4deg);
    border-color: var(--pink-ink);
}

.export-btn {
    font-family: var(--font-hand);
    font-size: 19px;
    background: var(--pink-bg);
    color: var(--pink-ink);
    border: 2px solid var(--pink-ink);
    border-radius: 18px 16px 20px 17px;
    padding: 7px 22px;
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 3px 4px 0 rgba(255,92,168,.22);
    transform: rotate(-1deg);
}
.export-btn:hover {
    transform: rotate(-2deg) scale(1.05);
    box-shadow: 5px 6px 0 rgba(255,92,168,.28);
}

/* ── main layout ──────────────────────────────────────── */
.main {
    display: flex;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

/* ── sketch card base (used by sidebar + categories) ───── */
.sketch-card {
    position: relative;
    background: rgba(255, 250, 240, 0.92);
    border: 2.5px solid var(--ink);
    border-radius: 22px 26px 24px 28px;
    box-shadow: 5px 6px 0 rgba(117, 86, 201, .14);
}

.sketch-card::after {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: -7px;
    border: 2px solid rgba(117, 86, 201, .35);
    border-radius: 28px 22px 30px 24px;
    transform: rotate(-0.4deg);
}

/* ── sidebar ──────────────────────────────────────────── */
.sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-title {
    font-family: var(--font-hand);
    font-size: 16px;
    color: var(--ink);
    padding: 12px 14px 6px;
    transform: rotate(-0.5deg);
}

.search-bar {
    margin: 6px 12px 8px;
    padding: 6px 12px;
    font-family: var(--font-hand);
    font-size: 14px;
    color: var(--ink);
    background: white;
    border: 1.8px solid var(--ink-faint);
    border-radius: 18px 16px 20px 17px;
    outline: none;
    transition: border-color 0.15s;
}
.search-bar:focus { border-color: var(--ink-light); }
.search-bar::placeholder { color: var(--muted); }

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    padding: 4px 10px 8px;
    overflow-y: auto;
    flex: 1;
    align-content: start;
}

.emoji-btn {
    background: var(--paper);
    border: 1.5px solid var(--ink-faint);
    border-radius: 10px 12px 11px 13px;
    cursor: grab;
    padding: 4px;
    text-align: center;
    line-height: 0;
    user-select: none;
    box-shadow: 1px 2px 0 rgba(117, 86, 201, .08);
    transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 38px;
}
.emoji-btn img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    pointer-events: none;
}
.emoji-btn:hover {
    transform: rotate(3deg) scale(1.18);
    border-color: var(--ink-light);
    box-shadow: 2px 3px 0 rgba(117, 86, 201, .18);
    z-index: 2;
}
.emoji-btn.dragging { opacity: 0.4; cursor: grabbing; }

.sidebar-hint {
    font-family: var(--font-hand);
    font-size: 14px;
    color: var(--pink-ink);
    padding: 8px 14px 12px;
    transform: rotate(-1deg);
}
.sidebar-hint::before { content: '↑ '; }

/* ── categories area ──────────────────────────────────── */
.categories-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    padding: 4px 6px 8px 4px;
}

.category-box {
    padding: 12px 14px 10px;
    flex-shrink: 0;
    align-self: flex-start;
    width: 100%;
    transition: box-shadow 0.15s;
}
.category-box:nth-child(odd) { transform: rotate(-0.3deg); }
.category-box:nth-child(even) { transform: rotate(0.4deg); }

.category-box.drag-over {
    border-color: var(--pink-ink);
    background: rgba(255, 248, 251, 0.95);
}
.category-box.drag-over::after { border-color: var(--pink-ink); }

.category-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.category-name {
    font-family: var(--font-hand);
    font-size: 19px;
    color: var(--ink);
    background: none;
    border: none;
    outline: none;
    flex: 1;
    min-width: 0;
    padding: 0;
    border-bottom: 1.5px dashed transparent;
    transition: border-color 0.15s;
}
.category-name:focus { border-color: var(--ink-light); }

.category-count {
    font-family: var(--font-hand);
    font-size: 12px;
    color: var(--muted);
}

.cat-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--muted);
    line-height: 1;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.12s, transform 0.12s;
}
.cat-delete-btn:hover { color: var(--pink-ink); transform: scale(1.2); }

.category-body {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-content: flex-start;
    padding-bottom: 6px;
}

.category-drop-hint {
    font-family: var(--font-hand);
    font-size: 13px;
    color: var(--ink-light);
    width: 100%;
    text-align: center;
    padding: 6px 0 0;
    border-top: 2px dashed rgba(117, 86, 201, .55);
    margin-top: 4px;
    border-radius: 0 0 18px 18px;
}

.cat-emoji {
    background: var(--paper);
    border: 1.5px solid var(--ink-faint);
    border-radius: 12px 14px 11px 13px;
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
    position: relative;
    user-select: none;
    box-shadow: 2px 3px 0 rgba(117, 86, 201, .1);
}
.cat-emoji img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    pointer-events: none;
}
.cat-emoji:hover {
    transform: rotate(3deg) scale(1.12);
    border-color: var(--ink-light);
    box-shadow: 3px 4px 0 rgba(117, 86, 201, .2);
    z-index: 2;
}
.cat-emoji .remove-emoji {
    display: none;
    position: absolute;
    top: -7px;
    right: -7px;
    width: 18px;
    height: 18px;
    background: var(--pink-ink);
    color: white;
    border-radius: 50%;
    font-size: 10px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-family: var(--font-ui);
    font-weight: 700;
    line-height: 1;
    border: 1.5px solid white;
}
.cat-emoji:hover .remove-emoji { display: flex; }

.add-category-btn {
    font-family: var(--font-hand);
    font-size: 17px;
    color: var(--pink-ink);
    background: var(--pink-bg);
    border: 2px dashed var(--pink-ink);
    border-radius: 18px 22px 20px 24px;
    padding: 12px;
    width: 100%;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    text-align: center;
    flex-shrink: 0;
    box-shadow: 3px 4px 0 rgba(255,92,168,.15);
}
.add-category-btn:hover {
    transform: rotate(-1deg) scale(1.01);
    box-shadow: 5px 6px 0 rgba(255,92,168,.22);
}

/* corner doodles */
.corner-doodle {
    position: fixed;
    pointer-events: none;
    z-index: 0;
    opacity: 0.85;
}
.corner-doodle img { display: block; }

.corner-doodle.tl { top: 4px; left: 8px; transform: rotate(-8deg); }
.corner-doodle.tl img { width: 90px; }

.corner-doodle.bl { bottom: 6px; left: 6px; transform: rotate(-6deg); }
.corner-doodle.bl img { width: 80px; }

/* scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 99px; }

/* drag ghost */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    font-size: 32px;
    transform: translate(-50%, -50%) scale(1.25) rotate(8deg);
    filter: drop-shadow(2px 4px 6px rgba(117,86,201,0.35));
}
