:root {
    /* Primary (초록 - Green) */
    --primary: #2B8A3E; 
    --primary-dark: #236B31; 
    --primary-light: #EBFBEE;
    
    /* Secondary (연두 - Yellow Green) */
    --secondary: #82C91E;
    --secondary-dark: #66A80F;
    --secondary-light: #F4FCE3;

    /* Accent (연초록 - Mint/Teal Green) */
    --accent: #20C997;
    --accent-dark: #12B886;
    --accent-light: #E6FCF5;

    /* Base Colors */
    --bg: #F4F7F4; 
    --card-bg: #FFFFFF;
    --text-main: #2C3E2D; 
    --text-sub: #7A8B7B;
    --border: #DCE5DD;
    
    /* Status Colors */
    --success: #37B24D; 
    --fail: #F03E3E; 
    --neutral: #CED4DA;
    
    /* Activity Badges */
    --act-work: #FFE066; --act-sleep: #B197FC; --act-leisure: #69DB7C;
    --act-meal: #FFA8A8; --act-study: #74C0FC; --act-social: #FCC419; --act-shop: #F06595;
    
    /* Location Cards */
    --loc-home: #E9ECEF; --loc-out: #D8F5A2; --loc-school: #D0EBFF;
    --loc-workplace: #FFF3BF; --loc-cafe: #FCC2D7; --loc-mart: #FFD8A8;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Pretendard', sans-serif; user-select: none; }
body { background-color: var(--bg); color: var(--text-main); display: flex; justify-content: center; height: 100dvh; overflow: hidden; }
#app { width: 100%; max-width: 600px; background: var(--bg); display: flex; flex-direction: column; position: relative; box-shadow: 0 0 25px rgba(0,0,0,0.06); }

/* Header */
header { padding: 18px 20px; border-bottom: 1px solid var(--border); background: var(--card-bg); z-index: 10; display: flex; justify-content: space-between; align-items: center; border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; box-shadow: 0 4px 12px rgba(43, 138, 62, 0.05); margin-bottom: 10px; }
.header-title { display: flex; flex-direction: column; align-items: flex-start; }
h1 { font-size: 1.2rem; color: var(--primary-dark); font-weight: 800; letter-spacing: -0.5px; }
.time-display { font-size: 0.85rem; color: var(--accent-dark); font-weight: 800; margin-top: 4px; background: var(--accent-light); padding: 4px 10px; border-radius: 12px; }

.header-controls { display: flex; gap: 12px; }
.btn-icon { background: none; border: none; color: var(--text-sub); font-size: 1.3rem; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; }
.btn-icon:hover { color: var(--primary); background: var(--primary-light); }

main { flex: 1; overflow-y: auto; padding: 10px 15px 30px; }
.view-section { display: none; animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.view-section.active { display: block; }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Cards & Typography */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px; padding: 20px; margin-bottom: 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.02); }
h3 { font-size: 1.05rem; margin-bottom: 15px; color: var(--text-main); font-weight: 700; display: flex; justify-content: space-between; align-items: center; }

