* { box-sizing: border-box; margin: 0; }
:root { --font: 'Chewy', 'Comic Sans MS', cursive; --amber: #ff3b30; --ink: #2b1d17; --paper: #fff6d8; --gap: clamp(12px, 3.2vw, 44px); }
html[data-scene=sunny]  { --sky1: #7fcfff; --sky2: #def3ff; --sun: #ffd23f; --rays: 1; --cloud: #fff; --hill1: #7ed957; --hill2: #4fb848; --stars: 0; }
html[data-scene=sunset] { --sky1: #ff7e5f; --sky2: #ffd9a0; --sun: #ff5a36; --rays: 1; --cloud: #ffe9d6; --hill1: #c4cf5a; --hill2: #8fa83f; --stars: 0; }
html[data-scene=night]  { --sky1: #151c4d; --sky2: #4f4297; --sun: #fdf6d3; --rays: 0; --cloud: #8f96cf; --hill1: #2f7a68; --hill2: #1f5448; --stars: 1; }
body { font-family: var(--font); color: var(--ink); background: #def3ff; min-height: 100vh; -webkit-font-smoothing: antialiased; font-synthesis-weight: none; }

/* Crayon scene */
.scene { position: fixed; inset: 0; z-index: -2; background: linear-gradient(var(--sky1), var(--sky2)); }
.scene svg { width: 100%; height: 100%; display: block; }
.sun { fill: var(--sun); transform-box: fill-box; transform-origin: center; animation: bob 6s ease-in-out infinite; }
.rays { opacity: var(--rays); transform-box: view-box; transform-origin: 650px 150px; animation: spin 40s linear infinite; }
.rays line { stroke: var(--sun); stroke-width: 9; }
.cloud { fill: var(--cloud); } .cg { animation: drift 14s ease-in-out infinite alternate; }
.hill1 { fill: var(--hill1); } .hill2 { fill: var(--hill2); }
.stem { stroke-width: 5; } .fl { fill: var(--amber); }
.stars { opacity: var(--stars); transition: opacity .6s; } .stars circle { animation: twinkle 3s ease-in-out infinite; }
body::after { content: ""; position: fixed; inset: 0; z-index: 4; pointer-events: none; opacity: .14; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.6'/%3E%3C/svg%3E"); }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; }

/* Top bar (sticker buttons) */
.top { position: fixed; inset: 0 0 auto 0; z-index: 5; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; padding: max(14px, env(safe-area-inset-top)) 16px 0; }
.right { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; align-items: flex-start; }
.dd { position: relative; }
.chip { font-family: var(--font); font-size: 1.05rem; color: var(--ink); cursor: pointer; padding: 8px 16px; background: var(--paper);
  border: 2.5px solid var(--ink); border-radius: 99px; box-shadow: 3px 3px 0 var(--ink); transition: transform .12s, box-shadow .12s; }
.chip:hover { transform: translate(-1px, -1px) rotate(-1deg); box-shadow: 4px 4px 0 var(--ink); }
.chip:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.menu { position: absolute; top: calc(100% + 10px); left: 0; min-width: 210px; list-style: none; padding: 6px; background: var(--paper);
  border: 3px solid var(--ink); border-radius: 20px; box-shadow: 5px 5px 0 var(--ink); }
.dd.r .menu { left: auto; right: 0; }
.menu[hidden] { display: none; }
.menu button { width: 100%; text-align: left; font-family: var(--font); font-size: 1.1rem; color: var(--ink); background: none; border: 0; border-radius: 12px; padding: 9px 14px; cursor: pointer; }
.menu button:hover, .menu button[aria-checked=true] { background: color-mix(in srgb, var(--amber) 28%, transparent); }
.sep { height: 2px; background: var(--ink); opacity: .25; margin: 6px 4px; }
.grp { padding: 8px 14px 2px; font-size: .95rem; opacity: .7; }
.sw, .opts { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 14px 10px; }
.menu .sw button { width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 2.5px solid var(--ink); background: var(--c); }
.menu .sw button[aria-checked=true] { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink); background: var(--c); }
.menu .opts button { width: auto; padding: 5px 14px; font-size: 1rem; border: 2px solid var(--ink); border-radius: 99px; }

/* Title-card layout */
main { min-height: 100vh; width: 100%; max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 80px 16px 30px; }
.sticker { background: var(--paper); color: var(--ink); border: 2.5px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); }
#status { display: inline-flex; align-items: center; gap: 8px; padding: 3px 14px; font-size: 0.95rem; letter-spacing: .05em; border-radius: 99px;
  background: var(--paper); border: 2.5px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); }
#status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--amber); border: 2px solid var(--ink); animation: pulse 2s ease-out infinite; }
#targetLabel { display: inline-block; margin: 10px 0 14px; padding: 5px 16px; font-size: clamp(1rem, 2.2vw, 1.35rem); line-height: 1.15; border-radius: 14px;
  background: var(--paper); border: 2.5px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); transform: rotate(-1deg); }
