:root {
  color-scheme: light;
  --background: #ffffff;
  --foreground: #000000;
  --muted: #666666;
  --faint: #8a8a8a;
  --line: #d4d4d4;
  --selection: #dedede;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --background: #000000;
    --foreground: #ffffff;
    --muted: #a3a3a3;
    --faint: #777777;
    --line: #3d3d3d;
    --selection: #333333;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --background: #ffffff;
  --foreground: #000000;
  --muted: #666666;
  --faint: #8a8a8a;
  --line: #d4d4d4;
  --selection: #dedede;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #000000;
  --foreground: #ffffff;
  --muted: #a3a3a3;
  --faint: #777777;
  --line: #3d3d3d;
  --selection: #333333;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--background);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  color: var(--foreground);
  background: var(--background);
}

.page-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(360px, 1fr) auto auto;
  min-height: 100vh;
  min-height: 100svh;
}

.page-shell:has(> .ad-region > .ad-slot > .adsbygoogle[data-ad-status="unfilled"]) {
  height: 100vh;
  height: 100svh;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--foreground);
  outline-offset: 3px;
}

::selection {
  color: var(--foreground);
  background: var(--selection);
}

.theme-toggle {
  position: fixed;
  z-index: 10;
  top: 18px;
  right: 18px;
  width: 68px;
  height: 36px;
  padding: 0;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--foreground);
}

.theme-toggle__track {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
}

.theme-toggle__thumb {
  position: absolute;
  z-index: 1;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
  background: var(--foreground);
  border-radius: 50%;
  transform: translateX(0);
  transition: transform 160ms ease;
}

:root[data-theme="light"] .theme-toggle__thumb {
  transform: translateX(32px);
}

.theme-toggle__icon {
  position: absolute;
  z-index: 2;
  top: 9px;
  width: 16px;
  height: 16px;
  background: var(--muted);
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: contain;
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  pointer-events: none;
}

.theme-toggle__icon--moon {
  left: 9px;
  mask-image: url("../icons/moon.svg");
  -webkit-mask-image: url("../icons/moon.svg");
}

.theme-toggle__icon--sun {
  right: 9px;
  mask-image: url("../icons/sun.svg");
  -webkit-mask-image: url("../icons/sun.svg");
}

:root[data-theme="dark"] .theme-toggle__icon--moon,
:root[data-theme="light"] .theme-toggle__icon--sun {
  background: var(--background);
}

.app {
  display: flex;
  grid-row: 1;
  width: min(88vw, 430px);
  margin: 0 auto;
  padding: 72px 0 28px;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.ad-region {
  display: grid;
  grid-row: 2;
  width: min(calc(100% - 32px), 728px);
  min-height: 116px;
  margin: 0 auto;
  padding: 8px 0 16px;
  place-items: center;
}

.ad-slot {
  display: grid;
  width: 100%;
  min-height: 90px;
  place-items: center;
}

.ad-slot > .adsbygoogle {
  width: 100%;
}

.ad-slot > .adsbygoogle[data-ad-status="unfilled"] {
  display: none !important;
}

.ad-region:has(> .ad-slot > .adsbygoogle[data-ad-status="unfilled"]) {
  min-height: 0;
  padding: 0;
}

.ad-region:has(> .ad-slot > .adsbygoogle[data-ad-status="unfilled"]) .ad-slot {
  min-height: 0;
}

.site-footer {
  grid-row: 3;
  min-height: 36px;
  padding: 0 16px 16px;
  text-align: right;
}

#privacy-open,
#privacy-close {
  padding: 4px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  font-size: 0.75rem;
  cursor: pointer;
}

#privacy-open {
  position: fixed;
  z-index: 9;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
}

#privacy-open:hover,
#privacy-close:hover {
  color: var(--foreground);
  border-color: var(--foreground);
}

.privacy-dialog {
  width: min(calc(100% - 32px), 520px);
  max-height: calc(100svh - 32px);
  padding: 0;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--line);
  border-radius: 0;
}

.privacy-dialog::backdrop {
  background: rgb(0 0 0 / 55%);
}

.privacy-dialog__content {
  padding: 28px;
}

.privacy-dialog h1 {
  margin: 0 0 20px;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.privacy-dialog p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.privacy-dialog a {
  color: var(--foreground);
  text-underline-offset: 3px;
}

.privacy-dialog form {
  margin-top: 24px;
  text-align: right;
}

#shift-form {
  width: 100%;
}

#shift-form[hidden] {
  display: none;
}

#time-in {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--line);
  border-radius: 0;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  caret-color: var(--foreground);
  transition: border-color 120ms ease;
}

#time-in:hover,
#time-in:focus {
  border-color: var(--foreground);
}

#time-in::placeholder {
  color: var(--faint);
  opacity: 1;
}

#time-in[aria-invalid="true"] {
  border-color: var(--foreground);
  border-style: dashed;
}

#input-error {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

#input-error[hidden] {
  display: none;
}

#result {
  width: 100%;
}

#result[hidden] {
  display: none;
}

#status-label {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

#countdown {
  margin: 0;
  font-size: clamp(3.2rem, 16vw, 5.8rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.065em;
  line-height: 0.95;
  white-space: nowrap;
}

.remaining-label {
  margin: 10px 0 28px;
  color: var(--faint);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.remaining-label[hidden] {
  display: none;
}

.target {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.target strong {
  color: var(--foreground);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#target-date {
  color: var(--faint);
}

#reset-button {
  margin-top: 24px;
  padding: 4px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  font-size: 0.75rem;
  cursor: pointer;
}

#reset-button:hover {
  color: var(--foreground);
  border-color: var(--foreground);
}

body[data-shift-status="complete"] #countdown {
  font-weight: 650;
}

.noscript {
  position: fixed;
  right: 0;
  bottom: 16px;
  left: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

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

@media (max-width: 420px) {
  .app {
    width: calc(100% - 32px);
  }

  #countdown {
    font-size: clamp(3rem, 17vw, 4.4rem);
  }
}

@media (min-width: 1100px) {
  .page-shell {
    grid-template-columns: minmax(300px, 1fr) minmax(320px, 430px) minmax(300px, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .app {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    padding: 72px 0 32px;
  }

  .ad-region {
    grid-column: 3;
    grid-row: 1;
    width: min(calc(100% - 32px), 300px);
    min-height: 250px;
    padding: 72px 0 32px;
  }

  .ad-slot {
    min-height: 250px;
  }

  .site-footer {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (max-height: 560px) and (max-width: 1099px) {
  .page-shell {
    grid-template-rows: minmax(320px, auto) auto auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
