:root {
    --theme-color: #b94047;
    --bg-color: #050505;
    --text-color: #f3f3f3;
    --sub-text: rgba(255,255,255,0.38);
    --sub-text-strong: rgba(255,255,255,0.58);
    --border-color: rgba(255,255,255,0.14);
    --panel-bg: rgba(255,255,255,0.03);
    --shadow-color: rgba(0,0,0,0.28);
}

body.light-mode {
    --bg-color: #e8e8e8;
    --text-color: #191919;
    --sub-text: rgba(0,0,0,0.34);
    --sub-text-strong: rgba(0,0,0,0.58);
    --border-color: rgba(0,0,0,0.10);
    --panel-bg: rgba(0,0,0,0.025);
    --shadow-color: rgba(0,0,0,0.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100dvh;
    overflow: hidden;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: 'M PLUS 1p', 'Barlow Condensed', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.8s ease, color 0.8s ease;
}

@media (pointer: coarse) {
    html, body {
        overflow-y: auto;
        overscroll-behavior-y: auto;
    }
}

body {
    position: relative;
}

/* ── もっちりバウンスアニメーション ── */
@keyframes squish-round {
    0%   { transform: scale(1); }
    20%  { transform: scale(0.93, 1.06); }
    42%  { transform: scale(1.06, 0.95); }
    60%  { transform: scale(0.97, 1.03); }
    76%  { transform: scale(1.02, 0.99); }
    88%  { transform: scale(0.99, 1.01); }
    100% { transform: scale(1); }
}

@keyframes squish-dot {
    0%   { transform: scale(1); }
    22%  { transform: scale(0.84); }
    48%  { transform: scale(1.14); }
    66%  { transform: scale(0.95); }
    82%  { transform: scale(1.04); }
    100% { transform: scale(1); }
}

@keyframes squish-icon {
    0%   { transform: scale(1); }
    20%  { transform: scale(0.91, 1.08); }
    42%  { transform: scale(1.08, 0.93); }
    60%  { transform: scale(0.97, 1.03); }
    76%  { transform: scale(1.02, 0.99); }
    100% { transform: scale(1); }
}

.squish-bounce {
    animation: squish-round 0.56s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.squish-dot-bounce {
    animation: squish-dot 0.52s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.squish-icon-bounce {
    animation: squish-icon 0.60s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

button {
    border: none;
    background: none;
    color: var(--sub-text);
    cursor: pointer;
    transition:
        color 0.28s ease,
        background-color 0.28s ease,
        border-color 0.28s ease,
        transform 0.22s ease,
        opacity 0.28s ease;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}

button:hover {
    color: var(--text-color);
}

button:disabled {
    opacity: 0.35;
    pointer-events: none;
}

#particleCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
}

.zen-mode #particleCanvas {
    opacity: 1;
}

.ambient-glow {
    position: fixed;
    inset: -20%;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.2s ease;
    background:
        radial-gradient(circle at 50% 43%, color-mix(in srgb, var(--theme-color) 5%, transparent) 0%, transparent 18%),
        radial-gradient(circle at 50% 43%, color-mix(in srgb, var(--theme-color) 3%, transparent) 22%, transparent 34%);
    filter: blur(22px);
}

.zen-mode .ambient-glow {
    opacity: 1;
}

.top-left-status {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 26px);
    left: 28px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 14px;
    pointer-events: none;
}

.wake-indicator,
.top-status {
    position: static;
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 0.14em;
    color: var(--sub-text);
}

.wake-indicator {
    opacity: 0;
    transition: opacity 0.35s ease;
}

.wake-indicator.show {
    opacity: 1;
}

.top-status {
    opacity: 1;
}

.status-text.on,
.top-status.on {
    color: var(--text-color);
}

.status-text.overtime-status,
.top-status.overtime-status,
.status-text.on.overtime-status,
.top-status.on.overtime-status {
    color: #ff453a !important;
}

.overtime-icon {
    display: inline-block;
    font-size: 0.72em;
    width: 0;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.6);
    transition:
        width 0.3s ease,
        opacity 0.3s ease,
        transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    vertical-align: middle;
    line-height: 1;
    white-space: nowrap;
    color: #ff453a;
}

