:root {
  --scale: 1;
  --panel-scale: 1;
  --red: #ff3f48;
  --blue: #37a4ff;
  --yellow: #ffd85a;
  --dark: #080916;
  --base-width: 774px;
  --base-height: 638px;
  --menu-offset: 34px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: transparent;
  color: #fff;
  font-family: "Courier New", Consolas, monospace;
  user-select: none;
}

button,
input {
  font: inherit;
}

.app {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 8px;
  opacity: 0.95;
}

.floating-timer {
  position: relative;
  width: var(--base-width);
  height: calc(var(--base-height) + var(--menu-offset));
  -webkit-app-region: drag;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.32));
}

.scale-stage {
  position: absolute;
  inset: 0 auto auto 0;
  width: var(--base-width);
  height: calc(var(--base-height) + var(--menu-offset));
  transform: scale(var(--scale));
  transform-origin: top left;
  -webkit-app-region: drag;
}

.timer-frame {
  position: absolute;
  left: 0;
  top: var(--menu-offset);
  width: var(--base-width);
  height: var(--base-height);
  container-type: inline-size;
}

.scene-image,
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.scene-image {
  z-index: 1;
  object-fit: contain;
  pointer-events: none;
}

#scene {
  z-index: 2;
  pointer-events: none;
}

.intro-layer {
  position: absolute;
  z-index: 120;
  inset: 0;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
  -webkit-app-region: no-drag;
}

.scale-stage:not(.intro-complete) .scene-image,
.scale-stage:not(.intro-complete) #scene,
.scale-stage:not(.intro-complete) .clock-layer,
.scale-stage:not(.intro-complete) .validation-message,
.scale-stage:not(.intro-complete) .confetti {
  visibility: hidden;
}

.intro-layer.is-complete {
  z-index: 8;
  pointer-events: none;
}

.intro-layer.is-cleared {
  display: none;
}

.intro-click {
  width: 20%;
  height: auto;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.48));
  animation: clickPrompt 1.35s ease-in-out infinite;
  transform-origin: center;
}

.intro-bg,
.intro-logo,
.intro-guide {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.intro-guide {
  width: 100%;
  height: 100%;
  align-content: center;
  justify-items: center;
  padding-top: 25%;
  color: #050505;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-weight: 900;
  text-align: center;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.45);
}

.intro-guide p {
  margin: 0 0 10px;
  opacity: 0;
  font-size: clamp(11px, 2.5cqw, 19px);
  line-height: 1.2;
}

.intro-guide span {
  color: var(--red);
}

.intro-layer.is-playing {
  cursor: default;
}

.intro-layer.is-playing .intro-click {
  display: none;
}

.intro-layer.is-playing .intro-bg,
.intro-layer.is-playing .intro-logo,
.intro-layer.is-playing .intro-guide,
.intro-layer.is-complete .intro-bg,
.intro-layer.is-complete .intro-logo,
.intro-layer.is-complete .intro-guide {
  display: block;
}

.intro-layer.is-playing .intro-guide,
.intro-layer.is-complete .intro-guide {
  display: grid;
}

.intro-layer.is-playing .intro-bg,
.intro-layer.is-playing .intro-logo {
  animation-duration: 900ms;
  animation-timing-function: cubic-bezier(0.16, 0.92, 0.22, 1);
  animation-fill-mode: forwards;
}

.intro-layer.is-playing .intro-bg {
  animation-name: introBgRise;
}

.intro-layer.is-playing .intro-logo {
  animation-name: introLogoSequence;
  animation-duration: 2600ms;
}

.intro-layer.is-playing .intro-guide {
  animation: introGuideRise 900ms cubic-bezier(0.16, 0.92, 0.22, 1) 1700ms forwards;
}

.intro-layer.is-playing .intro-guide p:nth-child(1) {
  animation: introGuideLine 360ms ease 1700ms forwards;
}

.intro-layer.is-playing .intro-guide p:nth-child(2) {
  animation: introGuideLine 360ms ease 1950ms forwards;
}

.intro-layer.is-playing .intro-guide p:nth-child(3) {
  animation: introGuideLine 360ms ease 2200ms forwards;
}

.intro-layer.is-playing .intro-guide p:nth-child(4) {
  animation: introGuideLine 360ms ease 2450ms forwards;
}

.window-tools {
  position: absolute;
  z-index: 20;
  top: 0;
  left: 0;
  width: var(--base-width);
  height: 40px;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 4px;
  -webkit-app-region: no-drag;
}

.tool-button,
.close-button {
  width: 34px;
  height: 34px;
  padding: 6px;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-weight: 900;
  opacity: 1;
  transform: none;
  -webkit-app-region: no-drag;
}

