:root {
  --sky: #2E9EF5;
  --sky-deep: #1C7ED6;
  --sky-light: #6FC3FF;
  --sky-pale: #EAF5FF;
  --white: #FFFFFF;
  --paper: #FCFDFF;
  --ink: #24313F;
  --ink-soft: #6B7A8C;
  --line: #DCE6F0;
  --red: #FF5C5C;
  --red-deep: #E14444;
  --radius: 18px;
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
  --shadow-raised: 0 1px 0 #FFFFFF inset, 0 -1px 0 rgba(0,0,0,0.03) inset, 0 10px 22px rgba(46, 158, 245, 0.14), 0 2px 4px rgba(36, 49, 63, 0.06);
  --shadow-raised-sm: 0 1px 0 #FFFFFF inset, 0 4px 10px rgba(46, 158, 245, 0.12), 0 1px 2px rgba(36, 49, 63, 0.05);
  --shadow-pressed: inset 0 2px 5px rgba(36, 49, 63, 0.16), inset 0 -1px 0 rgba(255,255,255,0.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: linear-gradient(180deg, #F4FAFF 0%, #FFFFFF 260px, #FFFFFF 100%);
  overflow-x: hidden;
}

* { scrollbar-width: thin; scrollbar-color: var(--sky-light) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--sky-light); border-radius: 10px; }
*::-webkit-scrollbar-thumb:hover { background: var(--sky); }

button { font-family: var(--font-body); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 2px;
}

.surface {
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-raised);
}

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  gap: 20px;
  padding: 20px;
}

.sidebar {
  border-radius: var(--radius);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: calc(100vh - 40px);
  position: sticky;
  top: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  box-shadow: 0 6px 14px rgba(46, 158, 245, 0.35);
}
.brand-text { display: flex; flex-direction: column; }
.brand h1 {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.5px;
  line-height: 1.1;
}
.brand-tagline {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  font-weight: 600;
}

.btn-add {
  background: linear-gradient(180deg, var(--sky-light) 0%, var(--sky) 55%, var(--sky-deep) 100%);
  border: 1px solid var(--sky-deep);
  color: #FFFFFF;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  padding: 13px 16px;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.5) inset, 0 6px 14px rgba(28, 126, 214, 0.4), 0 2px 3px rgba(28, 126, 214, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-add span { font-size: 18px; }
.btn-add:hover { transform: translateY(-2px); box-shadow: 0 1px 0 rgba(255,255,255,0.5) inset, 0 10px 20px rgba(28, 126, 214, 0.45), 0 3px 5px rgba(28, 126, 214, 0.3); }
.btn-add:active { transform: translateY(1px); box-shadow: var(--shadow-pressed); }

.nav-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 1px solid transparent;
  padding: 11px 12px;
  border-radius: 12px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.nav-item:hover { background: var(--sky-pale); }
.nav-item:hover .nav-emoji { transform: scale(1.15); }
.nav-emoji { font-size: 17px; display: inline-block; transition: transform 0.15s ease; }
.nav-item.active {
  background: var(--white);
  color: var(--sky-deep);
  border-color: var(--line);
  box-shadow: var(--shadow-raised-sm);
}
.count {
  margin-left: auto;
  background: rgba(46, 158, 245, 0.1);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
}
.nav-item.active .count {
  background: var(--sky);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  text-align: center;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.clock {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0;
  color: var(--sky-deep);
}
.today-date {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.topbar {
  border-radius: 16px;
  padding: 14px 18px;
  display: flex;
  gap: 14px;
  align-items: center;
}
.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow-pressed);
}
.search-icon { font-size: 15px; }
#searchInput {
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--font-body);
  font-size: 14.5px;
  color: var(--ink);
  width: 100%;
}
#searchInput::placeholder { color: var(--ink-soft); }

.sort-wrap select {
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 10px 12px;
  border-radius: 12px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
  outline: none;
  box-shadow: var(--shadow-raised-sm);
}

.content-header h2 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 4px;
  color: var(--ink);
}
.muted { color: var(--ink-soft); font-size: 14px; margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  margin-top: 18px;
}
#skeletonGrid.hide, #cardGrid.hide { display: none; }

