@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

:root {
    --bg-app: #f8f9fa;
    --bg-card: #ffffff;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --accent: #1e40af;
    /* Indigo-600 */
    --accent-hover: #1e3a8a;
    --border: #e5e7eb;
    --danger: #ef4444;
    --success: #10b981;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-app: #0f172a;
        --bg-card: #1e293b;
        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #64748b;
        --accent: #3b82f6;
        --accent-hover: #60a5fa;
        --border: #334155;
        --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    }
}

html,
body {
    height: 100%;
    font-family: var(--font-main);
    font-size: 16px;
    background: var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
    line-height: 1.5;
}

/* ─── Shared Components ─────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    gap: 8px;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-app);
}

/* ─── Header ───────────────────────────────────── */
#main-header {
    height: 72px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    z-index: 50;
    position: sticky;
    top: 0;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

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

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--bg-app);
}

/* ─── Lock Screen ─────────────────────────────────── */
#lock-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg-app);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 40px 24px;
}

#lock-screen.hidden {
    display: none !important;
}

.lock-input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 360px;
}

.lock-input-group input {
    width: 100%;
    padding: 16px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1.1rem;
    outline: none;
    text-align: center;
}

.lock-input-group input:focus {
    border-color: var(--accent);
}

.lock-title {
    font-size: 2.5rem;
    font-weight: 800;
    text-align: center;
}

.lock-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    text-align: center;
}

.lock-error {
    color: var(--danger);
    text-align: center;
    font-size: 0.9rem;
    height: 1.2rem;
}

/* ─── App Container ────────────────────────────── */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#app.hidden {
    display: none;
}

#main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* ─── Home View (List) ─────────────────────────── */
#home-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 32px;
    background: var(--bg-app);
}

.view-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 24px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#entries-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.entry-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: var(--shadow-sm);
}

.entry-card:hover {
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-date {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent);
}

.card-time {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

.card-preview {
    font-size: 0.95rem;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.6;
}

/* ─── Editor View ──────────────────────────────── */
#editor-view {
    position: fixed;
    inset: 0;
    background: var(--bg-app);
    z-index: 60;
    display: none;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

#editor-view.active {
    display: flex;
}

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

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

.editor-navbar {
    height: 72px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: var(--bg-card);
}

.editor-container {
    flex: 1;
    overflow-y: auto;
    padding: 40px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.editor-content {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.editor-meta-info {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
}

#entry-title-input {
    font-size: 2.5rem;
    font-weight: 800;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    width: 100%;
    letter-spacing: -0.025em;
}

#entry-title-input::placeholder {
    color: var(--text-muted);
}

#diary-textarea {
    font-size: 1.2rem;
    line-height: 1.8;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-secondary);
    width: 100%;
    resize: none;
    min-height: calc(100vh - 350px);
}

.char-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
    padding-top: 10px;
}

/* ─── Toast ─────────────────────────────────────── */
#toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: var(--bg-app);
    padding: 12px 28px;
    border-radius: 99px;
    font-weight: 600;
    z-index: 200;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow-md);
}

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

/* ─── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
    #main-header {
        padding: 0 16px;
    }

    .header-actions .icon-btn:not(:last-child) {
        display: none;
    }

    .logo {
        font-size: 1.25rem;
    }

    #home-view {
        padding: 20px;
    }

    #entry-title-input {
        font-size: 1.8rem;
    }

    .editor-container {
        padding: 24px 16px;
    }

    .editor-navbar {
        padding: 0 16px;
    }

    #entries-grid {
        grid-template-columns: 1fr;
    }
}