/* ==================================================================
   CATENOT.ES — design tokens
   Metáfora: uma árvore no escuro — o mundo é a terra à noite, as notas
   são folhas de papel que brotam dela. Cantos arredondados como
   pedras/folhas, tipografia serifada com caráter orgânico nos títulos.
   ================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=Manrope:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
    /* Color */
    --color-canvas:        #11140F;
    --color-canvas-dot:    #1D2318;
    --color-paper:         #EDE4C8;
    --color-paper-dim:     #D9CFAF;
    --color-ink:           #26241A;
    --color-ink-soft:      #56503D;
    --color-accent:        #C08A3E;
    --color-accent-soft:   #7C9473;
    --color-danger:        #B5533D;
    --color-overlay-backdrop: rgba(8, 10, 6, 0.72);

    /* Type */
    --font-display: 'Fraunces', Georgia, serif;
    --font-body:    'Manrope', system-ui, sans-serif;
    --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

    /* Layout */
    --note-height: 10vh;
    --note-width:  20vh;
    --radius-note: 14px;
    --radius-fab:  50%;

    color-scheme: dark;
}

* { box-sizing: border-box; }

::selection {
    background: var(--color-ink);
    color: var(--color-paper);
}

::-moz-selection {
    background: var(--color-ink);
    color: var(--color-paper);
}

html, body {
    margin:   0;
    padding:  0;
    overflow: hidden;
    height:   100%;
    background: var(--color-canvas);
    font-family: var(--font-body);
    -webkit-tap-highlight-color: transparent;
}

/* ------------------------------------------------------------ */
/* Canvas / world                                                */
/* ------------------------------------------------------------ */

#window {
    width:    100dvw;
    height:   100dvh;
    margin:   0;
    padding:  0;
    overflow: hidden;
    position: relative;
    background-color: var(--color-canvas);
    background-image: radial-gradient(var(--color-canvas-dot) 1.5px, transparent 1.5px);
    background-size: 28px 28px;
    cursor: grab;
}

#window:active { cursor: grabbing; }

#world {
    position: relative;
    width:    10000px;
    height:   10000px;
    transform-origin: 0 0;
}

/* The root grid sits centered on the (very large) #world so the initial
   view lands right on top of it. */
#root-grid {
    position: absolute;
    top:  5000px;
    left: 5000px;
    transform: translate(-50%, -50%);
    width: 80vw;
    max-width: 900px;
}

/* ------------------------------------------------------------ */
/* Note grid (root level and nested levels)                      */
/* ------------------------------------------------------------ */

.note-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    align-items: flex-start;
    gap: 3vh;
}

.note-grid--nested {
    position: static;
    margin-top: 3vh;
    width: 100%;
    flex-wrap: nowrap;
    flex-shrink: 0;
    justify-content: flex-start;
    align-items: center;
    height: calc(max(var(--note-height), 64px) + 28px);
    padding: 14px 6px;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(38, 36, 26, 0.035);
    border-radius: 12px;
}

/* ------------------------------------------------------------ */
/* Note card (closed)                                             */
/* ------------------------------------------------------------ */

.note {
    height: var(--note-height);
    width:  var(--note-width);
    min-height: 64px;
    min-width:  128px;
    background: var(--color-paper);
    border-radius: var(--radius-note);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.35) inset,
        0 10px 18px rgba(0, 0, 0, 0.35),
        0 2px 4px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    cursor: pointer;
    user-select: none;
    touch-action: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.note:hover {
    transform: translateY(-2px);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.35) inset,
        0 14px 22px rgba(0, 0, 0, 0.4),
        0 3px 6px rgba(0, 0, 0, 0.3);
}

.note:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 3px;
}

.note--dragging {
    cursor: grabbing;
    z-index: 50;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.35) inset,
        0 22px 30px rgba(0, 0, 0, 0.5);
}

.note__title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(13px, 1.6vh, 18px);
    color: var(--color-ink);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* ------------------------------------------------------------ */
/* Backdrop + overlay (opened note)                               */
/* ------------------------------------------------------------ */

#backdrop {
    position: fixed;
    inset: 0;
    background: var(--color-overlay-backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
    z-index: 90;
}

.backdrop--visible {
    opacity: 1;
    pointer-events: auto;
}

#overlay-host {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
}

.overlay {
    position: absolute;
    top: 6%;
    left: 6%;
    right: 6%;
    bottom: 6%;
    background: var(--color-paper);
    border-radius: 22px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px 24px 40px;
    pointer-events: auto;
    transition: transform 0.32s cubic-bezier(0.22, 0.9, 0.3, 1), opacity 0.28s ease;
}

.overlay__header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    background: var(--color-paper);
    padding-bottom: 8px;
    z-index: 2;
}

.overlay__back {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(38, 36, 26, 0.08);
    color: var(--color-ink);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.overlay__back:hover { background: rgba(38, 36, 26, 0.16); }

.overlay__delete {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(181, 83, 61, 0.12);
    color: var(--color-danger);
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.overlay__delete:hover { background: rgba(181, 83, 61, 0.22); }

.overlay__title {
    font-family: var(--font-display);
    font-size: clamp(20px, 3vh, 30px);
    font-weight: 600;
    color: var(--color-ink);
    border: none;
    background: transparent;
    outline: none;
    flex: 1;
    min-width: 0;
}

.overlay__title::placeholder { color: var(--color-ink-soft); }

.overlay__content {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-ink);
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    flex: 1 1 auto;
    min-height: 120px;
    width: 100%;
}

.overlay__content::placeholder { color: var(--color-ink-soft); }

.overlay__children-label {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-ink-soft);
    border-top: 1px solid rgba(38, 36, 26, 0.14);
    padding-top: 18px;
    margin-top: 8px;
    flex-shrink: 0;
}

/* ------------------------------------------------------------ */
/* Floating action button                                         */
/* ------------------------------------------------------------ */

#fab-container {
    position: fixed;
    bottom: max(24px, env(safe-area-inset-bottom));
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

#fab {
    width: 58px;
    height: 58px;
    border-radius: var(--radius-fab);
    border: none;
    background: var(--color-accent);
    color: var(--color-canvas);
    font-size: 28px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.25s ease, background 0.2s ease;
}

#fab:hover { background: #cf9a4f; }

#fab.fab--open { transform: rotate(45deg); }

.fab-menu {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.fab-menu--open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.fab-menu__item {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-paper);
    background: #232920;
    border: 1px solid rgba(237, 228, 200, 0.12);
    border-radius: 999px;
    padding: 9px 16px;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
    transition: background 0.15s ease;
}

.fab-menu__item:hover { background: #2C3327; }

/* ------------------------------------------------------------ */
/* Status toast                                                   */
/* ------------------------------------------------------------ */

#status {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    left: 50%;
    transform: translate(-50%, -140%);
    background: #232920;
    color: var(--color-paper);
    font-family: var(--font-mono);
    font-size: 12.5px;
    padding: 9px 16px;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    z-index: 300;
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
    max-width: 86vw;
    text-align: center;
}

#status.status--visible {
    transform: translate(-50%, 0);
    opacity: 1;
}

#status.status--error { color: #F0A98F; }

/* ------------------------------------------------------------ */
/* Reduced motion                                                 */
/* ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    .note, .overlay, .fab-menu, #fab, #status, #backdrop {
        transition-duration: 0.01ms !important;
    }
}