.card {
  border-radius: 18px;
  padding: 18px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 5px solid var(--sky);
  box-shadow: var(--shadow-raised);
  animation: cardIn 0.35s ease;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 1px 0 #fff inset, 0 16px 30px rgba(46,158,245,0.22), 0 3px 6px rgba(36,49,63,0.08); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.card.type-diary { border-left-color: var(--sky-deep); }
.card.type-note { border-left-color: var(--sky-light); }
.card.type-reminder { border-left-color: var(--red); }
.card.overdue { border-left-color: var(--red-deep); box-shadow: 0 0 0 2px rgba(255,92,92,0.25), var(--shadow-raised); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.card-tag-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.card-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--sky-pale);
  color: var(--sky-deep);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.card-tag-html {
  font-size: 10.5px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(255, 92, 92, 0.12);
  color: var(--red-deep);
  letter-spacing: 0.4px;
}
.card-title {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0;
  color: var(--ink);
  word-break: break-word;
}
.card-mood { font-size: 18px; }
.card-content {
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  white-space: pre-wrap;
}
.card-content-html {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  max-height: 130px;
  overflow: auto;
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.card-content-html * { max-width: 100%; }
.card-content-html::-webkit-scrollbar { width: 6px; }
.card-content-html::-webkit-scrollbar-thumb { background: var(--sky-light); border-radius: 10px; }
.card-date {
  font-size: 11.5px;
  color: var(--ink-soft);
  opacity: 0.85;
}
.card-reminder-time {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--red-deep);
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
  padding-top: 6px;
}
.icon-btn {
  border: 1px solid var(--line);
  background: var(--paper);
  width: 30px;
  height: 30px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-raised-sm);
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.icon-btn:hover { background: var(--white); transform: translateY(-1px); }
.icon-btn:active { box-shadow: var(--shadow-pressed); transform: translateY(0); }
.icon-btn.fav.active { color: #FFB020; }

.skeleton-card {
  border-left-color: var(--line);
  cursor: default;
  pointer-events: none;
}
.sk {
  border-radius: 8px;
  background: linear-gradient(90deg, #EAF2FA 25%, #F6FAFF 37%, #EAF2FA 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.sk-tag { width: 70px; height: 18px; border-radius: 20px; }
.sk-title { width: 70%; height: 20px; margin-top: 6px; }
.sk-line { width: 100%; height: 12px; }
.sk-line.short { width: 85%; }
.sk-line.shorter { width: 55%; }
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.empty-state {
  display: none;
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
}
.empty-state.show { display: block; }
.empty-emoji { font-size: 48px; display: block; margin-bottom: 10px; }
.empty-state h3 { font-family: var(--font-display); color: var(--ink); margin: 0 0 6px; }
.btn-add-small {
  margin-top: 14px;
  background: linear-gradient(180deg, var(--sky-light), var(--sky-deep));
  color: #fff;
  border: 1px solid var(--sky-deep);
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-raised-sm);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 49, 63, 0.32);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay.show { display: flex; }

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 22px;
  padding: 24px;
  background: var(--white);
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-head h3 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 20px;
}
.modal-close {
  border: 1px solid var(--line);
  background: var(--paper);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  box-shadow: var(--shadow-raised-sm);
}

.type-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.type-tab {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--paper);
  padding: 10px 6px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-soft);
  box-shadow: var(--shadow-raised-sm);
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.type-tab.active {
  background: linear-gradient(180deg, var(--sky-light), var(--sky-deep));
  color: #fff;
  border-color: var(--sky-deep);
  box-shadow: var(--shadow-pressed);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.field input[type="text"],
.field input[type="datetime-local"],
.field textarea {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  outline: none;
  resize: vertical;
  box-shadow: var(--shadow-pressed);
}
.field input:focus, .field textarea:focus {
  border-color: var(--sky);
}

.mood-row {
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.mood-options {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.mood-btn {
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 20px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-raised-sm);
}
.mood-btn.selected { border-color: var(--sky); background: var(--white); box-shadow: var(--shadow-pressed); }

#dateField.hidden { display: none; }

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-pressed);
}
.checkbox-field input[type="checkbox"] {
  margin-top: 3px;
  width: 17px;
  height: 17px;
  accent-color: var(--sky);
  cursor: pointer;
  flex-shrink: 0;
}
.checkbox-field span {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.checkbox-field small {
  font-weight: 500;
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.4;
}
.checkbox-field.hidden { display: none; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}
.btn-secondary, .btn-primary {
  border: 1px solid var(--line);
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font-body);
  box-shadow: var(--shadow-raised-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-secondary {
  background: var(--paper);
  color: var(--ink);
}
.btn-primary {
  background: linear-gradient(180deg, var(--sky-light), var(--sky-deep));
  color: #fff;
  border-color: var(--sky-deep);
}
.btn-secondary:active, .btn-primary:active { box-shadow: var(--shadow-pressed); transform: translateY(1px); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #EAF5FF;
  padding: 12px 22px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.reminder-alert {
  position: fixed;
  inset: 0;
  background: rgba(36, 49, 63, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.reminder-alert.show { display: flex; }
.reminder-alert-box {
  background: var(--white);
  border-radius: 22px;
  padding: 30px;
  text-align: center;
  max-width: 360px;
  animation: modalIn 0.3s ease;
}
.reminder-alert-emoji {
  font-size: 44px;
  display: block;
  animation: ring 0.6s ease infinite;
}
@keyframes ring {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(12deg); }
  75% { transform: rotate(-12deg); }
}
.reminder-alert-box h3 { font-family: var(--font-display); margin: 10px 0 6px; }
.reminder-alert-box p { color: var(--ink-soft); margin: 0 0 18px; font-size: 14px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    height: auto;
    position: relative;
    top: 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .nav-filters { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { display: none; }
  .brand { width: 100%; }
}

@media (max-width: 480px) {
  .app { padding: 12px; gap: 12px; }
  .grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
}
