:root {
    --bg: #0f172a;
    --card: #1e293b;
    --accent: #38bdf8;
    --text: #f8fafc;
    --danger: #ef4444;
    --warning: #facc15;
    --edit: #a855f7;
    --secondary: #334155;
    --success: #22c55e;
    --overlay: rgba(0, 0, 0, 0.8);
    --led-red: #ff3333;
    --vis-block-width: clamp(110px, 28vw, 400px); 
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0; 
    padding: 0 2% 40px 2%; 
}

.container { max-width: 98%; margin: 0 auto; }

/* --- HEADER --- */
.sticky-header {
    position: sticky;
    top: -1px;
    background: var(--bg);
    z-index: 100;
    padding: 15px 0;
    border-bottom: 1px solid transparent;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; 
}

.sticky-header.is-sticky {
    border-bottom: 1px solid var(--secondary);
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.7);
    padding: 10px 0;
}

.header-left { flex: 1; }
.header-center { flex: 2; text-align: center; }
.header-right { flex: 1; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

h1 { margin: 0; font-size: 1.2rem; opacity: 0.6; text-transform: uppercase; letter-spacing: 1px; }

.live-clock { 
    font-family: 'Digital-7 Mono', monospace; 
    font-size: clamp(4.5rem, 15vw, 12rem); 
    color: var(--led-red); 
    text-shadow: 0 0 15px rgba(255, 51, 51, 0.6); 
    line-height: 1;
    margin: 5px 0;
    letter-spacing: 2px;
}

.next-alarm-banner {
    font-size: clamp(1.5rem, 3.5vw, 2.5rem);
    font-weight: 900;
    color: var(--warning);
    margin-top: 8px;
    font-family: monospace;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(250, 204, 21, 0.4);
    line-height: 1.1;
}

.following-alarm {
    font-size: clamp(1rem, 2vw, 1.5rem); 
    color: #cbd5e1;
    font-family: monospace; 
    margin-top: 8px;
    font-weight: bold;
    letter-spacing: 1px;
    line-height: 1.1;
}

/* --- MODALS --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 9999; display: flex; justify-content: center; align-items: center;
    background: var(--overlay);
    backdrop-filter: blur(5px);
}

.ringing-mode { animation: blink-bg 0.6s infinite; background: rgba(0,0,0,0.9); }
.ringing-content { text-align: center; width: 100%; padding: 60px 0; border-top: 10px solid white; border-bottom: 10px solid white; background: rgba(0,0,0,0.8); }

.big-time { 
    font-family: 'Digital-7 Mono', monospace;
    font-size: clamp(6rem, 25vw, 15rem); 
    color: white;
    text-shadow: 0 0 20px white;
    line-height: 1; margin: 0; 
}
.big-label { font-size: clamp(1.5rem, 5vw, 3rem); font-weight: 700; text-transform: uppercase; margin-bottom: 40px; }

.manager-window {
    background: var(--card); width: 90%; max-width: 500px; max-height: 80vh;
    border-radius: 12px; border: 1px solid var(--secondary);
    display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.manager-header { padding: 15px; border-bottom: 1px solid var(--secondary); display: flex; justify-content: space-between; align-items: center; }
.manager-body { padding: 15px; overflow-y: auto; flex: 1; }
.profile-list { display: flex; flex-direction: column; gap: 10px; }

.profile-row { 
    display: flex; align-items: center; justify-content: space-between; 
    background: var(--bg); padding: 12px 15px; border-radius: 8px; border: 1px solid var(--secondary);
}
.profile-info { display: flex; flex-direction: column; }
.profile-name { font-weight: bold; font-size: 1.1rem; }
.profile-count { font-size: 0.8rem; opacity: 0.5; margin-top: 2px; }
.profile-actions { display: flex; gap: 8px; }

.btn-icon { background: none; border: none; cursor: pointer; font-size: 1.2rem; padding: 5px; opacity: 0.7; transition: opacity 0.2s; }
.btn-icon:hover { opacity: 1; transform: scale(1.1); }
.close-modal-btn { color: white; font-weight: bold; font-size: 1.5rem; }

.create-profile-btn { 
    width: 100%; padding: 12px; background: var(--accent); color: black; font-weight: bold; 
    border: none; border-radius: 8px; margin-bottom: 15px; cursor: pointer;
}

.stop-btn {
    background: white; color: black; font-size: 2rem; font-weight: 900;
    padding: 20px 60px; border-radius: 15px; border: none; cursor: pointer; width: 80%; max-width: 400px;
}

@keyframes blink-bg {
    0% { background-color: var(--danger); }
    50% { background-color: var(--warning); }
    100% { background-color: var(--danger); }
}

.hidden { display: none !important; }

/* --- FORM STYLING --- */
.alarm-creator, .alarm-creator * { box-sizing: border-box; }

.alarm-creator { 
    background: var(--card); padding: 25px; border-radius: 12px; 
    border: 2px solid transparent; width: 95%; max-width: 750px; max-height: 90vh; 
    overflow-y: auto; overflow-x: hidden;
    position: relative; box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.alarm-creator.editing-mode { border-color: var(--edit); box-shadow: 0 0 25px rgba(168, 85, 247, 0.4); }
.alarm-creator.copy-mode { border-color: var(--success); box-shadow: 0 0 25px rgba(34, 197, 94, 0.4); }

.input-row { display: flex; gap: 15px; margin-bottom: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; flex: 1; min-width: 180px; }

.field label { font-size: 0.7rem; margin-bottom: 4px; color: var(--accent); text-transform: uppercase; font-weight: bold; }
input, select { padding: 12px; border-radius: 8px; border: 1px solid #334155; background: #0f172a; color: white; font-size: 1rem; width: 100%; }
input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(1); cursor: pointer; }

.days-section { display: flex; align-items: center; gap: 20px; margin-bottom: 15px; padding-top: 15px; border-top: 1px solid #334155; flex-wrap: wrap; }
.quick-select-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-btn { font-size: 0.8rem; padding: 8px 12px; border-radius: 6px; background: var(--secondary); color: white; border: none; cursor: pointer; flex: 1; }
.mini-btn:hover { background: var(--accent); color: black; }

.days-picker { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.9rem; }
.days-picker label { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 5px; background: rgba(255,255,255,0.05); border-radius: 4px; }

.add-btn { background: var(--accent); color: #000; width: 100%; padding: 14px; border-radius: 8px; font-weight: bold; border: none; cursor: pointer; font-size: 1rem; }
.update-btn { background: var(--edit) !important; color: white !important; }
.copy-confirm-btn { background: var(--success) !important; color: black !important; }

/* --- GRID & CARDS --- */
.alarm-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(var(--card-width, 240px), 1fr)); 
    gap: 15px; 
    margin-top: 20px;
}
.alarm-card { 
    background: var(--card); padding: 20px; border-radius: 12px; 
    border-left: 6px solid var(--accent); position: relative; 
    transition: all 0.3s ease;
}
.alarm-card.inactive { opacity: 0.5; border-left-color: #475569; }

.next-alarm-highlight {
    border-color: var(--warning) !important;
    box-shadow: 0 0 15px rgba(250, 204, 21, 0.3) !important;
    background: rgba(250, 204, 21, 0.05) !important;
}

.card-time { font-size: var(--font-size, 2.2rem); font-weight: 900; margin-bottom: 5px; display: block; line-height: 1;}

.card-toggle { 
    position: absolute; 
    top: 20px; 
    right: 20px; 
    width: 24px; 
    height: 24px;
    cursor: pointer; 
    accent-color: var(--success);
    margin: 0;
}

.card-label { font-size: var(--label-size, 1rem); font-weight: bold; margin-bottom: 4px; line-height: 1.2; }
.card-days { font-size: var(--meta-size, 0.8rem); opacity: 0.8; margin-bottom: 6px; }
.card-info .sound-tag { font-size: var(--meta-size, 0.7rem); color: var(--accent); background: rgba(56, 189, 248, 0.1); padding: 4px 8px; border-radius: 4px; display: inline-block; }

.card-actions { display: flex; gap: 10px; margin-top: 15px; border-top: 1px solid #334155; padding-top: 10px; }

.edit-btn, .delete-btn, .copy-btn { 
    font-size: 0.85rem; 
    padding: 8px 12px; 
    background: none; border: none; cursor: pointer; font-weight: bold; flex: 1; border-radius: 4px;
}
.edit-btn { background: rgba(168, 85, 247, 0.1); color: var(--edit); }
.delete-btn { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.copy-btn { background: rgba(34, 197, 94, 0.1); color: var(--success); }

.sync-status { font-size: 0.7rem; opacity: 0.7; margin-top: 5px; font-family: monospace; display: flex; align-items: center; gap: 8px;}

.follow-btn {
    background: transparent; border: 1px solid var(--secondary); color: var(--text);
    padding: 6px 12px; border-radius: 6px; font-size: 0.85rem; cursor: pointer;
    transition: all 0.2s; opacity: 0.8; font-weight: bold;
}
.follow-btn.active {
    background: rgba(34, 197, 94, 0.2); border-color: var(--success); 
    color: var(--success); opacity: 1;
}

/* --- VISUALIZER --- */
#visualizerMode {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at top, #1e293b 0%, #020617 80%);
    z-index: 9500; overflow: hidden;
}

#particleCanvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 9500; 
    pointer-events: none; 
}

.laser-line {
    position: absolute; bottom: 20%; left: 0; width: 100%; height: 4px;
    background: var(--accent);
    box-shadow: 0 0 15px var(--accent), 0 0 30px var(--accent);
    z-index: 9501;
}

.laser-line::after {
    content: 'NOW'; position: absolute; right: 30px; bottom: 10px;
    color: var(--accent); font-family: monospace; font-weight: 900; letter-spacing: 4px;
    text-shadow: 0 0 15px var(--accent); font-size: 1.5rem;
}

.visualizer-clock {
    position: absolute;
    bottom: 4vh; 
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Digital-7 Mono', monospace;
    font-size: clamp(4rem, 11vw, 9rem); 
    color: var(--accent);
    text-shadow: 0 0 15px var(--accent), 0 0 40px var(--accent);
    z-index: 9505;
    letter-spacing: 4px;
    pointer-events: none;
    white-space: nowrap;
    line-height: 1; 
}

.tetris-block {
    position: absolute; 
    width: var(--vis-block-width); 
    padding: clamp(10px, 2vw, 20px);
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--accent); 
    border-radius: 8px;
    color: #fff; font-family: monospace; text-align: center;
    transition: bottom 1s linear, left 0.5s ease-out; 
    z-index: 9502;
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.2), inset 0 0 5px rgba(56, 189, 248, 0.1); 
    backdrop-filter: blur(8px);
    box-sizing: border-box; 
}

.tetris-block::before {
    content: '';
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.15) 0%, rgba(15, 23, 42, 0) 70%);
    animation: inner-pulse-vis 6s infinite alternate;
    z-index: -1;
    border-radius: 6px;
}