.tool-button img,
.close-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55));
}

.close-button {
  color: var(--red);
  font-size: 28px;
  line-height: 1;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.55);
}

.clock-layer {
  position: absolute;
  z-index: 10;
  left: 5.6%;
  right: 5.6%;
  bottom: 6.9%;
  height: 18.4%;
  display: grid;
  grid-template-columns: 0.9fr 1.34fr 1.34fr 0.72fr;
  grid-template-rows: 1fr 1fr;
  column-gap: 1.6%;
  row-gap: 5.5%;
  align-items: center;
  -webkit-app-region: no-drag;
  pointer-events: auto;
}

.round-field,
.time-field {
  display: grid;
  align-items: center;
  min-width: 0;
  text-shadow: 0.45cqw 0.45cqw 0 #000;
}

.round-field {
  grid-row: 1 / 3;
  grid-template-rows: 0.48fr 1fr 0.34fr;
  justify-items: center;
  color: var(--red);
}

.time-field {
  grid-template-columns: auto minmax(0, 1fr);
  gap: 3%;
  align-self: center;
}

.work-field {
  grid-column: 2 / 4;
  grid-row: 1;
  color: var(--red);
}

.rest-field {
  grid-column: 2 / 4;
  grid-row: 2;
  color: var(--blue);
}

.round-field span,
.time-field span {
  font-weight: 900;
  letter-spacing: 0;
}

.round-field span {
  font-size: clamp(14px, 5.6cqw, 38px);
  line-height: 1;
}

.time-field span {
  min-width: 4.2ch;
  font-size: clamp(14px, 5.3cqw, 36px);
  line-height: 1;
}

.clock-layer input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: currentColor;
  text-align: center;
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: 0.45cqw 0.45cqw 0 #000;
  -webkit-app-region: no-drag;
  pointer-events: auto;
}

.round-field input {
  height: 100%;
  font-size: clamp(34px, 12.6cqw, 84px);
  line-height: 0.9;
}

.round-field strong {
  min-height: 1.1em;
  margin-top: -2px;
  color: #fff;
  font-size: clamp(11px, 2.7cqw, 18px);
  line-height: 1;
  text-shadow: 0.35cqw 0.35cqw 0 #000;
}

.time-field input {
  font-size: clamp(24px, 8.3cqw, 56px);
  line-height: 0.9;
}

.clock-layer input:focus {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 2px currentColor;
}

