/* ============================================================
   Don't Count! - style.css
   Phong cách iOS tối giản, nền trắng, chữ đen.
   Mobile-first, responsive lên desktop.
   ============================================================ */

/* ---------- Reset cơ bản ---------- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
    background: #ffffff;
    color: #000000;
    /* Font hệ thống iOS/macOS, fallback sang sans-serif */
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display",
                 "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    /* Tắt double-tap-to-zoom và pinch-zoom trên iOS/Android.
       'manipulation' vẫn cho phép pan và tap bình thường,
       chỉ bỏ zoom → tránh bấm nhanh +/- bị phóng to. */
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

/* ---------- App container ----------
   Dùng 100dvh để fit đúng viewport thực trên mobile (tránh vấn đề
   thanh địa chỉ của Safari/Chrome mobile làm tràn màn hình).
   Toàn bộ nội dung chia theo flex-column, không cho phép scroll.
   ------------------------------------ */
.app {
    max-width: 500px;
    height: 100vh;           /* fallback */
    height: 100dvh;          /* viewport động, chuẩn cho mobile */
    margin: 0 auto;
    padding: 16px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    /* an toàn cho notch iPhone */
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* ---------- Header ---------- */
.header {
    position: relative;
    text-align: center;
    padding: 0;
    flex-shrink: 0;
    /* căn giữa tiêu đề nhưng cho phép nút loa nằm tuyệt đối bên phải */
}

.header h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

/* ---------- Volume button (loa) + popover ---------- */
.volume-wrap {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
}

.volume-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, transform 0.1s ease;
}

.volume-btn:hover {
    background: #F2F2F7;
}
.volume-btn:active {
    transform: scale(0.92);
}

.volume-icon {
    /* Chỉ set kích thước + màu; fill/stroke đã inline trong SVG nên
       kể cả khi CSS bị cache cũ, icon vẫn hiển thị đúng. */
    width: 22px;
    height: 22px;
    color: #000;
    display: block;
}

/* các sóng âm thanh ẩn/hiện theo mức volume (JS đổi class) */
.volume-icon .vi-wave1,
.volume-icon .vi-wave2,
.volume-icon .vi-mute {
    opacity: 0;
    transition: opacity 0.15s ease;
}
.volume-icon.is-low  .vi-wave1 { opacity: 1; }
.volume-icon.is-mid  .vi-wave1,
.volume-icon.is-mid  .vi-wave2 { opacity: 1; }
.volume-icon.is-high .vi-wave1,
.volume-icon.is-high .vi-wave2 { opacity: 1; }
.volume-icon.is-mute .vi-mute  { opacity: 1; }

/* Popover chứa thanh trượt dọc */
.volume-popover {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 56px;
    padding: 12px 8px 10px;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15), 0 2px 6px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 10;
    animation: popIn 0.15s ease-out;
}

/* Khi có thuộc tính [hidden] thì \u1ea9n h\u1eb3n (\u0111\u00e8 display:flex \u1edf tr\u00ean). */
.volume-popover[hidden] {
    display: none;
}

@keyframes popIn {
    from { opacity: 0; transform: translateY(-4px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.volume-percent {
    font-size: 12px;
    font-weight: 600;
    color: #555;
}

/* Slider dọc: dùng writing-mode (chuẩn) + fallback -webkit-appearance */
.volume-range-vertical {
    -webkit-appearance: slider-vertical; /* Safari/Chrome */
    appearance: slider-vertical;
    writing-mode: vertical-lr;
    direction: rtl;                       /* để trên = max, dưới = min */
    width: 8px;
    height: 140px;
    background: #E5E5EA;
    border-radius: 4px;
    outline: none;
    margin: 0;
}

.volume-range-vertical::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ffffff;
    border: 0.5px solid rgba(0,0,0,0.04);
    box-shadow: 0 2px 6px rgba(0,0,0,0.18), 0 1px 1px rgba(0,0,0,0.16);
    cursor: pointer;
}

.volume-range-vertical::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ffffff;
    border: 0.5px solid rgba(0,0,0,0.04);
    box-shadow: 0 2px 6px rgba(0,0,0,0.18), 0 1px 1px rgba(0,0,0,0.16);
    cursor: pointer;
}

/* ---------- Section chung ---------- */
.section {
    width: 100%;
    flex-shrink: 0;
}

.section-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
}

/* ============================================================
   TEMPO SLIDER
   ============================================================ */
.tempo-section {
    padding: 0;
}

/* Reset style mặc định của input range để chỉnh cho iOS */
#tempoRange {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: #E5E5EA;
    border-radius: 2px;
    outline: none;
    margin: 8px 0 6px;
}

/* thumb - webkit */
#tempoRange::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    border: 0.5px solid rgba(0,0,0,0.04);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15), 0 1px 1px rgba(0,0,0,0.16);
    cursor: pointer;
    transition: transform 0.1s ease;
}
#tempoRange::-webkit-slider-thumb:active {
    transform: scale(1.1);
}

/* thumb - firefox */
#tempoRange::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    border: 0.5px solid rgba(0,0,0,0.04);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15), 0 1px 1px rgba(0,0,0,0.16);
    cursor: pointer;
}

