:root {
  --ink: #1a2833;
  --muted: #5a6f7c;
  --paper: #eef4f7;
  --panel: rgba(250, 253, 255, 0.9);
  --line: rgba(26, 40, 51, 0.12);
  --accent: #2a7ba8;
  --accent-soft: #d2ebf4;
  --accent-hover: #21678e;
  --danger: #9b3d2e;
  --shadow: 0 24px 60px rgba(26, 40, 51, 0.14);
  --radius: 18px;
  --font-display: "Bricolage Grotesque", sans-serif;
  --font-body: "Manrope", sans-serif;
  --font-task: "Oswald", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 55% at 12% -10%, #b8daf0 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 10%, #d5ebf5 0%, transparent 50%),
    linear-gradient(165deg, #e6f1f7 0%, #f0f7fb 48%, #d4e8f2 100%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { filter: hue-rotate(0deg) saturate(1); transform: scale(1); }
  to { filter: hue-rotate(-6deg) saturate(1.05); transform: scale(1.03); }
}

.view {
  width: min(980px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.5rem 0 4rem;
}

.hidden {
  display: none !important;
}

.brand {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.brand.compact {
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.lede, .hint, .empty {
  color: var(--muted);
}

.auth-view {
  width: min(720px, calc(100% - 2rem));
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding-block: 2rem;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 0.55s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-form {
  display: grid;
  gap: 0.9rem;
  margin-top: 1.4rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font: inherit;
  color: var(--ink);
  background: #fafcff;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, white);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.auth-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.2rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #f4f8ff;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-hover);
}

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

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.55);
}

button.small {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1rem;
  animation: rise 0.45s ease both;
}

.tabs {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.55rem 1rem;
  font-size: 0.92rem;
}

.tab.active {
  background: var(--accent);
  color: #f4f8ff;
  border-color: var(--accent);
}

.range-row {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.range-btn.active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, white);
  color: var(--ink);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.4rem;
}

.stat-card {
  padding: 0.95rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat-card .label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.stat-card .value {
  margin: 0.25rem 0 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.stats-block {
  margin-bottom: 1.6rem;
}

.stats-block h2 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.chart {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 140px;
  padding: 0.75rem 0.4rem 0;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.chart-bar {
  flex: 1 0 8px;
  min-width: 8px;
  max-width: 18px;
  border-radius: 6px 6px 2px 2px;
  background: color-mix(in srgb, var(--accent) 55%, #9bc8db);
  height: var(--h, 4%);
  min-height: 4px;
  opacity: 0.85;
  transition: height 0.35s ease, opacity 0.2s ease;
  position: relative;
}

.chart-bar.full {
  background: var(--accent);
  opacity: 1;
}

.chart-bar.empty {
  background: rgba(26, 36, 51, 0.12);
  opacity: 0.55;
}

.chart-bar:hover {
  opacity: 1;
}

.chart-bar::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--ink);
  color: #f4f8ff;
  font-size: 0.7rem;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 2;
}

.chart-bar:hover::after {
  opacity: 1;
}

.task-stats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.task-stat {
  display: grid;
  gap: 0.35rem;
  padding: 0.85rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.task-stat.inactive .task-stat-title {
  color: var(--muted);
}

.task-stat-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.task-stat-title {
  margin: 0;
  font-family: var(--font-task);
  font-weight: 400;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.task-stat-count {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.meter {
  height: 8px;
  border-radius: 999px;
  background: rgba(26, 36, 51, 0.08);
  overflow: hidden;
}

.meter > span {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  background: var(--accent);
  border-radius: inherit;
}

.task-stat-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.history-list {
  display: grid;
  gap: 0.55rem;
}

.history-day {
  padding: 0.85rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.history-day-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.history-day-head strong {
  font-size: 0.95rem;
}

.history-day-head span {
  color: var(--muted);
  font-size: 0.85rem;
}

.history-tasks {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.2rem;
}

.history-tasks li {
  font-family: var(--font-task);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.history-tasks li em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.8rem;
}

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.add-form {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
  animation: rise 0.5s ease 0.05s both;
}

.add-row {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.add-row input {
  flex: 1;
  min-width: 180px;
}

.period-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
}

.period-option {
  margin: 0;
  cursor: pointer;
}

.period-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.period-option span {
  display: block;
  text-align: center;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 80%, white);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.period-option input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #f4f8ff;
}

.period-option:hover span {
  border-color: color-mix(in srgb, var(--accent) 35%, white);
}

.hint {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
}

.period-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  align-items: stretch;
}

.period-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 14rem;
  padding: 0.55rem;
  border: 1px dashed color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: calc(var(--radius) - 4px);
  background: color-mix(in srgb, var(--panel) 45%, transparent);
}

.period-title {
  margin: 0 0 0.55rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
  text-align: center;
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  align-content: start;
  min-height: 2.5rem;
}

#edit-board .edit-list {
  flex: 1;
  min-height: 10rem;
}

.period-board .task-item {
  padding: 0.75rem 0.85rem;
  gap: 0.55rem;
}

.period-board .task-title {
  font-size: 1.12rem;
}

.period-board .check {
  width: 1.75rem;
  height: 1.75rem;
  font-size: 0.9rem;
}

.task-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.95rem 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(26, 36, 51, 0.06);
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  animation: rise 0.4s ease both;
}

.task-item.do-mode {
  cursor: pointer;
}

.task-item.do-mode:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, white);
  box-shadow: 0 12px 30px rgba(42, 123, 168, 0.12);
}

.task-item.edit-mode {
  grid-template-columns: auto 1fr auto;
  cursor: grab;
}

.task-item.edit-mode:active {
  cursor: grabbing;
}

.task-item.dragging {
  opacity: 0.55;
  transform: scale(0.98);
}

.task-item.done {
  background: color-mix(in srgb, var(--accent-soft) 70%, white);
}

.task-item.done .task-title {
  color: var(--muted);
}

.task-item.done .task-title span {
  text-decoration: line-through;
}

.task-item.done .task-title em {
  margin-left: 1.25rem;
  font-style: normal;
  font-size: 0.8rem;
  color: color-mix(in srgb, var(--muted) 40%, white);
}

.handle {
  width: 1.1rem;
  height: 1.4rem;
  display: grid;
  gap: 3px;
  align-content: center;
  opacity: 0.35;
}

.handle span {
  display: block;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

.task-main {
  min-width: 0;
}

.task-title {
  margin: 0;
  font-family: var(--font-task);
  font-weight: 400;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  word-break: break-word;
}

.task-item.edit-mode .task-title {
  cursor: text;
  border-radius: 6px;
  outline: 1px solid transparent;
  transition: outline-color 0.15s ease, background 0.15s ease;
}

.task-item.edit-mode .task-title:hover {
  background: color-mix(in srgb, var(--accent-soft) 55%, white);
  outline-color: color-mix(in srgb, var(--accent) 25%, white);
}

.task-item.editing {
  cursor: default;
}

.title-edit {
  width: 100%;
  margin: 0;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
  font-family: var(--font-task);
  font-weight: 400;
  font-size: 1.12rem;
  letter-spacing: 0.02em;
}

.task-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.check {
  width: 2.05rem;
  height: 2.05rem;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 55%, white);
  background: #fff;
  color: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  pointer-events: none;
}

.task-item.done .check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.delete-btn {
  width: 2.05rem;
  height: 2.05rem;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 1.1rem;
}

.delete-btn:hover {
  background: rgba(155, 61, 46, 0.08);
  color: var(--danger);
  border-color: rgba(155, 61, 46, 0.15);
}

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

dialog {
  border: 0;
  border-radius: calc(var(--radius) + 4px);
  padding: 0;
  width: min(420px, calc(100% - 2rem));
  background: transparent;
  box-shadow: none;
}

dialog::backdrop {
  background: rgba(18, 28, 44, 0.45);
  backdrop-filter: blur(3px);
}

.confirm-panel {
  margin: 0;
  padding: 1.5rem;
  background: #fafcff;
  border: 1px solid var(--line);
  border-radius: inherit;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.85rem;
  animation: rise 0.3s ease both;
}

.confirm-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}

.confirm-panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.confirm-task {
  margin: 0;
  font-family: var(--font-task);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.answer-grid {
  display: grid;
  gap: 0.55rem;
}

.answer-grid button {
  width: 100%;
  border-radius: 14px;
  justify-content: center;
}

@media (max-width: 820px) {
  .period-board {
    grid-template-columns: 1fr;
    gap: 1.1rem;
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
    align-items: start;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .task-item.edit-mode {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "handle main"
      "handle actions";
  }

  .task-item.edit-mode .handle { grid-area: handle; }
  .task-item.edit-mode .task-main { grid-area: main; }
  .task-item.edit-mode .task-actions {
    grid-area: actions;
    justify-content: start;
  }
}
