*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --sky1: #56CCF2;
  --sky2: #BDE0FE;
  --accent: #FF4757;
  --accent2: #FF6B81;
  --green: #2ED573;
  --blue: #1E90FF;
  --purple: #A855F7;
  --orange: #F59E0B;
  --pink: #F472B6;
  --text: #2D2D44;
  --text-dim: #636E8A;
  --ring-color: #FF4757;
  --shadow: rgba(0,0,0,0.04);
}

html, body {
  height: 100%; width: 100%; overflow: hidden;
  background: linear-gradient(170deg, var(--sky1) 0%, var(--sky2) 45%, #E2F0CB 100%);
  color: var(--text);
  font-family: 'Rounded Mplus 1c', -apple-system, 'SF Pro Rounded', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}

/* === Floating decorations === */
.bg-deco {
  position: fixed; pointer-events: none; z-index: 0;
  animation: float 6s ease-in-out infinite;
  opacity: 0.55;
}
.bg-deco:nth-child(1) { top: 4%; left: 4%; animation-delay: 0s; font-size: 56px; }
.bg-deco:nth-child(2) { top: 10%; right: 5%; animation-delay: 1.2s; font-size: 38px; }
.bg-deco:nth-child(3) { bottom: 18%; left: 2%; animation-delay: 2.8s; font-size: 44px; }
.bg-deco:nth-child(4) { bottom: 8%; right: 4%; animation-delay: 0.6s; font-size: 32px; }
.bg-deco:nth-child(5) { top: 45%; left: 1%; animation-delay: 2s; font-size: 28px; }
.bg-deco:nth-child(6) { top: 35%; right: 1%; animation-delay: 3.6s; font-size: 34px; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-16px) rotate(10deg); }
}

/* === Ground === */
.ground {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 44px;
  background: linear-gradient(180deg, #7DCE94, #4CAF50);
  border-radius: 100% 100% 0 0 / 20px 20px 0 0;
  z-index: 0;
}

/* === App layout === */
.app {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; width: 100%;
  padding: 18px 24px 64px; gap: 14px;
}

/* === Header === */
.header {
  display: flex; justify-content: center; align-items: center;
  width: 100%; max-width: 400px; padding: 0;
}

.header h1 {
  font-size: 32px; font-weight: 900; letter-spacing: 0;
  padding: 5px 22px 5px 14px;
  border-radius: 28px;
  background-color: rgba(255,255,255,0.92);
  backdrop-filter: blur(6px);
  border: 3px solid rgba(255,71,87,0.35);
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  color: transparent;
  background-image: linear-gradient(135deg, #ff6b6b, #f0b84a, #6bde7e, #6ac0f5, #b88ae8);
  -webkit-background-clip: text; background-clip: text;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}

.header h1::before { content: '⏱'; font-size: 26px; }
.header h1::after { content: '✨'; font-size: 15px; animation: twinkle 1.4s ease-in-out infinite; }

@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1) rotate(0deg); }
  50% { opacity: 0.55; transform: scale(0.7) rotate(25deg); }
}


/* === Home button === */
.home-btn {
  position: fixed; top: 18px; left: 22px; z-index: 20;
  background: rgba(255,255,255,0.8);
  border: 2px solid rgba(255,255,255,0.5);
  color: var(--text-dim);
  font-size: 18px; font-weight: 800;
  padding: 4px 12px; border-radius: 18px;
  cursor: pointer; font-family: inherit;
  text-decoration: none; line-height: 1.4;
  transition: all 0.15s;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.home-btn:hover {
  transform: scale(1.06);
  background: rgba(255,255,255,0.92);
  border-color: var(--accent2);
  color: var(--accent);
}

/* === Header action buttons (fixed top) === */
.header-actions {
  position: fixed; top: 18px; right: 22px; z-index: 20;
  display: flex; gap: 6px;
}
.header-btn {
  background: rgba(255,255,255,0.8);
  border: 2px solid rgba(255,255,255,0.5);
  color: var(--text-dim);
  font-size: 12px; font-weight: 800;
  padding: 6px 14px; border-radius: 18px;
  cursor: pointer; font-family: inherit;
  transition: all 0.15s;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  line-height: 1;
}
.header-btn:hover {
  transform: scale(1.06) rotate(-3deg);
  background: rgba(255,255,255,0.92);
  border-color: var(--accent2);
  color: var(--accent);
}
.header-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(255,71,87,0.5);
  transform: scale(1.1);
}