.overtime-status .overtime-icon {
    width: 1.1em;
    opacity: 1;
    transform: scale(1);
}

.top-right-controls {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 26px);
    right: 28px;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 26px;
    max-width: calc(100vw - 56px);
    flex-wrap: wrap;
}

.mode-toggle {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.84rem;
    letter-spacing: 0.2em;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 999px;
    white-space: nowrap;
    background: var(--panel-bg);
    box-shadow: 0 8px 24px var(--shadow-color);
}

.mode-toggle:hover {
    border-color: var(--sub-text-strong);
}

.color-selector {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.color-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid transparent;
    opacity: 0.97;
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.08) inset,
        0 4px 14px rgba(0,0,0,0.16);
}

.light-mode .color-dot {
    box-shadow:
        0 0 0 1px rgba(0,0,0,0.08) inset,
        0 4px 14px rgba(0,0,0,0.10);
}

.color-dot:hover {
    transform: scale(1.12);
}

.color-dot.active {
    transform: scale(1.18);
    border-color: transparent;
    box-shadow:
        0 0 0 2px rgba(255,255,255,0.08),
        0 0 0 3.5px rgba(255,255,255,0.55);
}

.light-mode .color-dot.active {
    box-shadow:
        0 0 0 2px rgba(0,0,0,0.04),
        0 0 0 3.5px rgba(0,0,0,0.32);
}

.container {
    position: relative;
    z-index: 10;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding:
        calc(env(safe-area-inset-top, 0px) + 112px)
        24px
        calc(env(safe-area-inset-bottom, 0px) + 112px);
}

.timer-wrap {
    min-height: 34vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.timer {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: clamp(5.5rem, 19.6vw, 13rem);
    font-weight: 300;
    letter-spacing: -0.045em;
    line-height: 0.9;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: baseline;
    justify-content: center;
    white-space: nowrap;
    margin: 0;
    transform-origin: center center;
    transition:
        color 0.9s ease,
        text-shadow 0.9s ease,
        transform 0.6s ease;
}

.zen-mode .timer {
    color: var(--theme-color);
    text-shadow:
        0 0 10px color-mix(in srgb, var(--theme-color) 10%, transparent),
        0 0 22px color-mix(in srgb, var(--theme-color) 4%, transparent);
    transform: scale(1.03);
}

.colon {
    display: inline-block;
    transform: translateY(-0.11em);
    margin: 0 0.045em;
}

.ms-part {
    font-size: clamp(2.35rem, 6.2vw, 5rem);
    margin-left: 0.13em;
    opacity: 0.48;
    letter-spacing: -0.015em;
}

.ms-part span {
    letter-spacing: 0.01em;
}

.hide-ms .ms-part {
    display: none;
}

.controls-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-top: 2rem;
    transition: opacity 0.85s ease, transform 0.85s ease;
}

