:root {
  --bg: #f5f2ea;
  --dot: rgba(80, 60, 20, 0.045);
  --card: #fffcf5;
  --ink: #33302a;
  --muted: #7a7263;
  --line: #e7e1d2;
  --line-dash: #d8d0bd;
  --accent: #e2703a;
  --accent-deep: #c9531f;
  --accent-soft: #fbe9dd;
  --accent-border: #eccfae;
  --drop-bg: rgba(226, 112, 58, 0.07);
  --green: #7fa06a;
  --btn-bg: #fff;
  --card-hover: #f3ede0;
  --check-border: #cfc7b4;
  --pill-bg: #efe9da;
  --clone-bg: #fff;
  --input-focus-bg: #fff;
  --today-top: #fff7ec;
  --danger: #b3402a;
  --danger-bg: #f6e0d8;
  --scrim: rgba(50, 40, 20, 0.45);
  --shadow-day: 0 1px 2px rgba(60, 50, 30, 0.05), 0 12px 28px -20px rgba(60, 50, 30, 0.3);
  --nav-shadow: 0 3px 10px -4px rgba(120, 70, 30, 0.35);
}

[data-theme="dark"] {
  --bg: #1b1814;
  --dot: rgba(255, 255, 255, 0.05);
  --card: #262119;
  --ink: #ece7db;
  --muted: #a1988a;
  --line: #39332a;
  --line-dash: #464035;
  --accent: #e08147;
  --accent-deep: #eda06b;
  --accent-soft: rgba(224, 129, 71, 0.15);
  --accent-border: #55402a;
  --drop-bg: rgba(224, 129, 71, 0.1);
  --green: #90ad79;
  --btn-bg: #2e2820;
  --card-hover: #2f2a21;
  --check-border: #57503f;
  --pill-bg: #352e24;
  --clone-bg: #2b251d;
  --input-focus-bg: #2b251d;
  --today-top: #2e2417;
  --danger: #e58a70;
  --danger-bg: rgba(229, 138, 112, 0.14);
  --scrim: rgba(0, 0, 0, 0.6);
  --shadow-day: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 28px -20px rgba(0, 0, 0, 0.7);
  --nav-shadow: 0 3px 10px -4px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-soft); }

.app-header {
  max-width: 1760px;
  margin: 0 auto;
  padding: 22px 24px 6px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 650;
  font-size: 21px;
  letter-spacing: 0.01em;
}

.week-title {
  flex: 1;
  text-align: center;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 500;
  font-size: clamp(19px, 2.8vw, 28px);
  letter-spacing: 0.01em;
  margin: 0;
}

.week-nav { display: flex; align-items: center; gap: 7px; }

.nav-btn {
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--btn-bg);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.nav-btn:hover {
  border-color: var(--accent);
  box-shadow: var(--nav-shadow);
}

.nav-btn:active { transform: translateY(1px); }

.nav-btn:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.today-btn { font-size: 13px; font-weight: 600; }

.theme-btn { padding: 0; width: 34px; }

.icon-sun { display: none; }
.icon-moon { display: block; }

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

#app {
  max-width: 1760px;
  margin: 0 auto;
  padding: 0 24px calc(30px + env(safe-area-inset-bottom));
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.search-input {
  width: min(340px, 100%);
  padding: 9px 13px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--btn-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input::placeholder { color: var(--muted); }

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: filter 0.15s;
}

.btn-primary:hover { filter: brightness(0.93); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-ghost {
  background: none;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.btn-ghost:hover { border-color: var(--accent); }
.btn-ghost:disabled { opacity: 0.5; cursor: default; }

.rollover {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 12px;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  min-height: clamp(380px, 58vh, 560px);
  overflow: hidden;
  box-shadow: var(--shadow-day);
}

.day.today {
  border-color: var(--accent-border);
  background: linear-gradient(180deg, var(--today-top), var(--card) 110px);
}

.day-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 13px 14px 9px;
  border-bottom: 1px dashed var(--line);
}

.day-name {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}

.day-num {
  margin-left: auto;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 650;
  font-size: 21px;
}

.today .day-num { color: var(--accent-deep); }

.today-badge {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  border-radius: 99px;
  padding: 2.5px 7px;
  transform: translateY(-2px);
}

.progress {
  height: 3px;
  margin: 10px 14px 0;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  border-radius: 99px;
  transition: width 0.3s ease;
}

.day-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 9px;
  min-height: 90px;
  border-radius: 10px;
  transition: background 0.15s;
}

.day-list.drop-target {
  background: var(--drop-bg);
  box-shadow: inset 0 0 0 2px var(--accent-soft);
}

.task {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 10px;
}

.task.new-flash { animation: pop 0.18s ease; }

