:root {
  color-scheme: light;
  --canvas-color: #f4f3ef;
  --canvas-wash: #eeeee9;
  --panel-color: rgba(255, 255, 252, 0.92);
  --ink-color: #25302b;
  --muted-color: #7c8580;
  --faint-color: #aab1ac;
  --line-color: #e1e4de;
  --line-strong-color: #cbd2cc;
  --accent-color: #438775;
  --accent-dark-color: #276656;
  --accent-soft-color: #e3f0eb;
  --board-surface-color: #dedbd4;
  --piece-locked-color: #e9e6df;
  --danger-color: #ad625b;
  --panel-radius: 22px;
  --control-radius: 11px;
  --panel-shadow: 0 16px 42px rgba(47, 61, 55, 0.11),
    0 2px 8px rgba(47, 61, 55, 0.06);
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 280px;
  min-height: 100%;
  background: var(--canvas-color);
}

body {
  min-width: 280px;
  min-height: 100svh;
  margin: 0;
  background: var(--canvas-color);
  color: var(--ink-color);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
.file-picker:focus-within {
  outline: 3px solid rgba(67, 135, 117, 0.27);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  isolation: isolate;
}

.empty-canvas,
.puzzle-board {
  position: absolute;
  inset: 0;
}

.empty-canvas {
  z-index: -1;
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 255, 255, 0.34), transparent 34rem),
    var(--canvas-color);
}

.puzzle-board {
  z-index: 0;
  display: grid;
  place-items: center;
  padding: 0;
  pointer-events: none;
}

.puzzle-grid {
  --grid-columns: 1;
  --grid-rows: 1;
  display: grid;
  grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-rows), minmax(0, 1fr));
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  overflow: hidden;
  background: var(--board-surface-color);
  pointer-events: auto;
}

.puzzle-piece {
  --piece-clip: 0 0, 100% 0, 100% 100%, 0 100%;
  position: relative;
  z-index: 0;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  clip-path: polygon(var(--piece-clip));
  filter: drop-shadow(0 1px 1px rgba(71, 68, 62, 0.2));
  transition: filter 160ms ease, transform 160ms ease;
}

.puzzle-piece[data-state="revealed"] {
  z-index: 1;
  background: var(--board-surface-color);
}

.puzzle-piece__locked,
.puzzle-piece__image {
  position: absolute;
  inset: -10%;
  width: 120%;
  height: 120%;
}

.puzzle-piece__locked {
  background: linear-gradient(145deg, #f2f0eb, var(--piece-locked-color));
  box-shadow: inset 0 0 0 1px rgba(79, 75, 68, 0.12);
}

.puzzle-piece__locked::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.25), transparent 54%);
  content: "";
}

.puzzle-piece__image {
  display: block;
  object-fit: fill;
  user-select: none;
}

.puzzle-piece--revealing {
  animation: piece-reveal 380ms cubic-bezier(0.22, 0.85, 0.3, 1.15) both;
}

.puzzle-piece--removing {
  z-index: 2;
  animation: piece-remove 360ms cubic-bezier(0.45, 0.05, 0.55, 0.95) both;
}

@keyframes piece-reveal {
  0% {
    opacity: 0.25;
    transform: translateY(-10px) scale(0.82) rotate(-1deg);
  }

  68% {
    opacity: 1;
    transform: translateY(2px) scale(1.04) rotate(0.25deg);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }
}

@keyframes piece-remove {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }

  45% {
    opacity: 0.8;
    transform: translateY(-4px) scale(1.03) rotate(-0.5deg);
  }

  100% {
    opacity: 0;
    transform: translateY(-18px) scale(0.78) rotate(2deg);
  }
}