.presets {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.preset-row {
    display: flex;
    justify-content: center;
    gap: 18px;
    flex-wrap: wrap;
}

.preset-btn {
    min-width: 42px;
    font-size: 1.28rem;
    font-family: 'Barlow Condensed', sans-serif;
    line-height: 1;
    color: var(--sub-text);
}

.preset-btn:hover {
    color: color-mix(in srgb, var(--theme-color) 55%, var(--sub-text-strong));
}

.preset-btn.active {
    color: var(--theme-color);
    border-bottom: 1px solid var(--theme-color);
}

.increments {
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.inc-btn {
    font-size: 0.98rem;
    letter-spacing: 0.08em;
    font-family: 'Barlow Condensed', sans-serif;
    color: var(--sub-text);
}

.inc-btn:hover {
    color: var(--sub-text-strong);
}

.start-btn {
    margin-top: 1.8rem;
    min-width: 260px;
    padding: 13px 64px;
    background: var(--theme-color);
    border: 1px solid var(--theme-color);
    border-radius: 999px;
    color: #fff;
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1.08rem;
    font-weight: 400;
    letter-spacing: 0.42em;
    text-transform: uppercase;
    box-shadow: 0 12px 30px color-mix(in srgb, var(--theme-color) 20%, transparent);
}

.start-btn:hover {
    color: #fff;
    opacity: 0.95;
    transform: translateY(-1px);
}

.zen-controls {
    position: absolute;
    left: 50%;
    bottom: 16%;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    gap: 34px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

.zen-mode:hover .zen-controls,
.zen-mode.show-zen-controls .zen-controls {
    opacity: 1;
    pointer-events: auto;
}

.icon-btn {
    width: 112px;
    height: 112px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    background: rgba(255,255,255,0.015);
    box-shadow: 0 16px 32px rgba(0,0,0,0.22);
    backdrop-filter: blur(2px);
}

.light-mode .icon-btn {
    background: rgba(255,255,255,0.28);
}

.icon-btn .material-icons-round {
    font-size: 2.3rem;
}

#pauseBtn:hover {
    background: color-mix(in srgb, var(--theme-color) 12%, transparent);
    border-color: color-mix(in srgb, var(--theme-color) 50%, var(--border-color));
}

.reset-btn:hover {
    background: rgba(255,255,255,0.05);
    border-color: var(--sub-text-strong);
}

.bottom-left-nav {
    position: absolute;
    left: 28px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
    z-index: 100;
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
    max-width: calc(100vw - 56px);
}

.permanent-controls {
    position: absolute;
    right: 28px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
    z-index: 100;
}

.nav-btn,
.permanent-controls button,
.status-text {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1rem;
    letter-spacing: 0.1em;
    white-space: nowrap;
}

.nav-btn.on,
.status-text.on {
    color: var(--text-color);
}

.status-text {
    color: var(--sub-text);
}

.progress-container {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 5px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.8s ease;
    background: transparent;
}

.progress-track {
    position: absolute;
    inset: 0;
    background: var(--border-color);
}

.progress-bar {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--theme-color);
    transition: width 0.08s linear;
    box-shadow: 0 0 10px color-mix(in srgb, var(--theme-color) 35%, transparent);
}

.zen-mode .progress-container {
    opacity: 1;
}

.hide-on-zen {
    transition: opacity 0.85s ease, transform 0.85s ease;
}

.zen-mode .hide-on-zen {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}

@media (pointer: coarse) {
    .permanent-controls {
        display: none;
    }
}

@media (max-width: 1024px) {
    .container {
        padding:
            calc(env(safe-area-inset-top, 0px) + 98px)
            20px
            calc(env(safe-area-inset-bottom, 0px) + 98px);
    }

    .top-right-controls {
        top: calc(env(safe-area-inset-top, 0px) + 20px);
        right: 20px;
        max-width: calc(100vw - 40px);
        gap: 22px;
    }

    .bottom-left-nav {
        left: 20px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
        gap: 18px;
        max-width: calc(100vw - 40px);
    }

    .permanent-controls {
        right: 20px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
    }

    .top-left-status {
        top: calc(env(safe-area-inset-top, 0px) + 22px);
        left: 20px;
    }

    .timer {
        font-size: clamp(5.3rem, 20vw, 11rem);
    }

    .icon-btn {
        width: 94px;
        height: 94px;
    }
}

@media (max-width: 600px) {
    .container {
        padding:
            calc(env(safe-area-inset-top, 0px) + 84px)
            16px
            calc(env(safe-area-inset-bottom, 0px) + 120px);
        justify-content: flex-start;
    }

    .top-right-controls {
        top: calc(env(safe-area-inset-top, 0px) + 16px);
        right: 16px;
        left: 16px;
        max-width: none;
        gap: 14px;
        flex-direction: column;
        align-items: flex-end;
    }

    .top-left-status {
        top: calc(env(safe-area-inset-top, 0px) + 16px);
        left: 16px;
        gap: 10px;
    }

    .wake-indicator,
    .top-status {
        font-size: 0.8rem;
        letter-spacing: 0.12em;
    }

    .color-selector {
        gap: 11px;
    }

    .color-dot {
        width: 19px;
        height: 19px;
    }

    .timer-wrap {
        min-height: 24vh;
        margin-top: 110px;
    }

    .timer {
        font-size: clamp(6.4rem, 25.8vw, 9.6rem);
        letter-spacing: -0.055em;
    }

    .zen-mode .timer {
        transform: scale(1.04);
    }

    .ms-part {
        font-size: clamp(2.3rem, 7.5vw, 3.7rem);
    }

    .preset-row {
        gap: 12px;
    }

    .preset-btn {
        min-width: 38px;
        font-size: 1.18rem;
    }

    .increments {
        gap: 12px;
    }

    .inc-btn {
        font-size: 0.92rem;
    }

    .start-btn {
        min-width: 230px;
        padding: 12px 48px;
        margin-top: 1.2rem;
    }

    .bottom-left-nav {
        left: 16px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 56px);
        gap: 14px;
        max-width: calc(100vw - 32px);
    }

    .zen-controls {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 110px);
        gap: 22px;
    }

    .icon-btn {
        width: 74px;
        height: 74px;
    }

    .icon-btn .material-icons-round {
        font-size: 1.8rem;
    }

    .progress-container {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 44px);
    }
}