.clock { display: flex; gap: var(--gap); }
.unit { position: relative; display: flex; flex-direction: column; align-items: center; font-size: clamp(2rem, 6vw, 4.4rem); }
.num { display: block; font-size: 1em; font-weight: 600; line-height: .95; color: #fffbe8; font-variant-numeric: lining-nums tabular-nums;
  -webkit-text-stroke: .08em var(--ink); paint-order: stroke fill; text-shadow: .05em .06em 0 var(--ink); transition: transform .25s ease, opacity .25s ease; }
.num.tick { transform: translateY(-6px) rotate(-3deg); opacity: .3; }
#s { color: var(--amber); }
.unit small { display: inline-block; margin-top: 8px; padding: 1px 10px; font-size: clamp(.72rem, 1.2vw, .88rem); letter-spacing: .04em; color: var(--ink);
  background: var(--paper); border: 2px solid var(--ink); border-radius: 99px; box-shadow: 2px 2px 0 var(--ink); }
.unit:not(:last-child)::after { content: ":"; position: absolute; left: 100%; top: .06em; width: var(--gap); text-align: center; line-height: .95; font-size: .6em;
  color: #fffbe8; -webkit-text-stroke: .1em var(--ink); paint-order: stroke fill; animation: blink 1s steps(1) infinite; }

/* Timeline strip */
.timeline { width: 100%; margin-top: 16px; padding: 10px 14px 10px; border-radius: 16px; background: var(--paper); border: 2.5px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.progress { position: relative; height: 14px; background: #fff; border: 2.5px solid var(--ink); border-radius: 99px; }
.progress i { position: absolute; left: -2px; top: -2px; height: calc(100% + 4px); width: 0; min-width: 18px; background: var(--amber); border: 2.5px solid var(--ink); border-radius: 99px; transition: width .6s ease; }
.ends { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 1rem; }
#notifState { margin-top: 20px; padding: 6px 14px; font-size: .95rem; line-height: 1.35; max-width: 440px; border-radius: 14px; background: var(--paper); border: 2px solid var(--ink); }
.link { font: inherit; color: var(--ink); background: none; border: 0; text-decoration: underline wavy; cursor: pointer; padding: 0; }

/* Motion */
#status, #targetLabel, .unit, .timeline, #notifState { animation: rise .8s cubic-bezier(.3,1.5,.5,1) both; }
#targetLabel { animation-delay: .08s; }
.unit:nth-child(1) { animation-delay: .16s; } .unit:nth-child(2) { animation-delay: .24s; } .unit:nth-child(3) { animation-delay: .32s; } .unit:nth-child(4) { animation-delay: .4s; }
.timeline { animation-delay: .5s; } #notifState { animation-delay: .6s; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.96); } }
@keyframes blink { 50% { opacity: .15; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--amber) 70%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }
@keyframes bob { 50% { transform: translateY(8px) scale(1.03); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes drift { to { transform: translateX(34px); } }
@keyframes twinkle { 50% { opacity: .2; } }
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
@media (max-width: 560px) { .unit small { padding: 0 8px; font-size: .72rem; letter-spacing: 0; } }
@media (max-width: 420px) { .chip { padding: 7px 12px; font-size: 1rem; } .top { padding-left: 10px; padding-right: 10px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Background Image Layer */
.bg-image-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-size: cover;
  background-position: center 30%;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.6s ease;
}

body.has-custom-bg .scene {
  opacity: 0;
  transition: opacity 0.6s ease;
}

body.has-custom-bg .bg-image-layer {
  opacity: 1;
}

/* Glassmorphism Frosted Timer Area (Compact & Balanced) */
.timer-glass-card {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  background: rgba(255, 246, 216, 0.45);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 2.5px solid var(--ink);
  border-radius: 24px;
  padding: clamp(16px, 2.5vw, 24px);
  box-shadow: 4px 4px 0 var(--ink), 0 20px 45px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  animation: rise .8s cubic-bezier(.3,1.5,.5,1) both;
}

body.has-custom-bg .timer-glass-card {
  background: rgba(18, 22, 18, 0.56);
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55), 0 0 20px rgba(255, 255, 255, 0.08);
}

body.has-custom-bg .timer-glass-card #status,
body.has-custom-bg .timer-glass-card #targetLabel,
body.has-custom-bg .timer-glass-card .timeline,
body.has-custom-bg .timer-glass-card .unit small,
body.has-custom-bg .timer-glass-card #notifState {
  background: rgba(255, 246, 216, 0.88);
  backdrop-filter: blur(10px);
}
