:root {
    /* iOS Light Mode Colors */
    --ios-bg-primary: #FFFFFF;
    --ios-bg-secondary: #F2F2F7;
    /* Sidebar Gray */
    --ios-separator: #C6C6C8;
    --ios-yellow: #E0AB38;
    /* Classic Notes Yellow */
    --ios-text-primary: #000000;
    --ios-text-secondary: #8E8E93;
    --ios-search-bg: #E3E3E8;

    /* Layout */
    --sidebar-width: 350px;
    --header-height: 50px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 17px;
    background-color: var(--ios-bg-secondary);
    color: var(--ios-text-primary);
    overflow: hidden;
    /* App-like feel */
    height: 100vh;
    height: 100dvh;
    /* Dynamic Viewport Height for Mobile Safari */
}

#app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    background-color: var(--ios-bg-secondary);
    animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--ios-bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--ios-separator);
    height: 100%;
    z-index: 10;
}

.sidebar-header {
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    /* Handle Notch */
    height: auto;
    min-height: 44px;
    display: flex;
    align-items: center;
    color: var(--ios-yellow);
    font-weight: 500;
    font-size: 17px;
}

.folder-back {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.back-icon {
    font-size: 22px;
    margin-right: 5px;
    margin-top: -2px;
}

.sidebar-title {
    padding: 5px 20px 10px;
    font-size: 30px;
    font-weight: 700;
    color: var(--ios-text-primary);
    letter-spacing: 0.3px;
}

/* Search Bar */
.search-bar {
    padding: 10px 16px;
}

.search-input-wrapper {
    background-color: #7676801F;
    /* Specific iOS search bar fill */
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
}

.search-icon {
    margin-right: 8px;
    opacity: 0.6;
}

.search-input-wrapper input {
    border: none;
    background: transparent;
    font-size: 17px;
    width: 100%;
    outline: none;
    color: var(--ios-text-primary);
}

/* Note List */
.note-list {
    list-style: none;
    padding: 0 16px;
    overflow-y: auto;
    flex: 1;
    /* Take remaining height */
    margin-top: 10px;
}

.note-item {
    background-color: transparent;
    border-radius: 0;
    padding: 12px 20px;
    margin-bottom: 0;
    cursor: pointer;
    box-shadow: none;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    -webkit-touch-callout: none;
    border-bottom: 1px solid #C6C6C8;
}

.note-item:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

.note-item:last-child {
    border-bottom: none;
}

.note-item:active {
    background-color: #D1D1D6;
}

.note-item.active {
    background-color: #FFFFFF;
    /* Selected state in split view is often White with shadow or Yellow text. Let's go with White for high contrast */
    border: none;
    border-radius: 10px;
    /* actually mostly rounded in modern iPadOS split view */
    margin: 0 10px 5px 10px;
    /* Inset style */
}

/* Adjust active text for contrast if needed */
.note-item.active .note-title,
.note-item.active .note-time,
.note-item.active .note-preview {
    color: var(--ios-text-primary);
}

.note-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
}

.note-meta {
    display: flex;
    font-size: 15px;
    color: var(--ios-text-secondary);
    white-space: nowrap;
    overflow: hidden;
}

.note-time {
    margin-right: 8px;
    min-width: fit-content;
}

.note-preview {
    text-overflow: ellipsis;
    overflow: hidden;
}

.sidebar-footer {
    height: 44px;
    border-top: 1px solid var(--ios-separator);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 11px;
    color: var(--ios-text-secondary);
    position: relative;
    background-color: var(--ios-bg-secondary);
    backdrop-filter: blur(10px);
    padding-bottom: env(safe-area-inset-bottom);
    /* Handle Home Bar */
    height: auto;
    min-height: 44px;
}

.new-note-icon {
    position: absolute;
    right: 20px;
    top: 10px;
    cursor: pointer;
}

/* Editor Styling */
.editor {
    flex: 1;
    background-color: var(--ios-bg-primary);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    position: relative;
    z-index: 1;
}

.editor-header {
    height: auto;
    min-height: 50px;
    padding: 0 20px;
    padding-top: max(0px, env(safe-area-inset-top));
    /* Handle Notch in Landscape/Editor */
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Sticky header for scroll */
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
}

.mobile-back-btn {
    display: none;
    /* Hide on desktop */
    background: none;
    border: none;
    color: var(--ios-yellow);
    font-size: 17px;
    font-weight: 500;
    align-items: center;
    cursor: pointer;
}