/* === Ring === */
.ring-container {
  position: relative;
  width: min(62vw, 260px); height: min(62vw, 260px);
  flex-shrink: 0;
}

.ring-container.ring-large {
  width: min(78vw, 340px); height: min(78vw, 340px);
}

.ring-container::before {
  content: ''; position: absolute;
  inset: -10px;
  border: 3px dashed rgba(255,255,255,0.35);
  border-radius: 50%;
  animation: spin 25s linear infinite;
}

.ring-container::after {
  content: ''; position: absolute;
  inset: -16px;
  border: 2px dotted rgba(255,255,255,0.2);
  border-radius: 50%;
  animation: spin 35s linear infinite reverse;
}

@keyframes spin { to { transform: rotate(360deg); } }

.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255,255,255,0.3); stroke-width: 7; }
.ring-fg {
  fill: none; stroke: var(--ring-color); stroke-width: 7;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.25s ease;
  filter: drop-shadow(0 0 10px rgba(255,71,87,0.35));
}

.display-wrapper {
  position: absolute; inset: 0; padding: 18%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}

#display {
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: clamp(2rem, 10vw, 3.4rem); line-height: 1;
  font-weight: 900; letter-spacing: 4px;
  color: #fff;
  text-shadow: 4px 4px 0 rgba(0,0,0,0.15), 0 0 30px rgba(255,255,255,0.15);
}

#display.display-hr {
  font-size: clamp(1.3rem, 5.5vw, 2.2rem);
  letter-spacing: 2px;
}

/* === Pickers === */
.pickers-row {
  display: flex; align-items: center; gap: 4px;
  width: min(72vw, 270px); justify-content: center;
}
.picker-col { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.picker-col label {
  font-size: 9px; color: rgba(255,255,255,0.6);
  font-weight: 700; letter-spacing: 1px;
}

.picker {
  height: 132px; overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  width: 52px; scrollbar-width: none;
  border-radius: 12px;
  background: rgba(255,255,255,0.65);
  backdrop-filter: blur(8px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.3), 0 4px 12px rgba(0,0,0,0.03);
}
.picker::-webkit-scrollbar { display: none; }

.picker-item {
  height: 44px; display: flex; align-items: center; justify-content: center;
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 14px; color: var(--text-dim);
  scroll-snap-align: center; transition: all 0.12s; font-weight: 600;
}
.picker-item.selected { color: var(--accent); font-size: 26px; font-weight: 900; text-shadow: 0 0 8px rgba(255,71,87,0.2); }

.picker-colon {
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  font-size: 26px; font-weight: 900; color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.08);
  padding: 12px 1px 0;
}

/* === Setting view === */
#settingView {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

/* === Presets === */
.presets {
  display: flex; gap: 6px; flex-wrap: wrap;
  justify-content: center;
  width: min(92vw, 380px);
}