@media (orientation: landscape) and (max-height: 700px) {
    .container {
        padding:
            calc(env(safe-area-inset-top, 0px) + 70px)
            18px
            calc(env(safe-area-inset-bottom, 0px) + 68px);
    }

    .top-right-controls {
        top: calc(env(safe-area-inset-top, 0px) + 14px);
        right: 16px;
        left: auto;
        max-width: calc(100vw - 32px);
        gap: 18px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
    }

    .top-left-status {
        top: calc(env(safe-area-inset-top, 0px) + 16px);
        left: 16px;
    }

    .timer-wrap {
        min-height: 28vh;
        margin-top: 0;
    }

    .timer {
        font-size: clamp(4.4rem, 13vw, 9rem);
    }

    .ms-part {
        font-size: clamp(1.9rem, 4.2vw, 3.2rem);
    }

    .controls-group {
        margin-top: 1rem;
        gap: 12px;
    }

    .presets {
        gap: 9px;
    }

    .preset-row {
        gap: 11px;
    }

    .increments {
        gap: 14px;
    }

    .start-btn {
        min-width: 220px;
        padding: 10px 36px;
        margin-top: 0.9rem;
    }

    .bottom-left-nav {
        left: 16px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
        gap: 16px;
        max-width: calc(100vw - 32px);
    }

    .permanent-controls {
        right: 16px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    }

    .zen-controls {
        bottom: 10%;
        gap: 18px;
    }

    .icon-btn {
        width: 72px;
        height: 72px;
    }

    .icon-btn .material-icons-round {
        font-size: 1.7rem;
    }

    .progress-container {
        bottom: 0;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .timer {
        font-size: clamp(3.8rem, 11.8vw, 7.2rem);
    }

    .preset-btn {
        font-size: 1rem;
    }

    .inc-btn,
    .nav-btn,
    .permanent-controls button,
    .status-text,
    .mode-toggle {
        font-size: 0.88rem;
    }

    .color-dot {
        width: 16px;
        height: 16px;
    }

    .start-btn {
        min-width: 190px;
        padding: 8px 26px;
        font-size: 0.94rem;
    }
}

.timer.overtime {
    color: #ff453a;
    text-shadow:
        0 0 12px rgba(255, 69, 58, 0.30),
        0 0 26px rgba(255, 69, 58, 0.18);
}

.progress-bar {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--theme-color);
    transition: width 0.08s linear;
    box-shadow: 0 0 10px color-mix(in srgb, var(--theme-color) 35%, transparent);
    overflow: hidden;
}

.progress-bar::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(
            -45deg,
            rgba(255,255,255,0.10) 0 8px,
            rgba(255,255,255,0.02) 8px 16px
        );
    opacity: 0.45;
    pointer-events: none;
}

.progress-bar.overtime {
    background: #ff453a;
    box-shadow: 0 0 12px rgba(255, 69, 58, 0.28);
}

@keyframes stripe-slide {
    from { background-position: 0 0; }
    to   { background-position: 22.6px 0; }
}

.progress-bar.overtime::after {
    background:
        repeating-linear-gradient(
            -45deg,
            rgba(255,255,255,0.22) 0 8px,
            rgba(255,255,255,0.05) 8px 16px
        );
    background-size: 22.6px 22.6px;
    opacity: 0.9;
    animation: stripe-slide 0.6s linear infinite;
}
