:root {
    --bg: #050505;
    --card-bg: #111111;
    --text: #e0e0e0;
    --accent: #ff3c3c; /* Hyper-Red for alerts/actions */
    --dim: #555;
    --border: #333;
    --font-main: 'Georgia', 'Times New Roman', serif;
    --font-mono: 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

button, .ring {
    -webkit-tap-highlight-color: transparent;
    outline: none;                        
    user-select: none;                    
}

button:focus, .ring:focus {
    outline: none;                            
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-main);
    height: 100dvh;
    overflow: hidden; /* App-like feel */
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    max-width: 450px;
    height: 100%;
    position: relative;
    background: var(--bg);
    padding-bottom: env(safe-area-inset-bottom);
}

.screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
    z-index: 0;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    z-index: 10;
}

.hidden { display: none; }

/* --- TYPOGRAPHY --- */
h1 { font-size: 2rem; letter-spacing: 2px; margin-bottom: 1rem; font-weight: normal; }
h2 { font-size: 1.5rem; letter-spacing: 1px; font-weight: normal; text-transform: uppercase; }
p { line-height: 1.6; color: #ccc; font-size: 0.95rem; }

/* --- BUTTONS --- */
button {
    background: none;
    border: 1px solid var(--text);
    color: var(--text);
    padding: 1rem 2rem;
    font-family: var(--font-mono);
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s;
    letter-spacing: 1px;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

button:hover { background: var(--text); color: var(--bg); }

.btn-small { padding: 0.5rem 1rem; font-size: 0.8rem; }
.btn-secondary { border-color: var(--dim); color: var(--dim); }
.btn-secondary:hover { background: var(--dim); color: var(--text); }

/* --- VIEW 1: GATE --- */
.center-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
}

.pulsing-orb {
    width: 20px; height: 20px;
    background: var(--text);
    border-radius: 50%;
    margin-bottom: 2rem;
    box-shadow: 0 0 10px var(--text);
    animation: pulse 4s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.5); opacity: 1; }
    100% { transform: scale(1); opacity: 0.5; }
}

/* --- VIEW 2: SELECTOR --- */
.selector-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2rem;
}

.ring-group { text-align: center; }
.ring-group label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--dim);
    display: block;
    margin-bottom: 0.5rem;
}

.ring {
    font-size: 1.8rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.ring:active { color: var(--accent); }

/* --- VIEW 3: CARD --- */
.card {
    border: 1px solid var(--border);
    padding: 2rem;
    background: var(--card-bg);
    margin-top: auto;
    margin-bottom: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.card-header {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--dim);
    margin-bottom: 1.5rem;
    text-transform: uppercase;
}

.separator {
    width: 50px;
    height: 1px;
    background: var(--accent);
    margin: 1.5rem 0;
}

.advice-box {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--dim);
}

.advice-box .label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

/* --- VIEW 4: JOURNAL & CANVAS --- */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.8rem;
    margin-bottom: 1.5rem;
    height: auto;
}

.header-controls {
    display: flex;
    gap: 0.8rem;
}

/* Icon Buttons (Square & Modern) */
.btn-icon {
    width: 42px;
    height: 42px;
    padding: 0;
    margin: 0; /* Overrides global button margin */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    line-height: 1;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--dim);
    transition: all 0.2s ease;
    border-radius: 2px;
}

.btn-icon:hover {
    border-color: var(--text);
    color: var(--text);
    background: #1a1a1a;
    transform: translateY(-1px);
}

/* Primary "Add" Button */
#btn-new-dream {
    border-color: var(--accent);
    color: var(--accent);
}

#btn-new-dream:hover {
    background: var(--accent);
    color: #000;
    box-shadow: 0 0 10px rgba(255, 60, 60, 0.4);
}

.daily-sentence {
    font-style: italic;
    color: var(--dim);
    margin-bottom: 1rem;
    font-size: 1rem;
    border-left: 2px solid var(--accent);
    padding-left: 1rem;
}