.preset-btn {
  background: #fff; border: 3px solid #ddd;
  color: var(--text); font-size: 14px; font-weight: 800;
  padding: 10px 20px; border-radius: 24px;
  cursor: pointer; transition: all 0.12s;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.preset-btn:nth-child(1) { border-color: #FF4757; color: #fff; background: linear-gradient(135deg, #FF4757, #FF6B81); }
.preset-btn:nth-child(2) { border-color: #F59E0B; color: #fff; background: linear-gradient(135deg, #F59E0B, #FBBF24); }
.preset-btn:nth-child(3) { border-color: #10B981; color: #fff; background: linear-gradient(135deg, #10B981, #34D399); }
.preset-btn:nth-child(4) { border-color: #3B82F6; color: #fff; background: linear-gradient(135deg, #3B82F6, #60A5FA); }
.preset-btn:nth-child(5) { border-color: #8B5CF6; color: #fff; background: linear-gradient(135deg, #8B5CF6, #A78BFA); }
.preset-btn:hover { transform: scale(1.08) rotate(-2deg); box-shadow: 0 6px 20px rgba(0,0,0,0.15); }
.preset-btn:active { transform: scale(0.92); }

/* === Controls === */
.controls { display: flex; gap: 12px; align-items: center; }

.control-btn {
  border: none; cursor: pointer;
  font-size: 16px; font-family: inherit; font-weight: 900;
  border-radius: 34px; transition: all 0.12s;
  padding: 14px 48px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.06);
}

.control-btn.primary {
  background: linear-gradient(135deg, #FF6B81, #FF4757);
  color: #fff; border: 3px solid rgba(255,255,255,0.2);
  box-shadow: 0 4px 20px rgba(255,71,87,0.35);
}
.control-btn.primary:hover { transform: scale(1.06) rotate(-2deg); box-shadow: 0 8px 25px rgba(255,71,87,0.4); }
.control-btn.primary:active { transform: scale(0.92); }

.control-btn.secondary {
  background: #fff; color: var(--text); border: 3px solid #e0e0ea;
}
.control-btn.secondary:hover { transform: scale(1.05) rotate(1deg); border-color: #8395A7; }
.control-btn:active { transform: scale(0.92) !important; }

/* === Done overlay === */
.done-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, #FFE0E6, #FFF3CD, #D6ECFF, #E8D5FF);
  background-size: 400% 400%;
  animation: gradientBG 3s ease infinite;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px;
}
@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.done-overlay h1 {
  font-size: clamp(3rem, 14vw, 5rem);
  color: var(--text); font-weight: 900;
  text-shadow: 3px 3px 0 rgba(0,0,0,0.06);
  animation: bounceTitle 0.5s ease infinite alternate;
}
@keyframes bounceTitle {
  from { transform: translateY(0); } to { transform: translateY(-10px); }
}
.done-overlay.flash h1 { color: #ff8a8a; }

.done-btn {
  background: rgba(255,255,255,0.55);
  border: 3px solid rgba(255,255,255,0.5);
  color: var(--text); font-size: 20px; font-weight: 900;
  padding: 14px 56px; border-radius: 36px;
  cursor: pointer; font-family: inherit;
  transition: all 0.12s;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}
.done-btn:hover { background: rgba(255,255,255,0.75); transform: scale(1.05); }

/* === Party particles === */
.particle {
  position: fixed; pointer-events: none; z-index: 101;
  font-size: 28px;
  animation: partyFloat 2s ease-out forwards;
}
@keyframes partyFloat {
  0% { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translateY(-200px) rotate(400deg) scale(0.2); }
}

/* === Responsive === */
@media (max-width: 480px) {
  .app { padding: 14px 16px 56px; gap: 12px; }
  .ring-container { width: min(62vw, 200px); height: min(62vw, 200px); }
  .ring-container.ring-large { width: min(78vw, 260px); height: min(78vw, 260px); }
  #settingView { gap: 10px; }
  .presets { gap: 5px; }
  .preset-btn { font-size: 13px; padding: 9px 16px; }
  .control-btn { font-size: 15px; padding: 12px 38px; }
  .picker { height: 132px; width: 48px; }
}

.hidden { display: none !important; }

@media (min-width: 768px) {
  .ring-container { width: 280px; height: 280px; }
  .ring-container.ring-large { width: 370px; height: 370px; }
}

@supports (padding: env(safe-area-inset-bottom)) {
  .app { padding-bottom: max(64px, env(safe-area-inset-bottom)); }
}
