:root {
  --bg: #05070a;
  --panel: #101520;
  --text: #f5f8ff;
  --accent: #66f2ff;
  --warning: #ff3245;
  --muted: #a9b7d4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 14%, rgba(102, 196, 255, 0.42) 0%, transparent 34%),
    radial-gradient(circle at 88% 4%, rgba(74, 156, 235, 0.28) 0%, transparent 28%),
    linear-gradient(180deg, #0a1824 0%, #04080d 100%);
}

.timer-layout {
  min-height: 100vh;
  padding: 0.85rem 1rem calc(4.75rem + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  gap: 0.75rem;
}

.timer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.timer-header h1 {
  margin: 0;
  font-size: clamp(1.2rem, 3.5vw, 1.9rem);
  letter-spacing: 0.04em;
}

.home-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.home-link:focus-visible,
.home-link:hover {
  text-decoration: underline;
}

.timer-face {
  display: grid;
  place-items: center;
  border: 4px solid #36557a;
  border-radius: 1rem;
  background: linear-gradient(135deg, #0a0f18, #111c2f);
  box-shadow: 0 0 0.75rem rgba(102, 242, 255, 0.25);
  padding: 0.65rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
  overflow: hidden;
}

.timer-face.warning-on {
  border-color: var(--warning);
  box-shadow:
    0 0 0 0.32rem rgba(255, 50, 69, 0.24),
    0 0 1.35rem rgba(255, 50, 69, 0.82);
}

.time-display {
  margin: 0;
  line-height: 1;
  font-family: "Chakra Petch", "Consolas", monospace;
  font-weight: 700;
  font-size: clamp(4rem, 24vw, 15rem);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  color: #ffffff;
  text-shadow: 0 0 0.5rem rgba(102, 242, 255, 0.7);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  width: 100%;
  max-width: 100%;
}

.time-part {
  width: 2ch;
  text-align: center;
  -webkit-text-stroke: 2px transparent;
}

.time-colon {
  width: 1ch;
  text-align: center;
  flex: 0 0 1ch;
}

.time-display:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 4px;
}

.controls {
  display: grid;
  gap: 0.65rem;
}

.input-row,
.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.action-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  width: 100%;
  border: 2px solid #416086;
  border-radius: 0.6rem;
  background: #0f1a2b;
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0.65rem;
  text-align: center;
}

.btn {
  border: 2px solid transparent;
  border-radius: 0.65rem;
  color: #ffffff;
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  font-weight: 700;
  padding: 0.75rem;
  cursor: pointer;
  font-family: inherit;
}

.btn:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

.btn-primary {
  background: #0e9f6e;
}

.btn-secondary {
  background: #2d3e5a;
}

.btn-danger {
  background: #8a1420;
}

.btn-quick {
  background: #24304a;
  border-color: #5c8cc0;
}

.quick-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: rgba(3, 6, 11, 0.95);
  border-top: 1px solid #32496b;
  backdrop-filter: blur(6px);
}

.quick-panel {
  position: relative;
}

.quick-panel-toggle {
  list-style: none;
  min-height: 3rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: 2px solid #5c8cc0;
  border-radius: 0.75rem;
  background: #14243b;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.quick-panel-toggle::-webkit-details-marker {
  display: none;
}

.quick-panel-toggle::after {
  content: "+";
  font-size: 1.2rem;
  line-height: 1;
}

.quick-panel[open] .quick-panel-toggle::after {
  content: "-";
}

.quick-panel-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 0.6rem);
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.65rem;
  padding: 0.75rem;
  border: 1px solid #32496b;
  border-radius: 1rem;
  background: rgba(9, 14, 22, 0.96);
  box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.35);
}

.sound-select {
  min-height: 3.1rem;
  padding: 0.6rem 0.75rem;
  background: #14243b;
  border: 2px solid #5c8cc0;
  border-radius: 0.65rem;
  color: #ffffff;
  font-family: inherit;
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23a9b7d4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}

.sound-select:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

.expire-flash {
  position: fixed;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  background: #ffffff;
  transition: opacity 80ms linear;
}

.expire-flash.on {
  opacity: 0.9;
}

@media (max-width: 760px) {
  .action-row {
    grid-template-columns: 1fr 1fr;
  }

  .quick-panel-body {
    grid-template-columns: 1fr 1fr;
  }

  .sound-select {
    grid-column: 1 / -1;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .timer-layout {
    grid-template-rows: auto auto auto auto;
    padding-top: 0.65rem;
    padding-bottom: calc(4.2rem + env(safe-area-inset-bottom));
    gap: 0.5rem;
  }

  .timer-header h1 {
    font-size: 1.05rem;
  }

  .timer-face {
    min-height: 34vh;
    padding: 0.45rem;
  }

  .time-display {
    font-size: clamp(2.7rem, 13vw, 8rem);
  }

  .btn,
  .sound-select,
  .quick-panel-toggle {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    min-height: 2.7rem;
  }

  .status-message {
    min-height: 1rem;
    font-size: 0.85rem;
  }
}