.next-button {
  min-width: 0;
  width: min(100%, 8.8cqw);
  aspect-ratio: 1 / 1;
  justify-self: center;
  align-self: center;
  border: max(1px, 0.32cqw) solid #11131f;
  color: #fff;
  font-weight: 900;
  font-size: clamp(16px, 4cqw, 30px);
  cursor: pointer;
  text-shadow: 0.25cqw 0.25cqw 0 #000;
  box-shadow: 0.45cqw 0.45cqw 0 #000;
  padding: 0;
  -webkit-app-region: no-drag;
  pointer-events: auto;
  background: linear-gradient(#8f949d, #4a4e58);
  grid-column: 4;
  grid-row: 1 / 3;
}

.next-button:active {
  transform: translate(0.25cqw, 0.25cqw);
  box-shadow: 0.22cqw 0.22cqw 0 #000;
}

.start-button,
.pause-button {
  min-width: 0;
  height: 100%;
  border: max(1px, 0.32cqw) solid #11131f;
  color: #fff;
  font-weight: 900;
  font-size: clamp(9px, 2.15cqw, 16px);
  cursor: pointer;
  text-shadow: 0.25cqw 0.25cqw 0 #000;
  box-shadow: 0.45cqw 0.45cqw 0 #000;
  padding: 0;
  -webkit-app-region: no-drag;
  pointer-events: auto;
}

.start-button {
  grid-column: 4;
  grid-row: 1;
  background: linear-gradient(#ff5c62, #b90916);
}

.pause-button {
  grid-column: 4;
  grid-row: 2;
  background: linear-gradient(#54baff, #075ea8);
}

.start-button:active,
.pause-button:active {
  transform: translate(0.25cqw, 0.25cqw);
  box-shadow: 0.22cqw 0.22cqw 0 #000;
}

.validation-message {
  position: absolute;
  z-index: 18;
  left: 5.6%;
  right: 5.6%;
  bottom: 1.8%;
  min-height: 1.25em;
  color: var(--yellow);
  font-size: clamp(11px, 2.4cqw, 17px);
  font-weight: 900;
  text-align: center;
  text-shadow: 0.25cqw 0.25cqw 0 #000;
  -webkit-app-region: no-drag;
  pointer-events: none;
}

.is-locked .clock-layer input {
  pointer-events: none;
}

.settings {
  position: absolute;
  z-index: 30;
  top: 0;
  left: 0;
  right: auto;
  width: 200px;
  display: none;
  gap: 8px;
  padding: 10px;
  border: 2px solid #626879;
  background: rgba(8, 9, 22, 0.94);
  box-shadow: 4px 4px 0 #000;
  transform: scale(var(--panel-scale));
  transform-origin: top left;
  -webkit-app-region: no-drag;
}

.settings.open {
  display: grid;
}

.settings label {
  display: grid;
  grid-template-columns: 50px 1fr;
  align-items: center;
  gap: 7px;
  color: #eef2ff;
  font-size: 12px;
  font-weight: 900;
}

.settings input {
  min-width: 0;
}

.stepped-scale {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.stepped-scale input {
  grid-column: 1 / 2;
  width: 100%;
}

.scale-marks {
  grid-column: 1 / 2;
  display: flex;
  justify-content: space-between;
  margin-top: -3px;
  color: rgba(238, 242, 255, 0.85);
  font-size: 11px;
  line-height: 1;
}

.stepped-scale output {
  grid-column: 2;
  grid-row: 1 / 3;
  min-width: 28px;
  color: var(--yellow);
  text-align: right;
}

.confetti {
  position: absolute;
  z-index: 80;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti i {
  position: absolute;
  top: -12%;
  display: block;
  width: 10px;
  height: 16px;
  background: var(--c);
  border: max(1px, 0.12cqw) solid rgba(0, 0, 0, 0.28);
  box-shadow: 0 0 0.9cqw rgba(255, 255, 255, 0.55);
  opacity: 0;
  animation: confettiFall var(--d) linear forwards;
}

.confetti.active {
  animation: confettiPulse 0.55s steps(2, end) 2;
}

.invalid {
  animation: invalidFlash 0.18s steps(1, end) 4;
}

@keyframes confettiFall {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }

  9% {
    opacity: 1;
  }

  80% {
    opacity: 1;
  }

  to {
    transform: translate3d(var(--x), 116vh, 0) rotate(var(--r));
    opacity: 0;
  }
}

@keyframes confettiPulse {
  50% {
    filter: brightness(1.45);
  }
}

@keyframes invalidFlash {
  50% {
    filter: brightness(1.8);
  }
}

@keyframes introLogoSequence {
  0% {
    transform: translate3d(0, -47%, 0);
  }

  34.6%,
  65.4% {
    transform: translate3d(0, 0, 0);
  }

  100% {
    transform: translate3d(0, -213px, 0);
  }
}

@keyframes introBgRise {
  from {
    transform: translate3d(0, 105%, 0);
  }

  to {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes introGuideRise {
  from {
    transform: translate3d(0, 22%, 0);
  }

  to {
    transform: translate3d(0, -18%, 0);
  }
}

@keyframes introGuideLine {
  from {
    opacity: 0;
    transform: translate3d(0, 14px, 0);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes clickPrompt {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
    filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.48)) brightness(1);
  }

  48% {
    transform: translate3d(0, -2.4%, 0) scale(1.045);
    filter: drop-shadow(0 16px 0 rgba(0, 0, 0, 0.36)) brightness(1.18);
  }
}

@media (max-width: 560px) {
  .clock-layer {
    left: 5.8%;
    right: 5.8%;
    bottom: 7%;
    height: 17.8%;
    grid-template-columns: 0.86fr 1.3fr 1.3fr 0.74fr;
    column-gap: 1.2%;
  }

  .time-field {
    gap: 1%;
  }
}


/* Variant 1: CSS-driven Ready loop. */
.ready-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: none;
  pointer-events: none;
}
.ready-layer.ready-active { display: block; }
.ready-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.ready-frame-b { opacity: 0; }
.ready-layer.ready-active .ready-frame-a { animation: readyA 1s steps(1, end) infinite; }
.ready-layer.ready-active .ready-frame-b { animation: readyB 1s steps(1, end) infinite; }
@keyframes readyA { 0%, 49.9% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes readyB { 0%, 49.9% { opacity: 0; } 50%, 100% { opacity: 1; } }


/* Web publish fallback: browsers cannot close arbitrary tabs, so hide the timer cleanly. */
body.is-closed .floating-timer {
  display: none;
}

body.is-closed::before {
  content: "Deadline Buster가 종료되었습니다. 다시 시작하려면 페이지를 새로고침하세요.";
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #111;
  background: #f4f4f4;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 18px;
  text-align: center;
}
