/* ============================================================
   Tick Tock - two countdown timers
   ============================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    color: #fff;
    background: #111;
    user-select: none;
    -webkit-user-select: none;
}

.stage {
    position: fixed;
    inset: 0;
    cursor: pointer;
}

/* ---------- controls (shared by every theme) ---------- */
.fades { transition: opacity .6s, transform .6s; }

body.idle .fades {
    opacity: 0;
    pointer-events: none;
}

body.idle { cursor: none; }
body.idle .controls { transform: translate(-50%, 20px); }

.home-link {
    position: fixed;
    top: 16px;
    left: 18px;
    z-index: 10;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .5px;
    color: rgba(255, 255, 255, .7);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(10, 10, 20, .25);
    backdrop-filter: blur(8px);
}

.home-link:hover { color: #fff; }

.controls {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 14px;
    width: max-content;
    max-width: calc(100vw - 24px);
    padding: 10px 14px;
    border-radius: 22px;
    background: rgba(14, 14, 24, .42);
    border: 1px solid rgba(255, 255, 255, .12);
    backdrop-filter: blur(16px) saturate(1.3);
    -webkit-backdrop-filter: blur(16px) saturate(1.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}

.controls button,
.done button {
    font: inherit;
    color: inherit;
    border: 0;
    cursor: pointer;
}

.seg {
    display: flex;
    padding: 3px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .08);
}

.seg button {
    background: none;
    font-size: 14px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 9px;
    color: rgba(255, 255, 255, .7);
}

.seg button.on { background: rgba(255, 255, 255, .92); color: #15151f; }

.presets { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }

.chip {
    background: rgba(255, 255, 255, .08);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 9px;
    min-width: 38px;
}

.chip:hover { background: rgba(255, 255, 255, .16); }
.chip.on { background: rgba(255, 255, 255, .28); }

.setter, .actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .08);
    font-size: 17px;
    line-height: 1;
    display: grid;
    place-items: center;
}

.icon-btn svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-btn:hover { background: rgba(255, 255, 255, .16); }
.icon-btn.off { opacity: .6; }

.time-input {
    width: 86px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .16);
    background: rgba(0, 0, 0, .2);
    color: #fff;
    font: 600 17px 'Inter', sans-serif;
    font-variant-numeric: tabular-nums;
    text-align: center;
    outline: 0;
    user-select: text;
}

.time-input:focus { border-color: rgba(255, 255, 255, .6); }

.main-btn {
    min-width: 104px;
    height: 40px;
    padding: 0 18px;
    border-radius: 12px;
    background: #fff;
    color: #15151f !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    letter-spacing: .3px;
    transition: transform .1s;
}