.tempo-value {
    text-align: center;
    font-size: 15px;
    color: #555;
    margin-top: 6px;
}

.tempo-value #tempoValue {
    font-weight: 600;
    color: #000;
}

/* ============================================================
   COUNT DISPLAY - SVG + số lớn ở giữa
   flex:1 để chiếm hết không gian còn lại và tự co giãn.
   min-height:0 quan trọng: cho phép flex item co lại nhỏ hơn
   nội dung của nó (nếu không sẽ tràn viewport).
   ============================================================ */
.count-section {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    flex: 1 1 0;
    min-height: 0;
}

.count-display {
    position: relative;
    /* Chiều cao lấp đầy phần section (co giãn theo flex),
       chiều rộng bằng chiều cao nhờ aspect-ratio -> luôn là hình vuông
       và không bao giờ tràn ra ngoài viewport. */
    height: 100%;
    aspect-ratio: 1 / 1;
    max-width: min(80vw, 340px);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* SVG progress ring */
.progress-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* xoay -90deg để bắt đầu vẽ từ vị trí 12h */
    transform: rotate(-90deg);
}

.progress-ring-bg {
    stroke: #F2F2F7;
}

.progress-ring-fg {
    stroke: #007AFF;
    /* Chu vi ~ 2*PI*100 = 628.318. JS sẽ tính chính xác dashoffset. */
    stroke-dasharray: 628.318;
    stroke-dashoffset: 628.318; /* mặc định ẩn hoàn toàn */
    transition: none; /* JS tự điều khiển bằng RAF, không cần CSS transition */
}

/* số đếm chính giữa - dùng clamp để tự co theo màn hình */
.count-number {
    position: relative;
    font-size: clamp(56px, 18vw, 104px);
    font-weight: 700;
    letter-spacing: -3px;
    color: #000;
    text-align: center;
    line-height: 1;
    /* để khi hiển thị chữ "Ready?" không bị nhảy layout */
    min-width: 100px;
}

/* khi hiển thị "Ready?" chữ nhỏ hơn */
.count-number.is-ready {
    font-size: clamp(32px, 10vw, 52px);
    letter-spacing: -1px;
    font-weight: 600;
    color: #333;
}

/* Ở trạng thái IDLE cho phép bấm để sửa - hint bằng con trỏ text */
.count-number.is-editable {
    cursor: text;
}

/* Input chỉnh số đếm - kế thừa cùng cỡ chữ với .count-number để không nhảy layout.
   Ẩn spinner mặc định của <input type="number">. */
.count-input {
    position: relative;
    font-family: inherit;
    font-size: clamp(56px, 18vw, 104px);
    font-weight: 700;
    letter-spacing: -3px;
    color: #000;
    text-align: center;
    line-height: 1;
    width: 100%;
    max-width: 220px;
    border: none;
    outline: none;
    background: transparent;
    padding: 0;
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: textfield;
    touch-action: manipulation;
}

.count-input::-webkit-outer-spin-button,
.count-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* dấu nháy đậm hơn cho iOS */
.count-input:focus {
    caret-color: #007AFF;
}

/* ============================================================
   COUNTER PILL ( - | + )
   ============================================================ */
.counter-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.counter-pill {
    display: flex;
    align-items: center;
    background: #F2F2F7;
    border-radius: 999px;
    overflow: hidden;
    width: 170px;
    height: 44px;
    position: relative;
    transition: opacity 0.2s ease;
}

.counter-pill.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.counter-btn {
    flex: 1;
    height: 100%;
    border: none;
    background: transparent;
    font-size: 24px;
    font-weight: 500;
    color: #000;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
    touch-action: manipulation;
}

.counter-btn:active {
    background: rgba(0,0,0,0.06);
}

.counter-divider {
    width: 1px;
    height: 24px;
    background: rgba(0,0,0,0.15);
}

/* ============================================================
   CONTROL BUTTONS (Start / Reset|Stop)
   ============================================================ */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding-top: 4px;
    flex-shrink: 0;
}

.control-btn {
    flex: 1;
    height: 48px;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 600;
    color: #ffffff;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.2s ease, opacity 0.2s ease;
    -webkit-appearance: none;
    touch-action: manipulation;
}

.control-btn:active {
    transform: scale(0.97);
}

/* Start (xanh lá) - dùng cho cả Start và Pause */
.btn-start {
    background: #34C759;
}

/* Reset (xám) - khi ở trạng thái nghỉ */
.btn-reset {
    background: #8E8E93;
}

/* Stop (đỏ) - khi đang chạy/pause */
.btn-stop {
    background: #FF3B30;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Màn hình rất thấp (landscape phone) - giảm gap và ẩn label bớt */
@media (max-height: 560px) {
    .app {
        gap: 8px;
        padding: 10px 16px 12px;
    }
    .header h1 {
        font-size: 20px;
    }
    .counter-pill {
        height: 40px;
        width: 150px;
    }
    .control-btn {
        height: 42px;
        font-size: 16px;
    }
}

/* desktop / tablet cao */
@media (min-width: 700px) and (min-height: 700px) {
    .app {
        padding: 32px 32px 36px;
        gap: 20px;
    }
    .header h1 {
        font-size: 32px;
    }
}