/* Canvas Container */
#sky-container {
    flex-grow: 1;
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #111;
    background: radial-gradient(circle at center, #0a0a0a 0%, #000 100%);
    margin-bottom: 1rem;
    overflow: hidden;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* Tooltip (The Log Detail) */
.star-tooltip {
    position: absolute;
    background: rgba(10, 10, 10, 0.95);
    border: 1px solid var(--dim);
    padding: 0.8rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 20;
    width: 170px;
    font-size: 0.8rem;
    color: var(--text);
    box-shadow: 0 4px 15px rgba(0,0,0,0.8);
}

.star-tooltip strong {
    display: block;
    color: var(--accent);
    font-family: var(--font-main);
    font-size: 1rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid #333;
    padding-bottom: 0.25rem;
}

.star-tooltip span {
    display: block;
    color: var(--dim);
    font-family: var(--font-mono);
    margin-top: 0.2rem;
    font-size: 0.7rem;
}

.stats-container {
    display: flex;
    gap: 1rem;
}

.stat-box { flex: 1; text-align: center; }
.stat-num { display: block; font-size: 1.5rem; font-family: var(--font-mono); }
.stat-label { font-size: 0.7rem; color: var(--dim); text-transform: uppercase; }

/* Scrollbar Hide */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--dim); }

/* --- VIEW 5: HISTORY LIST (UPDATED) --- */
.history-container {
    flex-grow: 1;
    overflow-y: auto;
    margin-top: 0.5rem;
    padding-right: 5px;
    /* Fancy Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--dim) var(--bg);
}

.history-item {
    background: linear-gradient(90deg, #0a0a0a 0%, #111 100%);
    border: 1px solid #222;
    border-left: 2px solid var(--dim);
    padding: 1.2rem;
    margin-bottom: 1rem;
    position: relative;
    transition: all 0.2s ease;
}

.history-item:hover {
    border-left-color: var(--accent);
    background: #141414;
    transform: translateX(2px);
    box-shadow: -5px 5px 15px rgba(0,0,0,0.5);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.8rem;
    border-bottom: 1px dashed #222;
    padding-bottom: 0.5rem;
}

.history-date {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--dim);
    margin-top: 4px;
    text-transform: uppercase;
}

.history-title {
    font-size: 1.1rem;
    color: var(--text);
    letter-spacing: 0.5px;
}

.history-meta {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text);
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.history-meta span {
    color: var(--dim);
}

.history-directive {
    font-size: 0.9rem;
    color: #888;
    font-style: italic;
    line-height: 1.5;
}

.btn-delete-entry {
    opacity: 0; /* Hidden by default */
    background: transparent;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border: 1px solid #333;
    color: #444;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.2s;
    margin: 0;
}

.history-item:hover .btn-delete-entry {
    opacity: 1; /* Show on hover */
}

.btn-delete-entry:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(255, 60, 60, 0.1);
}

/* --- MOBILE ADJUSTMENTS --- */
@media (max-width: 600px) {
    .star-tooltip {
        width: auto;          /* Stop forcing 170px */
        min-width: 60px;     /* Ensure it's legible */
        max-width: 80px;     /* Cap width to prevent overflow */
        padding: 0.3rem;      /* Reduce padding */
        font-size: 0.7rem;    /* Smaller base text */
    }

    .star-tooltip strong {
        font-size: 0.75rem;   /* Smaller header */
        margin-bottom: 0.2rem;
        padding-bottom: 0.2rem;
    }

    .star-tooltip span {
        font-size: 0.65rem;   /* Smaller details */
        margin-top: 0.1rem;
    }
    .screen {
        overflow-y: auto; 
        -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
        justify-content: flex-start; /* Don't center vertically if scrolling */
    }

    /* 2. Shrink the massive gaps so it fits on screen */
    .selector-container {
        gap: 0.5rem; /* Reduced from 2rem */
        justify-content: center;
        padding: 1rem 0;
    }

    /* 3. Make rings smaller but still tappable */
    .ring {
        font-size: 1.4rem; /* Reduced from 1.8rem */
        padding: 0.8rem;
    }
    
    .ring-group label {
        margin-bottom: 0.2rem;
    }

    /* 4. Ensure button has space at the bottom */
    #btn-interpret {
        margin-top: 1rem;
        margin-bottom: 2rem; /* Space for scrolling past it */
        flex-shrink: 0; /* Prevent button from getting squashed */
    }
    p { font-size: 0.8rem; }
    .daily-sentence { font-size: 0.8rem; }
    
    /* Mobile Header adjustments */
    .dashboard-header {
        height: auto;
        padding-bottom: 1rem;
    }
    
    .stat-num { font-size: 1rem; }
    .stat-label { font-size: 0.6rem;}
    
    /* Ensure delete button is visible on mobile (no hover state) */
    .btn-delete-entry { opacity: 0.6; }
}