.control-panel {
  position: fixed;
  bottom: max(1rem, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 10;
  width: min(calc(100% - 2rem), 30rem);
  max-height: min(76svh, 34rem);
  padding: 1rem 1.05rem 0.9rem;
  overflow: auto;
  border: 1px solid rgba(203, 210, 204, 0.78);
  border-radius: var(--panel-radius);
  background: var(--panel-color);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(17px);
  transform: translateX(-50%);
  scrollbar-width: thin;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.panel-heading--compact {
  align-items: center;
  margin-bottom: 0.2rem;
}

.panel-heading__actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 0.45rem;
}

.panel-kicker {
  margin: 0 0 0.08rem;
  color: var(--accent-dark-color);
  font-size: 0.64rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  margin-bottom: 0;
  color: var(--ink-color);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.panel-mark {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-color);
  border-radius: 50%;
  color: var(--accent-color);
  font-size: 0.85rem;
}

.panel-hide-button {
  display: grid;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-color);
  border-radius: 50%;
  background: transparent;
  color: var(--muted-color);
  font-size: 1.15rem;
  line-height: 1;
  transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease;
}

.panel-hide-button:hover {
  border-color: var(--line-strong-color);
  background: var(--canvas-wash);
  color: var(--ink-color);
}

.panel-reopen-button {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 11;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.35rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid rgba(203, 210, 204, 0.9);
  border-radius: 999px;
  background: var(--panel-color);
  box-shadow: var(--panel-shadow);
  color: var(--ink-color);
  font-size: 0.72rem;
  font-weight: 700;
  backdrop-filter: blur(17px);
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.panel-reopen-button:hover {
  border-color: var(--line-strong-color);
  background: #fff;
  transform: translateY(-1px);
}

.setup-form {
  display: grid;
  gap: 0.7rem;
}

.form-field {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.form-field > label,
.checklist-fields legend {
  color: var(--muted-color);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

input[type="number"],
input[type="time"],
input[type="text"] {
  width: 100%;
  min-height: 2.25rem;
  padding: 0.4rem 0.62rem;
  border: 1px solid var(--line-color);
  border-radius: var(--control-radius);
  outline: 0;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink-color);
  transition: border-color 150ms ease, background-color 150ms ease;
}

input[type="number"]:hover,
input[type="time"]:hover,
input[type="text"]:hover {
  border-color: var(--line-strong-color);
}

input[type="number"]:focus,
input[type="time"]:focus,
input[type="text"]:focus {
  border-color: var(--accent-color);
  background: #fff;
}

input::placeholder {
  color: var(--faint-color);
}

.file-picker {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 3.5rem;
  padding: 0.58rem 0.72rem;
  border: 1px dashed var(--line-strong-color);
  border-radius: var(--control-radius);
  background: rgba(249, 250, 246, 0.64);
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.file-picker:hover {
  border-color: var(--accent-color);
  background: var(--accent-soft-color);
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.file-picker__icon {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 9px;
  background: var(--accent-soft-color);
  color: var(--accent-dark-color);
  font-size: 1.1rem;
  font-weight: 400;
}

.file-picker__copy {
  display: grid;
  min-width: 0;
  gap: 0.05rem;
}

.file-picker__title,
.file-picker__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-picker__title {
  color: var(--ink-color);
  font-size: 0.78rem;
  font-weight: 650;
}

.file-picker__name {
  color: var(--muted-color);
  font-size: 0.68rem;
}

.setup-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.checklist-fields {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.checklist-fields legend {
  margin-bottom: 0.28rem;
  padding: 0;
}

#setupChecklistFields {
  display: grid;
  gap: 0.35rem;
}

.checklist-field {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr);
  align-items: center;
  gap: 0.45rem;
}

.checklist-field__number {
  display: grid;
  width: 1.15rem;
  height: 1.15rem;
  place-items: center;
  border-radius: 50%;
  background: var(--canvas-wash);
  color: var(--muted-color);
  font-size: 0.62rem;
  font-weight: 700;
}

.checklist-field input {
  min-height: 2rem;
}

.setup-footer,
.puzzle-footer,
.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.privacy-note {
  max-width: 18rem;
  margin: 0;
  color: var(--muted-color);
  font-size: 0.65rem;
  line-height: 1.35;
}

.button {
  min-height: 2.25rem;
  padding: 0.42rem 1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.01em;
  transition: background-color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button--primary {
  flex: 0 0 auto;
  background: var(--accent-color);
  color: #fff;
}

.button--primary:hover {
  background: var(--accent-dark-color);
}

.button:disabled {
  cursor: wait;
  opacity: 0.55;
  transform: none;
}

.icon-button {
  display: grid;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line-color);
  border-radius: 50%;
  background: transparent;
  color: var(--muted-color);
  font-size: 1.1rem;
  line-height: 1;
  transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease;
}

.icon-button:hover {
  border-color: var(--line-strong-color);
  background: var(--canvas-wash);
  color: var(--ink-color);
}

.deadline {
  margin: 0 0 0.62rem;
  color: var(--muted-color);
  font-size: 0.68rem;
}

.daily-checklist {
  display: grid;
  gap: 0.2rem;
}

.daily-checklist__item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.45rem;
  padding: 0.2rem 0.25rem;
  border-radius: 10px;
  color: var(--ink-color);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.daily-checklist__item:hover {
  background: rgba(227, 240, 235, 0.52);
}

.daily-checklist__checkbox {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--accent-color);
}

.daily-checklist__label {
  font-size: 0.8rem;
  line-height: 1.25;
}

.daily-checklist__item:has(input:checked) .daily-checklist__label {
  color: var(--muted-color);
  text-decoration: line-through;
  text-decoration-color: rgba(67, 135, 117, 0.5);
}

.progress-row {
  margin-top: 0.65rem;
  color: var(--muted-color);
  font-size: 0.67rem;
  font-weight: 650;
}

.progress-day {
  color: var(--faint-color);
  font-weight: 550;
}

.progress-bar {
  display: block;
  width: 100%;
  height: 0.28rem;
  margin: 0.35rem 0 0.55rem;
  overflow: hidden;
  border: 0;
  border-radius: 99px;
  background: var(--canvas-wash);
}

.progress-bar::-webkit-progress-bar {
  border-radius: 99px;
  background: var(--canvas-wash);
}

.progress-bar::-webkit-progress-value {
  border-radius: 99px;
  background: var(--accent-color);
  transition: width 300ms ease;
}

.progress-bar::-moz-progress-bar {
  border-radius: 99px;
  background: var(--accent-color);
}

.puzzle-footer {
  align-items: flex-end;
  min-height: 1.2rem;
}

.status-message {
  min-height: 1.05em;
  margin: 0;
  color: var(--muted-color);
  font-size: 0.68rem;
  line-height: 1.35;
}

.status-message[data-tone="success"] {
  color: var(--accent-dark-color);
}

.status-message[data-tone="error"] {
  color: var(--danger-color);
}

.backup-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 0.55rem;
}

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted-color);
  font-size: 0.66rem;
  font-weight: 700;
}

.text-button:hover {
  color: var(--accent-dark-color);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

@media (min-width: 561px) {
  #setupChecklistFields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 0.6rem;
  }
}

@media (max-width: 560px) {
  .puzzle-board {
    padding: 0;
  }

  .puzzle-grid {
    width: 100%;
    height: 100%;
  }

  .control-panel {
    bottom: max(0.5rem, env(safe-area-inset-bottom));
    width: calc(100% - 1rem);
    max-height: 54svh;
    padding: 0.85rem 0.85rem 0.75rem;
    border-radius: 18px;
  }

  .panel-heading {
    margin-bottom: 0.65rem;
  }

  .setup-form {
    gap: 0.58rem;
  }

  .setup-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.42rem;
  }

  .setup-options input {
    padding-inline: 0.45rem;
  }

  .daily-checklist__item {
    min-height: 2.7rem;
  }

  .panel-reopen-button {
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