@keyframes inner-pulse-vis {
    0% { opacity: 0.1; }
    100% { opacity: 0.4; }
}

.tetris-label {
    font-weight: 900; 
    font-size: clamp(0.9rem, 2.2vw, 1.8rem); 
    margin-bottom: 5px; 
    word-wrap: break-word; 
    line-height: 1.2;
}

.tetris-time {
    font-size: clamp(1.2rem, 3.5vw, 2.8rem); 
    font-weight: bold;
    color: var(--accent);
    text-shadow: none; 
}

.close-visualizer {
    position: absolute; 
    top: 20px; 
    right: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff; 
    opacity: 0.15; 
    font-weight: bold; 
    z-index: 9510; 
    font-size: 1.2rem;
    background: rgba(255,255,255,0.05); 
    border-radius: 50%; 
    border: 1px solid rgba(255,255,255,0.05);
    cursor: pointer; 
    backdrop-filter: blur(2px);
    transition: all 0.3s ease;
}
.close-visualizer:hover { background: rgba(255,255,255,0.3); border-color: white; color: var(--accent); opacity: 1; backdrop-filter: blur(5px); }

@keyframes pulse-calm { 
    0% { box-shadow: 0 0 10px var(--edit), inset 0 0 5px rgba(168, 85, 247, 0.2); } 
    50% { box-shadow: 0 0 25px var(--edit), inset 0 0 15px rgba(168, 85, 247, 0.4); } 
    100% { box-shadow: 0 0 10px var(--edit), inset 0 0 5px rgba(168, 85, 247, 0.2); } 
}
@keyframes pulse-warn { 
    0% { box-shadow: 0 0 10px var(--warning), inset 0 0 5px rgba(250, 204, 21, 0.2); } 
    50% { box-shadow: 0 0 25px var(--warning), inset 0 0 15px rgba(250, 204, 21, 0.4); } 
    100% { box-shadow: 0 0 10px var(--warning), inset 0 0 5px rgba(250, 204, 21, 0.2); } 
}
@keyframes pulse-crit { 
    0% { box-shadow: 0 0 10px var(--danger), inset 0 0 5px rgba(239, 68, 68, 0.2); } 
    50% { box-shadow: 0 0 25px var(--danger), inset 0 0 15px rgba(239, 68, 68, 0.4); } 
    100% { box-shadow: 0 0 10px var(--danger), inset 0 0 5px rgba(239, 68, 68, 0.2); } 
}

/* --- MOBILE STYLES --- */
@media (max-width: 768px) {
    .header-left, .header-right { flex: 1 1 100%; text-align: center; margin-bottom: 10px; }
    .header-center { flex: 1 1 100%; order: -1; margin-bottom: 15px; }
    .header-right { align-items: center !important; } 
    
    .input-row { flex-direction: column; gap: 10px; } 
    .days-section { flex-direction: column; align-items: stretch; gap: 10px; }
    .days-picker { justify-content: space-between; }
    .days-picker label { flex: 1 1 30%; justify-content: center; padding: 10px; background: var(--secondary); border-radius: 6px; }
    .sync-status { justify-content: center; }

    .card-toggle {
        top: 15px !important;
        right: 15px !important;
    }
}
/* --- UNIVERSAL EMOJI FIX --- */
img.emoji {
    height: 1.2em !important;
    width: 1.2em !important;
    margin: 0 .05em 0 .1em !important;
    vertical-align: -0.1em !important;
    pointer-events: none !important;
    display: inline-block !important;
}