/* Buttons & Inputs */
.btn { padding: 10px 16px; border-radius: 12px; border: none; cursor: pointer; font-weight: 600; font-size: 0.9rem; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex-shrink: 0; }
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: white; box-shadow: 0 4px 10px rgba(32, 201, 151, 0.2); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-outline { background: white; border: 1.5px solid var(--border); color: var(--text-main); font-size: 0.85rem; font-weight: 600;}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-danger { background: #FFF5F5; border: 1.5px solid #FFE3E3; color: var(--fail); font-size: 0.85rem; }
.btn-danger:hover { background: var(--fail); color: white; }

/* Inline Input Group for Roster */
.input-group { display: flex; gap: 8px; margin-bottom: 15px; }
.input-field { flex: 1; padding: 12px 16px; border: 1.5px solid var(--border); border-radius: 12px; font-size: 0.95rem; background: #F8F9F8; transition: 0.2s; user-select: text; font-weight: 600; min-width: 0; }
.input-field:focus { outline: none; border-color: var(--accent); background: white; box-shadow: 0 0 0 3px var(--accent-light); }
.input-field::placeholder { color: #ADB5BD; font-weight: 500; }

/* Roster Elements */
.char-list { display: grid; grid-template-columns: 1fr; gap: 12px; }
.char-item { display: flex; align-items: center; justify-content: space-between; padding: 12px; border: 1.5px solid var(--border); border-radius: 16px; background: white; transition: 0.2s; box-shadow: 0 2px 6px rgba(0,0,0,0.01); }
.char-item:hover { border-color: var(--accent); box-shadow: 0 6px 15px rgba(32, 201, 151, 0.06); transform: translateY(-2px); }

.char-info { display: flex; align-items: center; gap: 14px; flex: 1; }
.avatar-wrapper { position: relative; width: 48px; height: 48px; border-radius: 16px; cursor: pointer; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); flex-shrink: 0; }
.avatar-img { width: 100%; height: 100%; object-fit: cover; }
.avatar-initial { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.3rem; color: white; }
.avatar-overlay { position: absolute; top:0; left:0; width:100%; height:100%; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; opacity: 0; transition: 0.2s; color: white; }
.avatar-wrapper:hover .avatar-overlay { opacity: 1; }

.char-name-group { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; }
.char-name-row { display: flex; align-items: center; gap: 6px; }
.char-name { font-weight: 800; font-size: 1.05rem; color: var(--text-main); }
.btn-edit-name { background: none; border: none; color: var(--neutral); cursor: pointer; font-size: 0.8rem; transition: 0.2s; padding: 2px; }
.btn-edit-name:hover { color: var(--accent); }

.char-actions { display: flex; gap: 8px; }
.action-btn { width: 36px; height: 36px; border-radius: 12px; border: 1.5px solid var(--border); background: white; color: var(--text-sub); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; }
.action-btn:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.action-btn.del:hover { background: #FFF5F5; color: var(--fail); border-color: var(--fail); }

/* Data Controls Grid */
.data-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- Timeline Editor Modal --- */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100dvh; background: rgba(0,0,0,0.6); z-index: 1000; display: none; flex-direction: column; align-items: center; justify-content: flex-end; backdrop-filter: blur(4px); }
.modal.active { display: flex; }
.modal-content { background: var(--bg); width: 100%; max-width: 600px; height: 100%; max-height: 95dvh; border-top-left-radius: 24px; border-top-right-radius: 24px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 -10px 30px rgba(0,0,0,0.1); animation: slideUpModal 0.3s ease-out; }
@keyframes slideUpModal { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: white; z-index: 5; flex-shrink: 0; }
.modal-body { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

.timeline-container { flex: 1; overflow: auto; background: white; position: relative; touch-action: auto; min-height: 0; } 
.timeline-wrapper { position: relative; min-width: max-content; padding-bottom: 20px; padding-right: 40px;} 

.timeline-header { display: flex; position: sticky; top: 0; background: white; z-index: 20; border-bottom: 2px solid var(--border); font-size: 0.75rem; font-weight: 700; color: var(--text-sub); }
.tl-corner { width: 50px; min-width: 50px; position: sticky; left: 0; background: white; z-index: 21; border-right: 2px solid var(--border); }
.tl-hours { display: flex; flex: 1; }
.tl-hour-label { width: 44px; min-width: 44px; text-align: center; padding: 10px 0; border-left: 1px dashed var(--border); flex: 1; }
.tl-hour-label:first-child { border-left: none; }

.tl-row { display: flex; position: relative; border-bottom: 1px solid var(--border); min-height: 56px; }
.tl-day-label { width: 50px; min-width: 50px; position: sticky; left: 0; background: white; z-index: 15; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.85rem; border-right: 2px solid var(--border); color: var(--text-main); cursor: grab; transition: 0.2s; }
.tl-day-label:active { cursor: grabbing; }
.tl-day-label.drag-over { background: var(--primary-light); color: var(--primary-dark); border-right: 3px dashed var(--primary); }

.tl-content-area { position: relative; display: flex; flex: 1; }
.tl-grid-layer { display: flex; width: 100%; position: absolute; top:0; left:0; height: 100%; z-index: 1;}
.tl-cell { width: 44px; min-width: 44px; height: 100%; border-left: 1px dashed var(--border); transition: 0.1s; position: relative; flex: 1; }
.tl-cell:first-child { border-left: none; }

.tl-event-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }
.tl-block { position: absolute; border-radius: 8px; border: 1.5px solid rgba(0,0,0,0.1); display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 2px 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); color: #1A1A1A; }

/* 텍스트 줄임 및 색상 상속 적용 */
.tl-badge-text { font-size: 0.65rem; font-weight: 800; color: inherit; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; display: block; width: 100%; text-align: center; min-width: 0; }

.tl-selection-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none; display: flex;}
.tl-sel-cell { width: 44px; min-width: 44px; height: 100%; transition: background 0.1s; border-left: 1px solid transparent; cursor: crosshair; flex: 1; pointer-events: auto; }
.tl-sel-cell.selecting { background: rgba(32, 201, 151, 0.15); border-left: 1px dashed var(--accent); border-right: 1px dashed var(--accent); }

.editor-tools { padding: 12px 15px; background: white; border-top: 1px solid var(--border); z-index: 5; box-shadow: 0 -4px 10px rgba(0,0,0,0.02); flex-shrink: 0; }
.tool-group { margin-bottom: 10px; display: flex; align-items: center; gap: 10px; }
.tool-title { font-size: 0.8rem; font-weight: 800; color: var(--text-main); min-width: 35px; }
.chip-container { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 4px; flex: 1; scrollbar-width: none; }
.chip-container::-webkit-scrollbar { display: none; }
.select-chip { flex-shrink: 0; padding: 6px 12px; border-radius: 20px; border: 1.5px solid var(--border); background: #FAFBFA; font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: 0.2s; color: var(--text-sub); }
.select-chip.active { border-color: var(--accent); background: var(--accent); color: white; box-shadow: 0 2px 6px rgba(32, 201, 151, 0.2); }

.modal-footer { padding: 12px 15px; background: #F8F9FA; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); flex-shrink: 0; }
.selection-info { font-size: 0.8rem; font-weight: 700; color: var(--accent); display: flex; align-items: center; width: 100%; justify-content: center; }
.modal-footer-btns { display: flex; gap: 8px; width: 100%; justify-content: center; }
.modal-footer-btns button { flex: 1; padding: 10px 8px; font-size: 0.85rem; white-space: nowrap; }

/* Custom Mini Modals */
.dialog-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 2000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.dialog-overlay.active { opacity: 1; pointer-events: auto; }
.dialog-box { background: white; width: 90%; max-width: 320px; border-radius: 20px; padding: 25px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.1); transform: scale(0.9); transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.dialog-overlay.active .dialog-box { transform: scale(1); }
.dialog-title { font-size: 1.1rem; font-weight: 800; color: var(--text-main); margin-bottom: 10px; }
.dialog-desc { font-size: 0.9rem; color: var(--text-sub); margin-bottom: 20px; line-height: 1.4; word-break: keep-all; }
.dialog-btns { display: flex; gap: 10px; }
.dialog-btns button { flex: 1; }

/* Badge Colors */
.b-work { background: var(--act-work) !important; color: #1A1A1A !important; border-color: #E6C84C !important;} 
.b-sleep { background: var(--act-sleep) !important; color: #FFFFFF !important; border-color: #977CE6 !important;} 
.b-leisure { background: var(--act-leisure) !important; color: #1A1A1A !important; border-color: #55B865 !important;}
.b-meal { background: var(--act-meal) !important; color: #1A1A1A !important; border-color: #E68A8A !important;} 
.b-study { background: var(--act-study) !important; color: #1A1A1A !important; border-color: #5AA1E6 !important;} 
.b-social { background: var(--act-social) !important; color: #1A1A1A !important; border-color: #E6B012 !important;} 
.b-shop { background: var(--act-shop) !important; color: #FFFFFF !important; border-color: #D95482 !important;}

.l-home { background: var(--loc-home) !important; color: #1A1A1A !important; border-color: #CFD4D9 !important; } 
.l-out { background: var(--loc-out) !important; color: #1A1A1A !important; border-color: #C0DE8C !important; } 
.l-school { background: var(--loc-school) !important; color: #1A1A1A !important; border-color: #B5D2E6 !important; }
.l-workplace { background: var(--loc-workplace) !important; color: #1A1A1A !important; border-color: #E6DAA6 !important; } 
.l-cafe { background: var(--loc-cafe) !important; color: #1A1A1A !important; border-color: #E6ACC3 !important; } 
.l-mart { background: var(--loc-mart) !important; color: #1A1A1A !important; border-color: #E6BF91 !important; }