:root {
  --paper: #faf7f0;
  --ink: #4b443a;
  --ink-soft: #8a8172;
  --line: #e7e0d2;
  --accent: #f2c94c;
  --danger: #d9776b;
  --shadow: 0 6px 16px rgba(90, 78, 54, 0.14);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html,
body {
  height: 100%;
}

body {
  font-family: "Neucha", "Segoe Print", "Comic Sans MS", cursive;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(rgba(75, 68, 58, 0.06) 1px, transparent 1px);
  background-size: 22px 22px;
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: linear-gradient(var(--paper) 85%, rgba(250, 247, 240, 0));
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-title {
  font-size: 30px;
  font-weight: 400;
  letter-spacing: 0.5px;
  transform: rotate(-1.2deg);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 1.5px dashed var(--ink-soft);
  border-radius: 12px;
  background: #fffdf6;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(90, 78, 54, 0.12);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.icon-btn:active {
  transform: scale(0.88);
  box-shadow: 0 1px 3px rgba(90, 78, 54, 0.12);
}

.icon-btn.accent {
  background: var(--accent);
  border-style: solid;
  border-color: #dcb63e;
}

.icon-btn.small {
  width: 30px;
  height: 30px;
  border: none;
  box-shadow: none;
  background: transparent;
  color: var(--ink-soft);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn.small svg {
  width: 16px;
  height: 16px;
}

.search-panel {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transform: translateY(-8px);
  transition: grid-template-rows 0.32s var(--ease), opacity 0.28s var(--ease),
    transform 0.32s var(--ease), margin 0.32s var(--ease);
}

.search-panel.open {
  grid-template-rows: 1fr;
  opacity: 1;
  transform: translateY(0);
  margin-top: 12px;
}

.search-panel > * {
  overflow: hidden;
}

.search-panel .search-field {
  min-height: 0;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fffdf6;
  border: 1.5px dashed var(--ink-soft);
  border-radius: 12px;
  padding: 8px 10px;
}

.search-icon {
  display: inline-flex;
  color: var(--ink-soft);
}

.search-icon svg {
  width: 18px;
  height: 18px;
}

.search-field input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
}

.date-filter {
  margin-top: 8px;
  width: 100%;
  border: 1.5px dashed var(--ink-soft);
  border-radius: 12px;
  background: #fffdf6;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 96px);
}

.note-card {
  position: relative;
  border-radius: 4px 14px 8px 12px;
  padding: 30px 12px 14px;
  min-height: 120px;
  box-shadow: var(--shadow);
  transform: rotate(var(--rot, 0deg));
  cursor: pointer;
  animation: card-in 0.42s var(--ease) backwards;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
  word-break: break-word;
}

.note-card:active {
  transform: rotate(var(--rot, 0deg)) scale(0.94);
  box-shadow: 0 3px 8px rgba(90, 78, 54, 0.14);
}

.note-card::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  width: 58px;
  height: 20px;
  transform: translateX(-50%) rotate(-2deg);
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(90, 78, 54, 0.12);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(90, 78, 54, 0.08);
}

.note-card.removing {
  animation: card-out 0.28s var(--ease) forwards;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: rotate(var(--rot, 0deg)) translateY(18px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: rotate(var(--rot, 0deg)) translateY(0) scale(1);
  }
}

@keyframes card-out {
  to {
    opacity: 0;
    transform: rotate(var(--rot, 0deg)) scale(0.6);
  }
}

.note-card h3 {
  font-size: 19px;
  font-weight: 400;
  line-height: 1.15;
  margin-bottom: 6px;
}

.note-when {
  font-size: 13px;
  color: rgba(75, 68, 58, 0.62);
  margin-bottom: 6px;
}

.note-preview {
  font-size: 15px;
  line-height: 1.3;
  color: rgba(75, 68, 58, 0.85);
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.c-yellow { background: #fff6a9; }
.c-pink { background: #ffd9e8; }
.c-blue { background: #cde8ff; }
.c-green { background: #d6f5d6; }
.c-orange { background: #ffe3c2; }
.c-violet { background: #e8deff; }

.empty {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.empty[hidden] {
  display: none;
}

.empty-sticker {
  pointer-events: auto;
  cursor: pointer;
  width: 210px;
  padding: 26px 18px;
  text-align: center;
  background: #fff6a9;
  border-radius: 4px 14px 8px 12px;
  box-shadow: var(--shadow);
  transform: rotate(-2deg);
  font-size: 18px;
  line-height: 1.35;
  animation: card-in 0.5s var(--ease) backwards;
}

.empty-icon svg {
  width: 34px;
  height: 34px;
  margin-bottom: 8px;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(60, 52, 38, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
  z-index: 30;
}

.backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  transform: translateY(105%);
  transition: transform 0.36s var(--ease);
  padding: 0 10px calc(env(safe-area-inset-bottom) + 10px);
}

.sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.85);
  margin: 0 auto 8px;
}

.sheet-paper {
  background: var(--sheet-color, #fff6a9);
  border-radius: 6px 18px 10px 14px;
  box-shadow: 0 -8px 30px rgba(60, 52, 38, 0.25);
  padding: 18px 16px 16px;
  max-height: 78vh;
  overflow-y: auto;
  transition: background 0.3s var(--ease);
}

.color-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.color-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(75, 68, 58, 0.18);
  cursor: pointer;
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease);
}

.color-dot.selected {
  border-color: var(--ink);
  transform: scale(1.22);
}

.color-dot:active {
  transform: scale(0.9);
}

.note-title {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 24px;
  color: var(--ink);
  border-bottom: 1.5px dashed rgba(75, 68, 58, 0.3);
  padding: 4px 2px 8px;
  margin-bottom: 12px;
}

.when-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.when-field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.5);
  border: 1.5px dashed rgba(75, 68, 58, 0.3);
  border-radius: 10px;
  padding: 7px 9px;
}

.when-icon {
  display: inline-flex;
  color: var(--ink-soft);
}

.when-icon svg {
  width: 17px;
  height: 17px;
}

.when-field input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
}

.note-body {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink);
  resize: none;
  min-height: 130px;
  background-image: repeating-linear-gradient(
    transparent,
    transparent 25px,
    rgba(75, 68, 58, 0.14) 26px
  );
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(90, 78, 54, 0.16);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.btn:active {
  transform: scale(0.94);
  box-shadow: 0 1px 3px rgba(90, 78, 54, 0.14);
}

.btn.primary {
  background: #fffdf6;
}

.btn.danger {
  background: rgba(255, 253, 246, 0.6);
  color: var(--danger);
}

.btn.ghost {
  background: transparent;
  box-shadow: none;
  border: 1.5px dashed var(--ink-soft);
}

.btn-icon {
  display: inline-flex;
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(60, 52, 38, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease);
}

.modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(320px, 86vw);
  background: #fffdf6;
  border-radius: 6px 16px 10px 14px;
  box-shadow: var(--shadow);
  padding: 22px 18px 16px;
  text-align: center;
  font-size: 19px;
  transform: scale(0.85) rotate(-1deg);
  transition: transform 0.25s var(--ease);
}

.modal.open .modal-card {
  transform: scale(1) rotate(-1deg);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 80px);
  background: var(--ink);
  color: #fffdf6;
  font-size: 16px;
  padding: 10px 18px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.34s var(--ease), opacity 0.3s var(--ease);
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

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

.skeleton {
  border-radius: 4px 14px 8px 12px;
  min-height: 130px;
  background: #f1ead9;
  animation: pulse 1.1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.55; }
  to { opacity: 1; }
}
