* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  font-family:
    "Segoe UI",
    "Yu Gothic UI",
    "Meiryo",
    sans-serif;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at center, #17243a 0%, #070b12 60%, #000000 100%);
  color: #f7f9ff;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.timer-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.timer-panel {
  width: min(1200px, 100%);
  perspective: 1800px;
  transition: opacity 0.35s ease;
}

.timer-panel-inner {
  display: grid;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s ease-in-out;
}

.timer-panel.is-finished {
  opacity: 0.7;
}

.timer-panel.is-finished .timer-panel-inner {
  transform: rotateY(180deg);
}

.timer-face {
  grid-area: 1 / 1;
  width: 100%;
  padding: clamp(20px, 3vw, 42px);
  border: 1px solid rgba(182, 211, 255, 0.55);
  border-radius: clamp(24px, 4vw, 56px);
  background:
    linear-gradient(
      145deg,
      rgba(32, 50, 78, 0.92),
      rgba(6, 12, 23, 0.96)
    );
  box-shadow:
    0 0 30px rgba(116, 168, 255, 0.18),
    inset 0 0 28px rgba(158, 200, 255, 0.08);
  text-align: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.timer-face-front {
  position: relative;
}

.timer-face-back {
  display: grid;
  min-height: 100%;
  align-content: center;
  justify-items: center;
  gap: clamp(28px, 5vw, 60px);
  transform: rotateY(180deg);
}

.timer-title {
  max-width: 100%;
  margin: 0 auto clamp(8px, 1.6vw, 18px);
  padding: 4px 18px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #eef5ff;
  font-size: clamp(2rem, 5vw, 4.8rem);
  font-weight: 700;
  line-height: 1.15;
  cursor: text;
  text-shadow: 0 0 16px rgba(159, 198, 255, 0.32);
  overflow-wrap: anywhere;
}

.timer-title:hover,
.timer-title:focus-visible {
  border-bottom-color: rgba(164, 202, 255, 0.7);
  outline: none;
}

.error-message {
  min-height: 1.5em;
  margin: 0;
  color: #ff9a9a;
  font-weight: 700;
}

.time-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(4px, 1vw, 18px);
  width: 100%;
  margin: 0 auto clamp(20px, 4vw, 42px);
}

.time-unit {
  display: grid;
  min-width: 0;
  justify-items: center;
}

.time-number {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #ffffff;
  font-family: Consolas, "Roboto Mono", "Courier New", monospace;
  font-size: clamp(6rem, 23vw, 20rem);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.08em;
  cursor: text;
  text-shadow:
    0 0 12px rgba(255, 255, 255, 0.5),
    0 0 28px rgba(153, 194, 255, 0.2);
}

.time-number:hover,
.time-number:focus-visible {
  outline: none;
  text-shadow:
    0 0 16px rgba(255, 255, 255, 0.72),
    0 0 36px rgba(125, 177, 255, 0.34);
}

.time-colon {
  align-self: center;
  padding-bottom: clamp(18px, 4vw, 52px);
  font-family: Consolas, "Roboto Mono", "Courier New", monospace;
  font-size: clamp(5rem, 13vw, 13rem);
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 16px rgba(255, 255, 255, 0.45);
}

.adjust-button {
  width: clamp(44px, 5vw, 64px);
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #91a8c8;
  font-size: clamp(1rem, 2vw, 1.8rem);
  cursor: pointer;
  opacity: 0.72;
  transition:
    color 0.15s ease,
    opacity 0.15s ease,
    transform 0.15s ease;
}

.adjust-button:hover,
.adjust-button:focus-visible {
  color: #d9e8ff;
  opacity: 1;
  outline: none;
  transform: scale(1.12);
}

.buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 1.8vw, 22px);
}

.buttons button,
.finished-reset-button {
  min-height: 64px;
  padding: 14px 18px;
  border: 1px solid rgba(151, 184, 227, 0.58);
  border-radius: 18px;
  background: rgba(21, 34, 54, 0.9);
  color: #eaf2ff;
  font-size: clamp(1rem, 2vw, 1.8rem);
  font-weight: 700;
  cursor: pointer;
  box-shadow: inset 0 0 16px rgba(122, 169, 236, 0.06);
}

#start-button {
  border-color: #84b6ff;
  background: linear-gradient(145deg, #376cff, #1541b8);
  box-shadow:
    0 0 22px rgba(71, 126, 255, 0.45),
    inset 0 0 12px rgba(255, 255, 255, 0.12);
}

#reset-button {
  color: #dce8fa;
}

.buttons button:hover:not(:disabled),
.buttons button:focus-visible:not(:disabled),
.finished-reset-button:hover,
.finished-reset-button:focus-visible {
  filter: brightness(1.14);
  outline: 3px solid rgba(155, 198, 255, 0.32);
  outline-offset: 3px;
}

.buttons button:disabled,
.adjust-button:disabled,
.time-number:disabled,
.timer-title:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.timer-panel.is-running .adjust-button {
  visibility: hidden;
}

.finished-message {
  display: grid;
  justify-items: center;
  gap: clamp(12px, 2vw, 24px);
  width: 100%;
}

.finished-title,
.finished-text {
  max-width: 100%;
  margin: 0;
  color: #ffffff;
  font-weight: 700;
  line-height: 1.05;
  overflow-wrap: anywhere;
  text-shadow:
    0 0 16px rgba(255, 255, 255, 0.4),
    0 0 34px rgba(153, 194, 255, 0.24);
}

.finished-title {
  font-size: clamp(2.5rem, 7vw, 7rem);
}

.finished-text {
  font-size: clamp(5rem, 16vw, 15rem);
  letter-spacing: 0.08em;
}

.finished-reset-button {
  width: min(360px, 80%);
}

@media (max-width: 720px) {
  .timer-page {
    padding: 12px;
  }

  .timer-face {
    padding: 20px 14px;
    border-radius: 28px;
  }

  .time-editor {
    gap: 0;
  }

  .time-number {
    font-size: clamp(5rem, 28vw, 10rem);
  }

  .time-colon {
    padding-bottom: 28px;
    font-size: clamp(3.8rem, 13vw, 6rem);
  }

  .buttons {
    grid-template-columns: 1fr;
  }

  .buttons button {
    width: 100%;
    min-height: 56px;
  }

  .timer-face-back {
    gap: 28px;
  }

  .finished-title {
    font-size: clamp(2.2rem, 10vw, 4.5rem);
  }

  .finished-text {
    font-size: clamp(4.5rem, 24vw, 9rem);
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .timer-page {
    padding: 8px;
  }

  .timer-face {
    padding: 12px 22px;
  }

  .timer-title {
    margin-bottom: 0;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
  }

  .error-message {
    min-height: 1.2em;
    font-size: 0.85rem;
  }

  .time-editor {
    margin-bottom: 8px;
  }

  .time-number {
    font-size: clamp(4rem, 17vw, 8rem);
  }

  .time-colon {
    padding-bottom: 24px;
    font-size: clamp(3rem, 9vw, 5rem);
  }

  .adjust-button {
    min-height: 30px;
  }

  .buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .buttons button {
    min-height: 48px;
    padding: 8px;
    font-size: 1rem;
  }

  .timer-face-back {
    gap: 16px;
  }

  .finished-title {
    font-size: clamp(1.8rem, 5vw, 3.2rem);
  }

  .finished-text {
    font-size: clamp(4rem, 12vw, 7rem);
  }

  .finished-reset-button {
    min-height: 48px;
    padding: 8px;
    font-size: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
