:root,
.theme-dark {
  --background-color: #121212;
  --text-color: #ffffff;
  --secondary-color: #ffffff;
  --accent-color: #03dac6;
  --success-color: #03dac6;
  --preset-color: rgba(255, 255, 255, 0.05);
  --preset-hover-color: rgba(255, 255, 255, 0.08);
  --preset-active-color: rgba(255, 255, 255, 0.12);
  --border-color: #444;
  --hover-color: #333;
  --shadow-color: rgba(255, 255, 255, 0.1);
}

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

body {
  align-items: stretch;
  background: var(--background-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  font-family: Inter, -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
  width: 100%;
}

.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

#site-header {
  flex-shrink: 0;
  width: 100%;
}

.top-page-nav {
  background: var(--background-color);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem;
  position: relative;
  z-index: 100;
}

.top-page-nav-inner {
  align-items: center;
  display: flex;
  justify-content: center;
  margin: 0 auto;
  max-width: 1200px;
}

.top-page-nav-toggle-button {
  align-items: center;
  background: var(--preset-color);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-color);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.72rem 1.35rem;
}

.top-page-nav-toggle-icon {
  font-size: 1.15rem;
}

.top-page-nav-panel {
  display: none;
}

.top-page-nav.is-open .top-page-nav-panel {
  display: block;
}

#app {
  align-items: center;
  background: var(--background-color);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 101px);
  position: relative;
  width: 100%;
  z-index: 1;
}

#countdown-container {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 auto;
  max-width: 1200px;
  padding: 2rem;
  text-align: center;
  width: 100%;
}

#countdown-display {
  display: flex;
  gap: 2rem;
  justify-content: center;
  margin-bottom: 3rem;
  transition: font-size 0.3s ease, transform 0.3s ease;
}

.time-section {
  align-items: center;
  display: flex;
  flex-direction: column;
  position: relative;
}

.time-section span {
  display: inline-block;
  font-size: calc(12rem * var(--timer-font-scale, 1));
  font-weight: 600;
  line-height: 1;
  min-width: 2ch;
  text-align: center;
  text-shadow: 0 4px 8px var(--shadow-color);
}

.time-section .label {
  color: var(--secondary-color);
  font-size: calc(2rem * min(var(--timer-font-scale, 1), 1.18));
  margin-top: 1rem;
}

#progress-container {
  background: rgba(128, 128, 128, 0.1);
  bottom: 0;
  height: 6px;
  left: 0;
  position: fixed;
  width: 100%;
}

#progress-bar {
  background: var(--accent-color);
  height: 100%;
  transition: width 0.3s linear;
  width: 0;
}

.controls,
#controls {
  width: 100%;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 2rem;
}

.preset-btn,
.custom-time-container,
.control-btn {
  background: var(--preset-color);
  border: 0;
  box-shadow: 0 2px 4px var(--shadow-color);
  color: var(--text-color);
  cursor: pointer;
}

.preset-btn {
  align-items: center;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 100px;
  padding: 1rem;
  position: relative;
}

.preset-time {
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1;
}

.preset-unit {
  font-size: 0.9rem;
  opacity: 0.8;
}

.custom-time-container {
  align-items: center;
  border-radius: 16px;
  display: flex;
  height: 100%;
  justify-content: center;
  padding: 0.8rem;
  width: 100px;
}

.custom-time-wrapper {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  justify-content: center;
  width: 100%;
}

#custom-time-input,
#custom-time-unit {
  background: transparent;
  border: 0;
  color: var(--text-color);
  text-align: center;
}

#custom-time-input {
  font-size: 2rem;
  font-weight: 600;
  height: 2.2rem;
  line-height: 1;
  width: 100%;
}

#custom-time-input::placeholder {
  color: var(--text-color);
  font-size: 1.2rem;
  opacity: 0.6;
}

#custom-time-unit {
  font-size: 0.9rem;
}

.main-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