.mobile-back-btn .chevron {
    font-size: 24px;
    margin-right: 2px;
    margin-top: -3px;
    display: inline-block;
}

.editor-actions {
    display: flex;
    gap: 20px;
    margin-left: auto;
    /* Push to right */
}

.action-icon {
    cursor: pointer;
    opacity: 0.8;
    transition: all 0.2s ease;
}

.action-icon:hover {
    opacity: 1;
    transform: scale(1.1);
}

.note-container {
    padding: 20px 40px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    animation: noteContentFade 0.3s ease-out;
}

@keyframes noteContentFade {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.note-date {
    text-align: center;
    color: var(--ios-text-secondary);
    font-size: 13px;
    margin-bottom: 20px;
    font-weight: 500;
}

.note-headline {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 20px;
    line-height: 1.2;
    text-align: left;
}

.note-body {
    font-size: 18px;
    line-height: 1.6;
    color: var(--ios-text-primary);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    text-align: left;
}

.note-body p {
    margin-bottom: 1em;
}

.note-body p:last-child {
    margin-bottom: 0;
}

.note-body h3 {
    font-size: 20px;
    font-weight: 600;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: var(--ios-text-primary);
}

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

.note-body ul,
.note-body ol {
    margin: 0.5em 0 1em 1.5em;
}

.note-body li {
    margin-bottom: 0.4em;
}

.note-body a {
    color: var(--ios-yellow);
    text-decoration: none;
    position: relative;
    transition: color 0.2s ease;
}

.note-body a::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 0;
    height: 1px;
    background-color: var(--ios-yellow);
    transition: width 0.25s ease;
}

.note-body a:hover::after {
    width: 100%;
}

.note-body a:hover {
    text-decoration: none;
}

/* Project Cards */
.project-card {
    background: var(--ios-bg-secondary);
    border-radius: 12px;
    padding: 16px 20px;
    margin: 1em 0;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border: 1px solid transparent;
}

.project-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: rgba(224, 171, 56, 0.2);
}

.project-card h3 {
    margin-top: 0 !important;
    margin-bottom: 0.3em !important;
    transition: color 0.2s ease;
}

.project-card:hover h3 {
    color: var(--ios-yellow);
}

.project-card a {
    display: inline-block;
    margin-top: 8px;
    color: var(--ios-yellow);
    font-weight: 500;
    font-size: 15px;
    transition: all 0.2s ease;
}

.project-card a:hover {
    transform: translateX(3px);
}

/* Journal Entry Styling */
.journal-entry {
    border-left: 3px solid var(--ios-yellow);
    padding-left: 16px;
    margin: 1.5em 0;
}

.journal-date {
    font-size: 13px;
    color: var(--ios-text-secondary);
    margin-bottom: 0.5em;
    font-weight: 500;
}

/* Currently Section */
.currently-item {
    display: flex;
    gap: 12px;
    margin-bottom: 1em;
    align-items: flex-start;
    padding: 12px 14px;
    background: var(--ios-bg-secondary);
    border-radius: 10px;
    transition: all 0.2s ease;
}

.currently-item:hover {
    transform: translateX(3px);
    background: rgba(224, 171, 56, 0.08);
}

.currently-emoji {
    font-size: 24px;
    line-height: 1.2;
    transition: transform 0.2s ease;
}

.currently-item:hover .currently-emoji {
    transform: scale(1.1);
}

.currently-content {
    flex: 1;
}

.currently-label {
    font-size: 13px;
    color: var(--ios-text-secondary);
    margin-bottom: 2px;
}

.currently-value {
    font-weight: 500;
}

/* Fun Facts / Tags */
.fact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin: 1em 0;
}

.fact-item {
    background: var(--ios-bg-secondary);
    padding: 12px 16px;
    border-radius: 10px;
}

.fact-label {
    font-size: 12px;
    color: var(--ios-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.fact-value {
    font-weight: 500;
}

/* Quote Block */
.quote-block {
    font-style: italic;
    font-size: 20px;
    color: var(--ios-text-secondary);
    border-left: 3px solid var(--ios-yellow);
    padding-left: 16px;
    margin: 1.5em 0;
}

/* Interest Tags */
.interest-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 1em 0;
}

.interest-tag {
    background: rgba(224, 171, 56, 0.15);
    color: var(--ios-yellow);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

/* Service Overview Styles */
.service-overview {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 1.5em 0;
}

.service-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    background: var(--ios-bg-secondary);
    border-radius: 12px;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border: 1px solid transparent;
}

.service-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: rgba(224, 171, 56, 0.2);
}

