:root {
    --chalkboard-green: #1a4332;
    --wood-frame: #5d4037;
    --clock-font: clamp(1.85rem, 3.2vw + 1rem, 3rem);
    --cal-month-fs: clamp(1.1rem, 1.9vw + 0.85rem, 1.75rem);
    --cal-cell-fs: clamp(0.76rem, 1.15vw + 0.5rem, 1.08rem);
    --cal-header-fs: clamp(0.8rem, 1.2vw + 0.5rem, 1.1rem);
    --student-name-fs: clamp(1.15rem, 1.8vw + 0.85rem, 1.65rem);
    --schedule-subject-fs: clamp(0.86rem, 1.2vw + 0.62rem, 1.14rem);
    --schedule-period-fs: clamp(0.68rem, 0.95vw + 0.45rem, 0.86rem);
    --eval-emoji-fs: clamp(1.35rem, 2vw + 0.85rem, 1.75rem);
    --layout-pad: clamp(8px, 1.5vw, 15px);
    --layout-gap: clamp(6px, 1vw, 12px);
    --today-twin-box: clamp(210px, 30vh, 290px);
}

html {
    height: 100%;
    box-sizing: border-box;
}

*, *::before, *::after { box-sizing: inherit; }

body {
    background: #222;
    margin: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    height: 100%;
    min-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

/* 화면 높이를 꽉 채우고, 안쪽에서만 스크롤 */
.chalkboard-bg {
    background: var(--chalkboard-green);
    border: clamp(4px, 1vw, 10px) solid var(--wood-frame);
    border-radius: 10px;
    flex: 1;
    min-height: 0;
    height: auto;
    padding: var(--layout-pad);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: var(--layout-gap);
    box-shadow: inset 0 0 80px rgba(0,0,0,0.5);
}

html:fullscreen,
html:fullscreen body {
    height: 100%;
    width: 100%;
    margin: 0;
    min-height: 0;
    overflow: hidden;
}

html:fullscreen .chalkboard-bg {
    border-radius: 0;
    flex: 1;
    min-height: 0;
    height: 100%;
}

.top-header-bar {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    min-height: clamp(52px, 8vw, 72px);
    margin-bottom: 5px;
    z-index: 2000;
    flex-shrink: 0;
}
/* 시계: 클릭 통과 + 낮은 z-index. 버튼 영역은 위 레이어에서 반드시 클릭 받음 */
.top-center-clock {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    padding: clamp(4px, 0.8vw, 8px) clamp(14px, 2.5vw, 28px) !important;
    pointer-events: none;
    z-index: 0;
}
.admin-area {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: min(52%, 540px);
    position: relative;
    z-index: 30;
    pointer-events: auto;
}
.teacher-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.admin-area .custom-selectors,
.admin-area .teacher-toolbar .droplet-btn,
.admin-area .focus-mode-toggle-btn,
.admin-area input[type="color"] {
    position: relative;
    z-index: 31;
    pointer-events: auto;
}
body.focus-mode .teacher-toolbar {
    display: none;
}
.focus-mode-toggle-btn {
    background: #7e57c2;
    flex-shrink: 0;
}
.focus-mode-toggle-btn:hover {
    filter: brightness(1.05);
}
body.focus-mode .focus-mode-toggle-btn {
    background: #5e35b1;
}
.custom-selectors { display: flex; gap: 8px; background: rgba(255, 255, 255, 0.9); padding: 4px 10px; border-radius: 15px; }
.picker-group { display: flex; align-items: center; gap: 4px; font-size: 0.7rem; font-weight: bold; color: #333; }
input[type="color"] { width: 18px; height: 18px; border: none; border-radius: 50%; cursor: pointer; background: none; padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }

.add-timer-btn { background: #ff5252; color: white; border: none; border-radius: 18px; padding: 6px 15px; font-size: 0.85rem; font-weight: bold; cursor: pointer; }
.droplet-btn { border: none; background: #64b5f6; border-radius: 18px; padding: 6px 15px; color: white; font-size: 0.85rem; font-weight: bold; cursor: pointer; }
.auth-toggle-btn { background: #ff9800; }
.auth-toggle-btn:hover { background: #f57c00; }

.top-nav {
    display: grid;
    grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr);
    gap: calc(var(--layout-gap) + 4px);
    flex: 4 1 0;
    min-height: clamp(200px, 28vh, 320px);
    box-sizing: border-box;
    min-width: 0;
}
.nav-cluster {
    display: grid;
    min-width: 0;
    gap: var(--layout-gap);
    align-items: stretch;
}
.nav-cluster-today {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.nav-cluster-today > .calendar-widget,
.nav-cluster-today > .weather-frame {
    width: 100%;
    max-width: var(--today-twin-box);
    height: var(--today-twin-box);
    max-height: var(--today-twin-box);
    min-height: 0;
    margin-inline: auto;
    justify-self: center;
    box-sizing: border-box;
}
.nav-cluster-today > .calendar-widget {
    max-width: calc(var(--today-twin-box) + 14px);
    height: calc(var(--today-twin-box) + 14px);
    max-height: calc(var(--today-twin-box) + 14px);
}
.nav-cluster-routine {
    grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    padding-left: calc(var(--layout-gap) + 4px);
    margin-left: 2px;
}
.widget { height: 100%; box-sizing: border-box; overflow: hidden; display: flex; flex-direction: column; justify-content: center; }
.glass-card { background: rgba(255, 255, 255, 0.15); backdrop-filter: blur(8px); border-radius: 18px; border: 1px solid rgba(255,255,255,0.2); }

.digital-clock-box {
    background: #000;
    border: clamp(3px, 0.6vw, 5px) solid #333;
    border-radius: clamp(10px, 1.5vw, 15px);
    box-shadow: 0 0 12px rgba(0,0,0,0.6);
}
.clock-text {
    font-size: var(--clock-font);
    line-height: 1.05;
    color: #ffeb3b;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    text-align: center;
    margin: 0;
}

.calendar-widget {
    background: white !important;
    padding: clamp(4px, 0.85vw, 10px) !important;
    align-items: center;
    justify-content: center;
    min-width: 0;
}
.home-cal-month {
    font-size: var(--cal-month-fs);
    font-weight: 900;
    margin-bottom: clamp(2px, 0.6vw, 6px);
    text-align: center;
    width: 100%;
    color: #333;
    white-space: nowrap;
}
#home-calendar {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    min-width: 0;
    overflow: hidden;
}
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    text-align: center;
    font-size: var(--cal-cell-fs);
    width: 100%;
    gap: clamp(1px, 0.35vw, 4px) 0;
    flex: 0 1 auto;
    align-content: center;
    min-width: 0;
    max-height: 100%;
}
.cal-day-header {
    color: #777;
    font-weight: bold;
    margin-bottom: clamp(2px, 0.5vw, 5px);
    font-size: var(--cal-header-fs);
    white-space: nowrap;
}
.cal-date-num {
    color: #333;
    font-weight: 800;
    font-size: var(--cal-cell-fs);
    white-space: nowrap;
}
.cal-grid div {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(18px, 3.2vw, 30px);
}
.cal-today {
    border: 2px solid #ff5252;
    border-radius: 50%;
    width: clamp(24px, 4.2vw, 34px);
    height: clamp(24px, 4.2vw, 34px);
    font-size: var(--cal-cell-fs);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: auto;
    font-weight: 900;
    color: #333;
    flex-shrink: 0;
}

.color-good { color: #81c784; } .color-normal { color: #ffe082; } .color-bad { color: #ffb74d; } .color-very-bad { color: #e57373; } .color-rain { color: #64b5f6; }

.weather-frame {
    align-items: center;
    justify-content: center;
    color: white;
    border: 3px solid rgba(255,255,255,0.4);
    padding: clamp(8px, 1.5vw, 15px) !important;
    gap: clamp(4px, 1vw, 8px);
    min-width: 0;
    overflow: hidden;
}
.weather-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(6px, 1.2vw, 10px);
    margin-bottom: 5px;
    position: relative;
    flex-wrap: nowrap;
}
.weather-emoji-large {
    font-size: clamp(1.6rem, 4.2vw, 2.8rem);
    cursor: pointer;
    margin-bottom: 0;
    flex-shrink: 0;
    line-height: 1;
}
.temp-large {
    font-size: clamp(1.15rem, 2.8vw, 1.95rem);
    font-weight: 900;
    white-space: nowrap;
}
.weather-refresh-btn {
    cursor: pointer;
    font-size: clamp(1rem, 2vw, 1.25rem);
    opacity: 0.7;
    transition: transform 0.5s ease-in-out, opacity 0.2s;
    margin-left: 5px;
    flex-shrink: 0;
}
.weather-refresh-btn:hover { opacity: 1; }
.dust-info-large {
    font-size: clamp(0.84rem, 1.6vw, 1.15rem);
    font-weight: bold;
    margin-top: 2px;
    background: rgba(0,0,0,0.2);
    padding: clamp(5px, 1.2vw, 8px) clamp(6px, 1.2vw, 10px);
    border-radius: 8px;
    width: 95%;
    max-width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.timer-section-stack {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 9px;
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
}
.add-timer-main-btn {
    flex-shrink: 0;
    align-self: center;
    padding: 8px 21px;
    font-size: 1.2rem;
}
.timer-row-flex {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(9px, 1.8vw, 18px);
    flex: 1;
    min-height: 0;
    min-width: 0;
    width: 100%;
}
.add-timer-extra-btn {
    flex-shrink: 0;
    width: clamp(51px, 12vw, 63px);
    height: clamp(51px, 12vw, 63px);
    border: none;
    border-radius: 18px;
    background: #ff5252;
    color: white;
    font-size: clamp(1.65rem, 4.5vw, 2rem);
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.25);
    align-items: center;
    justify-content: center;
    padding: 0;
}
.add-timer-extra-btn:hover {
    filter: brightness(1.08);
}
.timer-center-container {
    display: flex;
    gap: clamp(12px, 2.7vw, 27px);
    justify-content: center;
    align-items: center;
    flex: 1;
    height: 100%;
    width: 100%;
    min-width: 0;
    min-height: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
}
.visual-timer-circular {
    width: clamp(138px, 27vw, 186px);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(145deg, #2c3e50, #1a252f);
    padding: clamp(9px, 2.1vw, 18px);
    border-radius: clamp(21px, 3vw, 30px);
    box-shadow: 0 8px 23px rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.1);
}
.timer-face-white {
    width: clamp(96px, 21vw, 132px);
    height: clamp(96px, 21vw, 132px);
    background: white;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    border: 5px solid #fff;
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.2);
}
.timer-red-sector { width: 100%; height: 100%; border-radius: 50%; background: conic-gradient(#ff5252 0deg, #eee 0deg); }
.timer-center-dot { position: absolute; width: 15px; height: 15px; background: #ddd; border-radius: 50%; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2; }
.timer-controls-bottom { margin-top: 18px; width: 100%; text-align: center; }
.timer-name-input { width: 90%; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; font-size: 1.35rem; text-align: center; margin-bottom: 12px; font-weight: bold; padding: 9px; color: white; }
.timer-time-set { width: 68px; font-size: 1.35rem; font-weight: bold; text-align: center; border-radius: 6px; border: none; padding: 6px; background: white; color: #333; }
.timer-play-btn { background: #ff5252; color: white; border: none; border-radius: 6px; padding: 5px 12px; font-weight: bold; cursor: pointer; font-size: 1.1rem; }
.timer-close-btn { background: #999; color: white; border: none; border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 1.1rem; }

.meal-tray-widget { padding: 0 !important; align-items: center; min-width: 0; }
.timer-section {
    min-width: 0;
    justify-content: flex-start !important;
    padding-top: 4px;
}
.meal-tray-outer {
    background: #e0e0e0;
    border: clamp(3px, 0.8vw, 5px) solid #bdbdbd;
    border-radius: clamp(14px, 2vw, 20px);
    padding: clamp(5px, 1vw, 8px);
    width: min(100%, 360px);
    height: 90%;
    max-height: min(220px, 24vh);
    min-height: clamp(96px, 14vh, 150px);
    margin: 0 auto;
    box-sizing: border-box;
}
.tray-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: clamp(4px, 1vw, 8px);
    height: 100%;
}
.tray-cell {
    background: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: clamp(3px, 0.45vw, 6px);
    min-width: 0;
    min-height: 0;
    font-size: clamp(0.72rem, 1.35vw + 0.52rem, 1.05rem);
    font-weight: bold;
}
.tray-cell-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    text-align: center;
    line-height: 1.28;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: keep-all;
    hyphens: none;
    max-width: 100%;
}
.tray-cell.top { grid-column: span 2; }
.tray-cell.bottom { grid-column: span 3; }

/* 학생 영역: 남는 세로 공간을 채우고, 카드 안에서는 한 줄 유지 + 글자가 뷰포트에 맞게 축소 */
.student-section {
    flex: 6 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.student-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-end;
    gap: clamp(10px, 2vw, 20px);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-top: clamp(2px, 0.5vh, 8px);
    padding-bottom: clamp(10px, 2vh, 22px);
}

html:fullscreen {
    --today-twin-box: clamp(280px, 40vh, 410px);
}
html:fullscreen .top-nav {
    min-height: clamp(250px, 40vh, 500px);
}
html:fullscreen .nav-cluster,
html:fullscreen .nav-cluster-routine {
    align-items: stretch;
}
.student-card {
    flex: 1 1 clamp(140px, 32vw, 220px);
    max-width: min(100%, 380px);
    min-width: 0;
    box-sizing: border-box;
    background: white;
    border-radius: clamp(12px, 2vw, 18px);
    padding: clamp(10px, 1.8vw, 15px);
    color: #333;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
}

.student-card > div:last-child { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    justify-content: flex-start; 
    gap: 8px; 
    margin-top: 5px;
}

.card-header h3 {
    text-align: center;
    font-size: var(--student-name-fs);
    margin: 0 0 clamp(8px, 1.2vw, 12px) 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.schedule-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: clamp(3px, 0.55vw, 6px);
    background: #fdfdfd;
    padding: clamp(5px, 1vw, 8px) clamp(6px, 1.2vw, 10px);
    border-radius: 10px;
    border: 1px solid #eee;
    min-height: clamp(30px, 4vw, 40px);
    flex-wrap: nowrap;
}

.subject-text {
    font-size: var(--schedule-subject-fs);
    font-weight: 800;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: clamp(3px, 0.55vw, 5px);
    min-width: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
}
.subject-period {
    font-size: var(--schedule-period-fs);
    color: #888;
    flex-shrink: 0;
    line-height: 1.15;
}
.subject-main {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    line-height: 1.2;
}
.eval-emoji-group {
    display: flex;
    gap: 0;
    flex-shrink: 0;
    align-items: center;
}
.eval-btn {
    cursor: pointer;
    font-size: clamp(0.92rem, 1.25vw + 0.65rem, 1.28rem);
    opacity: 0.2;
    filter: grayscale(1);
    transition: 0.2s;
    line-height: 1;
    border: none;
    background: transparent;
    padding: 0 2px;
    margin: 0;
    font-family: inherit;
}
.eval-btn:hover { opacity: 0.6; filter: grayscale(0); }
.eval-btn:focus-visible {
    outline: 2px solid #1976d2;
    outline-offset: 2px;
    border-radius: 4px;
}
.eval-btn.active { opacity: 1 !important; filter: grayscale(0) !important; transform: scale(1.2); }

.class-info-area {
    display: flex;
    align-items: baseline;
    gap: clamp(6px, 1.2vw, 10px);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    min-width: 0;
    flex: 1 1 auto;
    max-width: calc(100% - min(320px, 52vw));
    padding-right: clamp(56px, 14vw, 180px);
    position: relative;
    z-index: 1;
    overflow: hidden;
}
#display-class-name {
    font-size: clamp(1.25rem, 2.5vw + 0.8rem, 1.95rem);
    color: #fff176;
    font-weight: 900;
    margin: 0;
    white-space: nowrap;
    flex-shrink: 0;
}
#display-class-motto {
    font-size: clamp(0.72rem, 1.1vw + 0.55rem, 0.95rem);
    color: rgba(255, 255, 255, 0.85);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

@media (max-width: 720px) {
    .top-nav {
        grid-template-columns: 1fr;
        min-height: unset;
        max-height: none;
    }
    .nav-cluster-today {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }
    .nav-cluster-routine {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        padding-top: var(--layout-gap);
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .admin-area {
        max-width: 100%;
    }

    .class-info-area {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        padding-right: 0;
    }

    #display-class-motto {
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}