.main-btn:active { transform: scale(.96); }
.main-btn.running { background: rgba(255, 255, 255, .2); color: #fff !important; }

/* ---------- done ---------- */
.done {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    max-width: calc(100vw - 24px);
    animation: fadeIn .5s ease-out;
}

.done[hidden] { display: none; }

.done-card {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 16px;
    padding: 10px 12px 10px 22px;
    border-radius: 22px;
    background: rgba(20, 20, 32, .55);
    border: 1px solid rgba(255, 255, 255, .15);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
    animation: drop .6s cubic-bezier(.2, 1.4, .4, 1);
}

.done-title { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.done-sub { opacity: .7; font-size: 15px; }
.done-row { display: flex; gap: 8px; }

.ghost-btn {
    height: 40px;
    padding: 0 22px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .12);
    font-weight: 600;
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes drop { from { transform: translateY(-30px) scale(.9); opacity: 0; } }

/* ============================================================
   SAND
   ============================================================ */
body[data-theme="sand"] { background: #140f1c; }

.sand {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2vh;
    padding-bottom: var(--ctrl-h, 120px);
    background:
        radial-gradient(ellipse 50% 45% at 50% 42%, rgba(255, 190, 110, .16), transparent 70%),
        radial-gradient(ellipse at 50% 120%, #3a2318 0%, transparent 55%),
        linear-gradient(#1c1528, #120d18);
}

.sand-glass {
    filter: drop-shadow(0 30px 40px rgba(0, 0, 0, .5));
}

.sand-glass canvas { display: block; }

.sand-glass.turn { animation: turn 1s cubic-bezier(.6, 0, .25, 1); }

@keyframes turn {
    from { transform: rotate(-180deg); }
}

.sand-time {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 600;
    font-size: clamp(40px, 8vh, 84px);
    line-height: 1;
    letter-spacing: 2px;
    color: #f6dcae;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 30px rgba(255, 190, 110, .35);
}

.sand.finished .sand-time { animation: glowPulse 1.6s ease-in-out infinite; }

@keyframes glowPulse {
    50% { text-shadow: 0 0 50px rgba(255, 200, 120, .9); color: #fff3d8; }
}

/* ============================================================
   FLIP
   ============================================================ */
body[data-theme="flip"] { background: #0c0c0e; }

.flip {
    --h: min(34vh, 21vw, calc((100vh - var(--ctrl-h, 120px)) * .55));
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5vh;
    padding-bottom: var(--ctrl-h, 120px);
    background: radial-gradient(ellipse at 50% 40%, #222226 0%, #0c0c0e 70%);
}

.flap-row { display: flex; align-items: center; gap: calc(var(--h) * .1); }
.flap-group { display: flex; gap: calc(var(--h) * .06); }

.flap {
    position: relative;
    width: calc(var(--h) * .7);
    height: var(--h);
    perspective: calc(var(--h) * 4);
    font-family: 'Bebas Neue', 'Oswald', sans-serif;
    font-size: calc(var(--h) * .92);
    color: #eeeae2;
    border-radius: calc(var(--h) * .07);
    box-shadow: 0 calc(var(--h) * .05) calc(var(--h) * .12) rgba(0, 0, 0, .6);
}

.half {
    position: absolute;
    left: 0;
    right: 0;
    height: 50%;
    overflow: hidden;
    background: linear-gradient(#2a2a2e, #222225);
}

.half span {
    display: block;
    height: var(--h);
    line-height: calc(var(--h) * 1.06);
    text-align: center;
}

.half.top {
    top: 0;
    border-radius: calc(var(--h) * .07) calc(var(--h) * .07) 0 0;
    border-bottom: 1px solid rgba(0, 0, 0, .7);
}

.half.bottom {
    bottom: 0;
    border-radius: 0 0 calc(var(--h) * .07) calc(var(--h) * .07);
    background: linear-gradient(#202023, #1a1a1d);
}

.half.bottom span { transform: translateY(-50%); }

.leaf {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    transform-origin: 50% 100%;
    transform-style: preserve-3d;
    visibility: hidden;
    z-index: 2;
}

.leaf .half { height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.leaf .front { top: 0; }
.leaf .back { top: 0; bottom: auto; transform: rotateX(180deg); border-radius: 0 0 calc(var(--h) * .07) calc(var(--h) * .07); }

.flap.flipping .leaf { visibility: visible; animation: flap .6s cubic-bezier(.45, .05, .55, .95) forwards; }

/* a shadow falls over the bottom half as the flap comes down */
.flap.flipping .half.bottom:not(.back)::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(rgba(0, 0, 0, .55), rgba(0, 0, 0, 0));
    animation: shade .6s ease-in forwards;
}

@keyframes flap {
    to { transform: rotateX(-180deg); }
}

@keyframes shade {
    from { opacity: 0; }
    60% { opacity: 1; }
    to { opacity: 0; }
}

.colon {
    display: flex;
    flex-direction: column;
    gap: calc(var(--h) * .22);
}

.colon i {
    width: calc(var(--h) * .07);
    height: calc(var(--h) * .07);
    border-radius: 50%;
    background: #ff6a3d;
    box-shadow: 0 0 14px rgba(255, 106, 61, .6);
}

body.is-running .flip .colon i { animation: blink 1s steps(1) infinite; }

@keyframes blink { 50% { opacity: .25; } }

.flip-track {
    width: min(70vw, calc(var(--h) * 4.6));
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, .08);
    overflow: hidden;
}

.flip-bar {
    height: 100%;
    background: linear-gradient(90deg, #ff9a3d, #ff4f5e);
    transform-origin: left;
    box-shadow: 0 0 12px rgba(255, 106, 61, .7);
}

.flip.paused .flap-row { opacity: .6; }
.flip.finished .flap { color: #ff6a3d; animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 50% { color: #ffd2bd; } }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
    .controls { bottom: 10px; padding: 10px; gap: 8px; }
    .presets .chip { padding: 5px 8px; }
    .flip { --h: min(30vh, 19vw); }
}

@media (prefers-reduced-motion: reduce) {
    .sand-glass.turn, .flap.flipping .leaf { animation: none; }
}