@keyframes pop {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.task:hover { background: var(--card-hover); }

.task.dragging { opacity: 0.35; }

.task.drop-before::before,
.task.drop-after::before {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.task.drop-before::before { top: -4px; }
.task.drop-after::before  { bottom: -4px; }

.touch-clone {
  position: fixed;
  z-index: 99;
  pointer-events: none;
  background: var(--clone-bg);
  border: 1px solid var(--line);
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -100%);
}

.check {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 50%;
  border: 1.6px solid var(--check-border);
  background: var(--btn-bg);
  cursor: pointer;
  position: relative;
  padding: 0;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.check:hover { border-color: var(--accent); transform: scale(1.08); }

.check::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  opacity: 0;
}

.done .check {
  background: var(--green);
  border-color: var(--green);
}

.done .check::after { opacity: 1; }

.task-text {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
  cursor: text;
  min-width: 0;
}

.done .task-text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--muted);
}

.rep-flag {
  flex: none;
  width: 13px;
  height: 13px;
  margin-top: 3px;
  color: var(--accent);
}

.del,
.rep,
.mov {
  flex: none;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.del { font-size: 15px; line-height: 1; }

.rep svg,
.mov svg { width: 13px; height: 13px; }

.task:hover .del,
.task:hover .rep,
.task:hover .mov,
.del:focus-visible,
.rep:focus-visible,
.mov:focus-visible { opacity: 1; }

.del:hover { color: var(--danger); background: var(--danger-bg); }

.rep:hover,
.mov:hover { color: var(--accent); background: var(--accent-soft); }

.add-input {
  margin: 4px 10px 12px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px dashed var(--line-dash);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.add-input::placeholder { color: var(--muted); }

.add-input:focus {
  background: var(--input-focus-bg);
  border-style: solid;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.someday {
  margin-top: 12px;
  min-height: 0;
  border-style: dashed;
  background: transparent;
  box-shadow: none;
}

.someday .day-list { min-height: 44px; }

.someday-icon { color: var(--muted); align-self: center; flex: none; }

.count-pill {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--pill-bg);
  border-radius: 99px;
  padding: 2px 9px;
}

.result-group {
  margin-top: 12px;
  min-height: 0;
}

.rg-head {
  padding: 10px 14px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px dashed var(--line);
}

.empty-state {
  margin-top: 16px;
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  background: var(--card);
  border: 1px dashed var(--line-dash);
  border-radius: 16px;
}

.foot {
  max-width: 1760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 0 16px 30px;
}

.foot-actions { display: flex; gap: 14px; }

.foot-actions button,
.foot-actions a,
.foot-actions a:visited {
  background: none;
  border: none;
  padding: 2px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.foot-actions button:hover,
.foot-actions a:hover { color: var(--accent); }

.dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  padding: 22px;
  width: min(420px, calc(100vw - 40px));
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.5);
}

.dialog::backdrop { background: var(--scrim); }

.dialog-title {
  margin: 0 0 6px;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 650;
  font-size: 20px;
}

.dialog-hint {
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.field {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

.field input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 400;
  font-size: 14px;
  color: var(--ink);
  background: var(--btn-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sync-status {
  min-height: 18px;
  margin: 4px 0 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.sync-status.err { color: var(--danger); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.move-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.move-grid button { padding: 9px 6px; font-size: 12.5px; }

.move-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.toast button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

.toast button:hover { text-decoration: underline; }

.nav-btn:focus-visible,
.check:focus-visible,
.del:focus-visible,
.rep:focus-visible,
.mov:focus-visible,
.search-input:focus-visible,
.btn-primary:focus-visible,
.btn-ghost:focus-visible,
.foot-actions button:focus-visible,
.foot-actions a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 1080px) {
  .board {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    scrollbar-color: var(--line-dash) transparent;
    padding-bottom: 10px;
  }

  .day {
    min-width: min(310px, 80vw);
    scroll-snap-align: center;
  }
}

@media (max-width: 700px) {
  .app-header { justify-content: center; padding-top: 16px; }
  .week-title { order: 3; flex-basis: 100%; }
}

@media (max-width: 640px) {
  #app { padding-left: 12px; padding-right: 12px; }

  .toolbar { margin-top: 10px; }
  .search-input { width: 100%; }

  .board {
    display: flex;
    flex-direction: column;
    overflow: visible;
    scroll-snap-type: none;
    padding-bottom: 0;
  }

  .day {
    min-width: 0;
    min-height: 0;
    scroll-snap-align: none;
  }

  .day-list { min-height: 40px; }

  .foot { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}

@media (hover: none) and (pointer: coarse) {
  .nav-btn { height: 42px; min-width: 42px; }
  .theme-btn { width: 42px; }
  .today-btn { font-size: 14px; }

  .check { width: 24px; height: 24px; margin-top: 1px; }

  .check::after {
    left: 7px;
    top: 4px;
    width: 7px;
    height: 12px;
  }

  .del,
  .rep,
  .mov {
    width: 32px;
    height: 32px;
    opacity: 1;
  }

  .del { font-size: 18px; }
  .rep svg,
  .mov svg { width: 16px; height: 16px; }

  .task-text,
  .search-input,
  .add-input { font-size: 16px; }

  .add-input { padding: 11px 12px; }

  .field input { font-size: 16px; }

  .task-text { user-select: none; -webkit-user-select: none; }
  .task { -webkit-touch-callout: none; }
}

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