/* 타이머 공용 UI — 1차 필기시험 타이머와 이후 타이머가 함께 쓴다.
   루트 요소에 class="tm"을 달고 칩·버튼·상태줄·디지털 숫자·원판·알림 배너·전체화면 규칙을 그대로 쓴다.
   도구 전용 규칙(1차 벽시계·시간표 등)은 각 도구 CSS에 둔다 */

/* 칩·버튼·필드에 display를 주므로 브라우저 기본 [hidden] 규칙이 밀린다 — 되돌려 둔다 */
.tm [hidden] {
    display: none !important;
}

.tm {
    --tm-break: #2E7D32; /* 흰 글자 대비 4.5:1 이상 */
    max-width: 880px;
    margin: 0 auto;
}

/* ── 설정 패널 ── 접으면 머리줄에 현재 선택이 한 줄로 요약된다 */
.tm-panel {
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface-color);
}

.tm-panel-head {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    padding: 8px 14px;
    border: 0;
    border-radius: 12px;
    background: none;
    color: var(--text-color);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.tm-panel-head .material-icons {
    font-size: 20px;
    color: var(--text-muted-color);
}

.tm-panel-title {
    font-size: 14px;
    font-weight: 600;
}

.tm-panel-summary {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text-secondary-color);
}

/* 펼쳐 있으면 요약은 중복이라 걷는다 */
.tm-panel.is-open .tm-panel-summary {
    visibility: hidden;
}

.tm-panel-caret {
    transition: transform 0.2s;
}

.tm-panel.is-open .tm-panel-caret {
    transform: rotate(180deg);
}

.tm-panel-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 4px 32px;
    padding: 4px 14px 14px;
    border-top: 1px solid var(--border-color);
}

.tm-group-title {
    margin: 12px 0 4px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-muted-color);
}

.tm-field {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    padding: 6px 0;
}

.tm-label {
    flex: 0 0 52px;
    font-size: 13px;
    color: var(--text-secondary-color);
}

/* 단일 선택 칩은 하나로 이어진 분할 버튼, 알림 같은 다중 선택은 따로 떨어진 칩 */
.tm-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 3px;
    border-radius: 10px;
    background: var(--surface-alt-color);
}

.tm-chips--multi {
    gap: 6px;
    padding: 0;
    background: none;
}

.tm-chip {
    min-height: 32px;
    padding: 4px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: none;
    color: var(--text-secondary-color);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tm-chips--multi .tm-chip {
    border-color: var(--border-color);
    border-radius: 16px;
    background: var(--surface-color);
}

.tm-chip:hover:not(:disabled):not(.is-active) {
    background: var(--tint-orange-bg);
    color: var(--primary-dark);
}

.tm-chip.is-active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
    font-weight: 600;
}

.tm-chips--multi .tm-chip.is-active::before {
    content: '✓ ';
}

/* 진행 중엔 잠긴 설정(모드·범위·연장 등) */
.tm-chip:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.tm-chip.is-active:disabled {
    opacity: 0.8;
}

.tm-note {
    margin: 8px 0;
    font-size: 13px;
    color: var(--text-muted-color);
}

.tm-sound {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 12px 0;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--tint-amber-bg);
    color: var(--text-color);
    font-size: 14px;
}

/* 키보드 포커스 표시 */
.tm .tm-chip:focus-visible,
.tm .tm-panel-head:focus-visible,
.tm .tm-btn:focus-visible,
.tm .tm-digital:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 알림 배너 — 전체화면에서도 보이도록 .tm 루트 안에 둔다 */
/* 평소엔 Toast가 알리므로 배너는 전체화면 전용이고, 떠도 레이아웃을 밀지 않게 위에 겹친다 */
.tm-alert {
    display: none;
    position: fixed;
    top: 24px;
    left: 50%;
    z-index: 10;
    width: max-content;
    max-width: calc(100vw - 48px);
    transform: translateX(-50%);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    padding: 12px 16px;
    border-radius: 10px;
    background: var(--primary-color);
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
}

/* ── 상태 ── */
.tm-status {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 6px 12px;
    margin: 20px 0 12px;
    text-align: center;
}

.tm-phase {
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--surface-alt-color);
    color: var(--text-secondary-color);
    font-size: 13px;
    font-weight: 600;
}