.service-emoji {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.service-item:hover .service-emoji {
    transform: scale(1.1);
}

.service-text {
    flex: 1;
}

.service-text strong {
    display: block;
    font-size: 17px;
    margin-bottom: 4px;
    color: var(--ios-text-primary);
    transition: color 0.2s ease;
}

.service-item:hover .service-text strong {
    color: var(--ios-yellow);
}

.service-text p {
    margin: 0 !important;
    font-size: 15px;
    color: var(--ios-text-secondary);
}

/* Last.fm Widget Styles */
.lastfm-widget {
    background: var(--ios-bg-secondary);
    border-radius: 12px;
    padding: 12px 16px;
    margin: 1em 0;
}

.lastfm-widget.now-playing {
    background: linear-gradient(135deg, rgba(224, 171, 56, 0.1), rgba(224, 171, 56, 0.05));
    border: 1px solid rgba(224, 171, 56, 0.2);
}

.lastfm-header {
    margin-bottom: 10px;
}

.lastfm-status {
    font-size: 13px;
    font-weight: 600;
    color: var(--ios-yellow);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.lastfm-track {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lastfm-album-art {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.lastfm-album-art-placeholder {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    background: var(--ios-separator);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.lastfm-track-info {
    flex: 1;
    min-width: 0;
}

.lastfm-track-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lastfm-artist {
    font-size: 13px;
    color: var(--ios-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lastfm-time {
    font-size: 12px;
    color: var(--ios-text-secondary);
    margin-top: 2px;
}

/* Animated playing indicator */
.lastfm-playing-indicator {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 20px;
    padding-left: 8px;
}

.lastfm-playing-indicator span {
    width: 3px;
    background: var(--ios-yellow);
    border-radius: 2px;
    animation: sound-bar 0.8s infinite ease-in-out;
}

.lastfm-playing-indicator span:nth-child(1) {
    height: 8px;
    animation-delay: 0s;
}

.lastfm-playing-indicator span:nth-child(2) {
    height: 14px;
    animation-delay: 0.2s;
}

.lastfm-playing-indicator span:nth-child(3) {
    height: 10px;
    animation-delay: 0.4s;
}

@keyframes sound-bar {

    0%,
    100% {
        transform: scaleY(0.5);
    }

    50% {
        transform: scaleY(1);
    }
}

.lastfm-empty {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    color: var(--ios-text-secondary);
    font-size: 14px;
}

/* Spotify Embed Styles */
.spotify-embed {
    margin: 1.5em 0;
    border-radius: 12px;
    overflow: hidden;
}

.spotify-embed iframe {
    display: block;
    border-radius: 12px;
}

.playlist-section {
    margin-top: 2em;
}

.playlist-section h3 {
    margin-bottom: 1em !important;
}

/* Responsive Handlers */
@media (max-width: 768px) {
    #app {
        position: relative;
    }

    .sidebar {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
        will-change: transform;
        backface-visibility: hidden;
    }

    .editor {
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        transform: translateX(100%);
        /* Start hidden */
        transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.1);
        /* iOS slide shadow */
        z-index: 20;
        /* Ensure it slides ABOVE sidebar */
        will-change: transform;
        backface-visibility: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* States for Mobile */
    body.view-note .sidebar {
        transform: translateX(-30%);
        /* Subtle parallax fade out */
    }

    body.view-note .editor {
        transform: translateX(0);
    }

    .mobile-back-btn {
        display: flex;
    }

    .note-container {
        padding: 20px;
    }

    .note-item.active {
        border: none;
        /* No selected state on list view in mobile usually */
    }
}

/* ========================================
   DARK MODE - System Preference Detection
   Matches iOS Notes Dark Theme
   ======================================== */
@media (prefers-color-scheme: dark) {
    :root {
        --ios-bg-primary: #1C1C1E;
        --ios-bg-secondary: #000000;
        --ios-separator: #38383A;
        --ios-yellow: #FFD60A;
        --ios-text-primary: #FFFFFF;
        --ios-text-secondary: #98989D;
        --ios-search-bg: #1C1C1E;
    }

    body {
        background-color: var(--ios-bg-secondary);
    }

    #app {
        background-color: var(--ios-bg-secondary);
    }

    /* Sidebar */
    .sidebar {
        background-color: var(--ios-bg-secondary);
        border-right-color: var(--ios-separator);
    }

    .sidebar-header {
        color: var(--ios-yellow);
    }

    .sidebar-title {
        color: var(--ios-text-primary);
    }

    .search-input-wrapper {
        background-color: var(--ios-search-bg);
    }

    .search-input-wrapper input {
        color: var(--ios-text-primary);
    }

    .search-input-wrapper input::placeholder {
        color: var(--ios-text-secondary);
    }

    .note-item {
        border-bottom-color: var(--ios-separator);
    }

    .note-item:hover {
        background-color: rgba(255, 255, 255, 0.05);
    }

    .note-item:active {
        background-color: #2C2C2E;
    }

    .note-item.active {
        background-color: #2C2C2E;
    }

    .note-title {
        color: var(--ios-text-primary);
    }

    .note-meta {
        color: var(--ios-text-secondary);
    }

    .sidebar-footer {
        border-top-color: var(--ios-separator);
        background-color: var(--ios-bg-secondary);
    }

    /* Editor */
    .editor {
        background-color: var(--ios-bg-primary);
    }

    .editor-header {
        background: rgba(28, 28, 30, 0.95);
    }

    .mobile-back-btn {
        color: var(--ios-yellow);
    }

    .note-date {
        color: var(--ios-text-secondary);
    }

    .note-headline {
        color: var(--ios-text-primary);
    }

    .note-body {
        color: var(--ios-text-primary);
    }

    .note-body h3 {
        color: var(--ios-text-primary);
    }

    .note-body a {
        color: var(--ios-yellow);
    }

    .note-body a::after {
        background-color: var(--ios-yellow);
    }

    /* Project Cards */
    .project-card {
        background: #2C2C2E;
    }

    .project-card:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        border-color: rgba(255, 214, 10, 0.3);
    }

    /* Journal Entries */
    .journal-entry {
        border-left-color: var(--ios-yellow);
    }

    .journal-date {
        color: var(--ios-text-secondary);
    }

    /* Currently Section */
    .currently-item {
        background: #2C2C2E;
    }

    .currently-item:hover {
        background: rgba(255, 214, 10, 0.1);
    }

    .currently-label {
        color: var(--ios-text-secondary);
    }

    .currently-value {
        color: var(--ios-text-primary);
    }

    /* Fact Items */
    .fact-item {
        background: #2C2C2E;
    }

    .fact-label {
        color: var(--ios-text-secondary);
    }

    .fact-value {
        color: var(--ios-text-primary);
    }

    /* Quote Block */
    .quote-block {
        color: var(--ios-text-secondary);
        border-left-color: var(--ios-yellow);
    }

    /* Interest Tags */
    .interest-tag {
        background: rgba(255, 214, 10, 0.15);
        color: var(--ios-yellow);
    }

    /* Last.fm Widget */
    .lastfm-widget {
        background: #2C2C2E;
    }

    .lastfm-widget.now-playing {
        background: linear-gradient(135deg, rgba(255, 214, 10, 0.1), rgba(255, 214, 10, 0.05));
        border-color: rgba(255, 214, 10, 0.2);
    }

    .lastfm-status {
        color: var(--ios-yellow);
    }

    .lastfm-track-name {
        color: var(--ios-text-primary);
    }

    .lastfm-artist {
        color: var(--ios-text-secondary);
    }

    .lastfm-time {
        color: var(--ios-text-secondary);
    }

    .lastfm-album-art-placeholder {
        background: var(--ios-separator);
    }

    .lastfm-playing-indicator span {
        background: var(--ios-yellow);
    }

    .lastfm-empty {
        color: var(--ios-text-secondary);
    }

    /* Scrollbar */
    ::-webkit-scrollbar-thumb {
        background: #48484A;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: #636366;
    }

    /* Selection */
    ::selection {
        background-color: rgba(255, 214, 10, 0.3);
    }

    /* Mobile slide shadow */
    @media (max-width: 768px) {
        .editor {
            box-shadow: -5px 0 20px rgba(0, 0, 0, 0.4);
        }
    }
}

/* Share Toast Notification */
.share-toast {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 500;
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.share-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

@media (prefers-color-scheme: dark) {
    .share-toast {
        background: rgba(60, 60, 67, 0.9);
    }
}