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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #13132b;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
}

#app {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: 20px;
}

.settings-btn {
  position: absolute;
  top: 24px;
  right: 24px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.35);
  cursor: pointer;
  transition: color 0.2s, transform 0.2s;
  z-index: 10;
  padding: 8px;
}

.settings-btn:hover {
  color: rgba(255,255,255,0.7);
  transform: rotate(60deg);
}

/* Flip Clock */
.flip-clock {
  display: flex;
  align-items: center;
  gap: clamp(4px, 1vh, 16px);
  margin-bottom: 40px;
}

.flip-digit {
  position: relative;
  width: clamp(33px, 26vh, 280px);
  height: clamp(50px, 40vh, 420px);
  flex-shrink: 0;
}

.flip-digit > span {
  position: absolute;
  inset: 0;
  display: block;
  perspective: 400px;
}

.flip-digit > span::before,
.flip-digit > span::after {
  content: attr(data-digit);
  position: absolute;
  left: 0;
  width: 100%;
  height: 50%;
  text-align: center;
  font-size: clamp(40px, 32vh, 340px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #e8e8f0;
  background: #1c1c3a;
  overflow: hidden;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.flip-digit > span::before {
  top: 0;
  line-height: 1.24;
  border-radius: clamp(5px, 0.6vw, 10px) clamp(5px, 0.6vw, 10px) 0 0;
  transform-origin: bottom;
  border-bottom: 1px solid rgba(0,0,0,0.35);
}

.flip-digit > span::after {
  bottom: 0;
  line-height: 0;
  border-radius: 0 0 clamp(5px, 0.6vw, 10px) clamp(5px, 0.6vw, 10px);
  transform-origin: top;
  border-top: 1px solid rgba(255,255,255,0.05);
}

.flip-digit.flipping .flip-next {
  z-index: 0;
  animation: nextZIndex 0.7s linear forwards;
}

.flip-digit.flipping .flip-next::after {
  animation: flipBottom 0.7s linear forwards,
             bottomShadowIn 0.7s linear forwards;
}

.flip-digit.flipping .flip-current {
  z-index: 1;
  animation: currentZIndex 0.7s linear forwards;
}

.flip-digit.flipping .flip-current::before {
  animation: flipTop 0.7s linear forwards,
             topShadowOut 0.7s linear forwards;
}

.flip-digit.flipping .flip-current::after {
  animation: bottomShadowOut 0.7s linear forwards;
}

@keyframes nextZIndex {
  to { z-index: 1; }
}

@keyframes currentZIndex {
  to { z-index: 0; }
}

@keyframes flipTop {
  from { transform: rotateX(0); }
  to { transform: rotateX(-180deg); }
}

@keyframes flipBottom {
  from { transform: rotateX(180deg); }
  to { transform: rotateX(0); }
}

@keyframes topShadowOut {
  0% { box-shadow: inset 0 0 10px -8px rgba(0,0,0,0); }
  100% { box-shadow: inset 0 -80px 20px -10px rgba(0,0,0,0.6); }
}

@keyframes bottomShadowOut {
  0% { box-shadow: inset 0 0 10px -8px rgba(0,0,0,0); }
  100% { box-shadow: inset 0 80px 20px -10px rgba(0,0,0,0.6); }
}

@keyframes bottomShadowIn {
  from { box-shadow: inset 0 80px 20px -10px rgba(0,0,0,0.6); }
  to { box-shadow: inset 0 0 20px -10px rgba(0,0,0,0); }
}

.flip-sep {
  font-size: clamp(30px, 22vh, 240px);
  font-weight: 300;
  color: rgba(255,255,255,0.25);
  line-height: 1;
  margin: 0 clamp(2px, 0.5vh, 8px);
  animation: sepPulse 1s ease-in-out infinite;
}

@keyframes sepPulse {
  50% { opacity: 0.12; }
}

#app.running .flip-digit > span::before,
#app.running .flip-digit > span::after {
  text-shadow: 0 0 24px rgba(100,140,255,0.18);
}

/* Controls */
#controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.ctrl-btn {
  padding: 14px 36px;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  letter-spacing: 0.02em;
}

.ctrl-btn:active {
  transform: scale(0.95);
}

.ctrl-btn.start {
  background: #2ea043;
  color: #fff;
  box-shadow: 0 4px 20px rgba(46,160,67,0.35);
}

.ctrl-btn.start:hover {
  box-shadow: 0 6px 28px rgba(46,160,67,0.5);
}

.ctrl-btn.stop {
  background: #da3633;
  color: #fff;
  box-shadow: 0 4px 20px rgba(218,54,51,0.35);
}

.ctrl-btn.stop:hover {
  box-shadow: 0 6px 28px rgba(218,54,51,0.5);
}

.ctrl-btn.reset {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  border: 1px solid rgba(255,255,255,0.12);
}

.ctrl-btn.reset:hover {
  background: rgba(255,255,255,0.14);
  color: #fff;
}

.ctrl-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Info bar */
#info {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 64px;
  font-size: clamp(1.25rem, 3.75vw, 3.75rem);
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  transition: opacity 0.25s;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: #14141e;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 36px 40px 32px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 24px;
  color: #e0e0f0;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.5);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: #fff;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: rgba(100,140,255,0.5);
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
}

.modal-actions .ctrl-btn {
  flex: 1;
  text-align: center;
  padding: 12px;
  font-size: 0.95rem;
}

@media (max-width: 480px) {
  #info {
    gap: 24px;
    flex-direction: column;
    align-items: center;
    bottom: 20px;
  }

  .ctrl-btn {
    padding: 12px 24px;
    font-size: 0.95rem;
  }

  .modal {
    padding: 28px 24px;
  }
}