.tm-phase[data-phase="exam"] { background: var(--primary-color); color: #fff; }
.tm-phase[data-phase="break"] { background: var(--tm-break); color: #fff; }
.tm-phase[data-phase="paused"] { background: var(--tint-amber-bg); color: var(--text-color); }

.tm-title {
    font-size: 20px;
}

.tm-range {
    font-size: 14px;
    color: var(--text-secondary-color);
    font-variant-numeric: tabular-nums;
}

/* ── 아날로그 ── */
.tm-clocks {
    display: flex;
    justify-content: center;
    gap: 32px;
}

.tm-clock {
    width: min(320px, 42vw);
    height: auto;
}

@media (max-width: 600px) {
    .tm-clocks {
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }

    .tm-clock {
        width: min(280px, 80vw);
    }
}

.tm-face { fill: var(--surface-color); stroke: var(--border-color); stroke-width: 2; }
.tm-tick { stroke: var(--text-muted-color); stroke-width: 1; }
.tm-tick-major { stroke: var(--text-color); stroke-width: 2.5; }
.tm-pin { fill: var(--text-color); }
.tm-disc { fill: var(--primary-color); }
.tm-disc.is-break { fill: var(--tm-break); }
.tm-disc.is-waiting { fill: var(--text-muted-color); opacity: 0.35; }
/* 원판 위 어느 색에서도 읽히도록 바탕색 테두리를 깐다 */
.tm-disc-label { fill: var(--text-color); font-size: 12px; text-anchor: middle; paint-order: stroke; stroke: var(--surface-color); stroke-width: 3; }

.tm-caption {
    margin: 12px 0 0;
    text-align: center;
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}

/* ── 디지털 ── */
.tm-digital {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 32px 16px;
    border: 0;
    background: none;
    color: var(--text-color);
    font: inherit;
    cursor: pointer;
}

.tm-digital-label { font-size: 15px; color: var(--text-secondary-color); }
.tm-digital-time { font-size: clamp(56px, 16vw, 128px); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.tm-digital-sub { font-size: 14px; color: var(--text-muted-color); font-variant-numeric: tabular-nums; }

/* ── 조작 ── */
.tm-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 24px 0 8px;
}

.tm-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 18px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface-color);
    color: var(--text-color);
    font: inherit;
    font-size: 15px;
    cursor: pointer;
}

.tm-btn-primary {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
}

@media (max-width: 767px) {
    .tm-chip { min-height: 40px; }
}

@media (max-width: 600px) {
    /* 좁으면 이름표를 칩 위로 올린다 */
    .tm-label { flex-basis: 100%; }
}

/* ── 전체화면: 시계와 조작만 남긴다 ── */
.tm:fullscreen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    max-width: none;
    padding: 24px;
    overflow-y: auto;
    background: var(--bg-color);
}

.tm:fullscreen .tm-alert { display: block; }

.tm:fullscreen .tm-panel,
.tm:fullscreen .tm-note {
    display: none;
}

/* 시계는 상태줄·조작 줄(약 220px)을 뺀 화면 전부를 쓴다. 두 개면 가로로 반씩 */
.tm:fullscreen .tm-clock {
    width: min(calc(50vw - 40px), calc(100vh - 220px));
}

.tm:fullscreen .tm-clock:only-child {
    width: min(calc(100vw - 48px), calc(100vh - 220px));
}

.tm:fullscreen .tm-caption { font-size: 26px; }

/* 가장 긴 표시 '1:20:00'(약 3.6em)이 가로를 넘지 않는 크기 */
.tm:fullscreen .tm-digital-time { font-size: min(24vw, 50vh); }
.tm:fullscreen .tm-digital-label { font-size: 24px; }
.tm:fullscreen .tm-digital-sub { font-size: 22px; }

@media (max-width: 600px) {
    /* 세로로 쌓이므로 두 개면 높이를 반씩 */
    .tm:fullscreen .tm-clock {
        width: min(calc(100vw - 48px), calc((100vh - 240px) / 2));
    }

    .tm:fullscreen .tm-clock:only-child {
        width: min(calc(100vw - 48px), calc(100vh - 220px));
    }
}