.control-btn {
  border-radius: 8px;
  font-size: 1rem;
  padding: 0.8rem 1.5rem;
}

.control-btn.primary {
  background: var(--success-color);
  color: var(--background-color);
}

.theme-dropdown,
.settings-dropdown {
  display: inline-block;
  position: relative;
}

.theme-menu,
.settings-menu {
  background: var(--background-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  bottom: calc(100% + 16px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: none;
  max-height: 70vh;
  min-width: 240px;
  overflow-y: auto;
  padding: 16px;
  position: absolute;
  right: 0;
  z-index: 1000;
}

.theme-dropdown.open .theme-menu,
.settings-dropdown.open .settings-menu {
  display: block;
}

.shortcut-hint {
  display: none;
}

audio {
  display: none;
}

@media (max-width: 768px) {
  #app {
    /* 居中分布计时器与控件，避免内容堆在顶部造成首屏下方大片空白；
       header 实际高度约 100px，用 100px 抵消避免 #app 溢出视口 */
    justify-content: center;
    min-height: calc(100svh - 100px);
    min-height: calc(100dvh - 100px);
  }

  #countdown-container {
    gap: clamp(1.1rem, 4vw, 1.8rem);
    justify-content: center;
    padding: clamp(0.8rem, 3vw, 1.2rem) clamp(0.7rem, 3vw, 1rem) calc(1rem + env(safe-area-inset-bottom));
  }

  #countdown-display {
    display: grid;
    gap: clamp(0.35rem, 2vw, 0.72rem);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: clamp(1rem, 4vh, 2rem);
    max-width: 100%;
    width: 100%;
  }

  .time-section {
    min-width: 0;
    width: 100%;
  }

  .time-section span {
    font-size: calc(clamp(2.95rem, 16.5vw, 4.35rem) * min(var(--timer-font-scale, 1), 1));
    line-height: 0.98;
    max-width: 100%;
    min-width: 0;
  }

  .time-section .label {
    font-size: calc(clamp(0.66rem, 2.9vw, 0.9rem) * min(var(--timer-font-scale, 1), 1));
    margin-top: 0.4rem;
  }

  #controls {
    display: grid;
    gap: clamp(0.72rem, 2.8vw, 1rem);
    width: min(100%, 430px);
  }

  .presets {
    display: grid;
    gap: 0.55rem;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin-bottom: 0;
    width: 100%;
  }

  .preset-btn,
  .custom-time-container {
    border-radius: 12px;
    min-height: 58px;
    min-width: 0;
    padding: 0.54rem 0.38rem;
    width: 100%;
  }

  .preset-time {
    font-size: clamp(1.15rem, 5vw, 1.45rem);
  }

  .preset-unit,
  #custom-time-unit {
    font-size: 0.72rem;
  }

  #custom-time-input {
    font-size: 1.15rem;
    height: 1.9rem;
  }

  #custom-time-input::placeholder {
    font-size: 0.72rem;
  }

  .main-controls {
    display: grid;
    gap: 0.55rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .main-controls > .control-btn,
  .main-controls > .theme-dropdown,
  .main-controls > .settings-dropdown {
    min-width: 0;
    width: 100%;
  }

  .control-btn,
  .theme-toggle,
  .settings-toggle {
    align-items: center;
    border-radius: 12px;
    display: inline-flex;
    font-size: 0.9rem;
    justify-content: center;
    min-height: 44px;
    padding: 0.68rem 0.58rem;
    width: 100%;
  }

  .current-theme-name,
  .settings-toggle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main-controls > .settings-dropdown:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 380px) {
  #countdown-container {
    padding-left: 0.55rem;
    padding-right: 0.55rem;
  }

  .time-section span {
    font-size: calc(clamp(2.8rem, 15.8vw, 3.85rem) * min(var(--timer-font-scale, 1), 1));
  }

  .presets {
    gap: 0.42rem;
  }

  .preset-btn,
  .custom-time-container {
    min-height: 54px;
    padding: 0.48rem 0.28rem;
  }
}
