
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Crimson+Text:ital,wght@0,400;0,600;1,400;1,600&display=swap');

:root {
  --bg:        #1a1410;
  --bg2:       #211c16;
  --bg3:       #2a231b;
  --bg4:       #332b20;
  --border:    #4a3d2a;
  --border2:   #5c4d36;
  --text:      #e8dcc8;
  --text2:     #b8a88a;
  --text3:     #7a6a52;
  --accent:    #c9973a;
  --accent2:   #e8b84b;
  --low:       #4a9e6b;
  --medium:    #c9973a;
  --high:      #c0392b;
  --sidebar-w: 260px;
  --detail-w:  360px;
  --radius:    4px;
  --font-body:    'Crimson Text', Georgia, serif;
  --font-display: 'Cinzel', 'Times New Roman', serif;

  /* parchment texture via repeating gradient */
  --parchment: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 28px,
    rgba(255,255,255,0.012) 28px,
    rgba(255,255,255,0.012) 29px
  );
}

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
}

ul { list-style: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }

/* ── Layout ─────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  background: var(--bg2);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* aged wood grain on sidebar */
.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--parchment);
  pointer-events: none;
  opacity: 0.4;
}

.sidebar-top {
  padding: 28px 20px 20px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.logo-mark {
  font-size: 28px;
  color: var(--accent);
  display: block;
  line-height: 1;
  text-shadow: 0 0 20px rgba(201,151,58,0.4);
}

.logo-text {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.15em;
  color: var(--accent2);
  text-transform: uppercase;
}

.logo-subtitle {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 12px;
  color: var(--text3);
  letter-spacing: 0.05em;
}

.sidebar-section {
  flex: 1;
  padding: 20px 14px;
  overflow-y: auto;
  position: relative;
}

.sidebar-section::-webkit-scrollbar { width: 4px; }
.sidebar-section::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.sidebar-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--border), transparent);
}

.project-list { display: flex; flex-direction: column; gap: 2px; }

.project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  position: relative;
  border: 1px solid transparent;
}

.project-item:hover { background: var(--bg3); border-color: var(--border); }
.project-item.active {
  background: var(--bg3);
  border-color: var(--border2);
}
.project-item.active .project-name { color: var(--accent2); font-weight: 600; }

.project-dot {
  width: 8px;
  height: 8px;
  border-radius: 1px;
  flex-shrink: 0;
  transform: rotate(45deg);
}

.project-name {
  flex: 1;
  color: var(--text2);
  font-size: 15px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-count {
  font-size: 11px;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--accent);
  background: var(--bg4);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 2px;
}

.delete-project {
  opacity: 0;
  color: var(--text3);
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 2px;
  transition: opacity 0.15s, color 0.15s;
  position: absolute;
  right: 6px;
}
.project-item:hover .delete-project { opacity: 1; }
.delete-project:hover { color: var(--high); }

.btn-new-project {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text3);
  font-size: 14px;
  font-style: italic;
  font-family: var(--font-body);
  border-radius: var(--radius);
  width: 100%;
  text-align: left;
  margin-top: 6px;
  transition: color 0.15s, background 0.15s;
  border: 1px dashed var(--border);
}
.btn-new-project:hover { color: var(--accent); border-color: var(--accent); background: var(--bg3); }
.btn-new-project span { font-size: 18px; font-style: normal; }

.sidebar-bottom {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  position: relative;
}

/* decorative corner flourish */
.sidebar-bottom::before {
  content: '✦';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--accent);
  background: var(--bg2);
  padding: 0 8px;
}

.stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-num {
  font-size: 26px;
  font-family: var(--font-display);
  color: var(--accent2);
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  font-family: var(--font-display);
  color: var(--text3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.stat-divider {
  width: 1px;
  height: 32px;
  background: var(--border2);
}

/* ── Main ───────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: var(--bg);
  background-image: var(--parchment);
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 40px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

/* decorative header rule */
.main-header::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 40px;
  right: 40px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--accent), transparent);
  opacity: 0.4;
}

.main-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent2);
  text-transform: uppercase;
  position: relative;
}

.main-title::before {
  content: '⚔ ';
  font-size: 20px;
  color: var(--accent);
  vertical-align: middle;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, #a67828 100%);
  color: #1a1410;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--accent2);
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(201,151,58,0.2), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(201,151,58,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-primary:active { transform: translateY(0); }

.todo-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 40px 48px;
}

.todo-container::-webkit-scrollbar { width: 6px; }
.todo-container::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── Todo List ──────────────────────────────────────────── */
.todo-ul { display: flex; flex-direction: column; gap: 6px; }

.todo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
  overflow: hidden;
}

/* priority left bar */
.todo-item::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
}

.todo-item.priority-low::before    { background: var(--low); }
.todo-item.priority-medium::before { background: var(--medium); }
.todo-item.priority-high::before   { background: var(--high); }

.todo-item:hover { border-color: var(--border2); background: var(--bg3); }
.todo-item.selected { border-color: var(--accent); background: var(--bg3); }
.todo-item.completed { opacity: 0.45; }
.todo-item.completed .todo-title { text-decoration: line-through; color: var(--text3); }

.todo-check {
  width: 22px;
  height: 22px;
  border-radius: 2px;
  border: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  color: transparent;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  transform: rotate(45deg);
}
.todo-check:hover { border-color: var(--accent); }
.todo-check.checked {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1410;
}

.todo-body { flex: 1; min-width: 0; }

.todo-main { display: flex; align-items: center; gap: 8px; }

.todo-title {
  font-size: 16px;
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delete-todo {
  opacity: 0;
  color: var(--text3);
  font-size: 18px;
  padding: 2px 6px;
  border-radius: 2px;
  line-height: 1;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}
.todo-item:hover .delete-todo { opacity: 1; }
.delete-todo:hover { color: var(--high); }

.section-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text3);
  font-weight: 600;
  padding: 20px 4px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-label::before,
.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border), transparent);
}

/* ── Empty State ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text3);
}
.empty-icon {
  font-size: 48px;
  margin-bottom: 20px;
  color: var(--border2);
}
.empty-state p {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--text2);
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}
.empty-state small { font-size: 14px; font-style: italic; }
.empty-state strong { color: var(--accent); }

/* ── Detail Panel ───────────────────────────────────────── */
.detail-panel {
  width: 0;
  overflow: hidden;
  border-left: 2px solid var(--border);
  background: var(--bg2);
  transition: width 0.25s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  position: relative;
}

.detail-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--parchment);
  pointer-events: none;
  opacity: 0.3;
}

.detail-panel.open {
  width: var(--detail-w);
  overflow-y: auto;
}

.detail-panel.open::-webkit-scrollbar { width: 4px; }
.detail-panel.open::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.detail-header {
  position: sticky;
  top: 0;
  background: var(--bg2);
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  flex-shrink: 0;
}

.detail-priority-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.detail-close {
  font-size: 20px;
  color: var(--text3);
  padding: 4px 8px;
  border-radius: 2px;
  transition: color 0.15s, background 0.15s;
}
.detail-close:hover { color: var(--text); background: var(--bg3); }

.detail-actions { display: flex; gap: 6px; }

.detail-body { padding: 20px 20px 36px; display: flex; flex-direction: column; gap: 18px; }

.detail-field { display: flex; flex-direction: column; gap: 6px; }
.detail-field label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.detail-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.detail-title-input {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.03em;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border2);
  color: var(--accent2);
  padding: 4px 0 8px;
  width: 100%;
  transition: border-color 0.15s;
}
.detail-title-input:focus { outline: none; border-color: var(--accent); }

.detail-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 15px;
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s;
}
.detail-input:focus { outline: none; border-color: var(--accent); }

.detail-textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--text);
  width: 100%;
  resize: vertical;
  min-height: 72px;
  transition: border-color 0.15s;
  line-height: 1.6;
}
.detail-textarea:focus { outline: none; border-color: var(--accent); }

.detail-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--text);
  width: 100%;
  appearance: none;
  cursor: pointer;
}
.detail-select:focus { outline: none; border-color: var(--accent); }

/* ── Checklist ──────────────────────────────────────────── */
.checklist { display: flex; flex-direction: column; gap: 6px; }

.checklist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: opacity 0.15s;
}
.checklist-item.done { opacity: 0.5; }
.checklist-item.done .check-text { text-decoration: line-through; color: var(--text3); }

.check-btn {
  width: 18px;
  height: 18px;
  border-radius: 1px;
  border: 1px solid var(--border2);
  font-size: 10px;
  color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transform: rotate(45deg);
  transition: all 0.15s;
}
.check-btn.checked { background: var(--accent); border-color: var(--accent); color: #1a1410; }
.check-btn:hover:not(.checked) { border-color: var(--accent); }

.check-text { flex: 1; font-size: 15px; color: var(--text2); font-style: italic; }

.remove-checklist-item {
  opacity: 0;
  color: var(--text3);
  font-size: 16px;
  padding: 1px 4px;
  border-radius: 2px;
  transition: opacity 0.15s, color 0.15s;
}
.checklist-item:hover .remove-checklist-item { opacity: 1; }
.remove-checklist-item:hover { color: var(--high); }

.checklist-add { display: flex; gap: 6px; margin-top: 4px; }
.checklist-add .detail-input { flex: 1; }

.btn-add-check {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 18px;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}
.btn-add-check:hover { background: var(--border2); border-color: var(--accent); color: var(--accent); }

.btn-save {
  background: linear-gradient(180deg, var(--accent) 0%, #a67828 100%);
  color: #1a1410;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 11px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--accent2);
  width: 100%;
  transition: opacity 0.15s;
  margin-top: 4px;
  box-shadow: 0 2px 8px rgba(201,151,58,0.2);
}
.btn-save:hover { opacity: 0.88; }

/* ── Modal ──────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal.open { display: flex; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(3px);
}

.modal-box {
  position: relative;
  z-index: 101;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 32px;
  width: 460px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: modalIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(201,151,58,0.15);
}

/* decorative top border on modal */
.modal-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--accent), transparent);
  border-radius: var(--radius) var(--radius) 0 0;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.modal-box h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent2);
}

.modal-field { display: flex; flex-direction: column; gap: 6px; }
.modal-field label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
}

.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

.btn-cancel {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: background 0.15s;
}
.btn-cancel:hover { background: var(--border2); }

/* ── Color Picker ───────────────────────────────────────── */
.color-picker { display: flex; gap: 10px; flex-wrap: wrap; }

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  transform: rotate(45deg);
  transition: transform 0.15s;
  border: 2px solid transparent;
}
.color-swatch:hover { transform: rotate(45deg) scale(1.2); }
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

/* ── Btn Icon ───────────────────────────────────────────── */
.btn-icon {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  transition: color 0.15s;
  line-height: 1;
  padding: 4px;
  border-radius: 2px;
  font-size: 16px;
}
.btn-icon:hover { color: var(--text); background: var(--bg3); }

/* ── Scrollbar global ───────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --detail-w: 300px; }
}
@media (max-width: 700px) {
  .app { grid-template-columns: 200px 1fr; }
  :root { --sidebar-w: 200px; --detail-w: 280px; }
  .detail-panel.open { position: fixed; right: 0; top: 0; bottom: 0; width: var(--detail-w); z-index: 50; }
}

@media (max-width: 480px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    height: auto;
    border-right: none;
    border-bottom: 2px solid var(--border);
  }

  .sidebar-section {
    display: none;
  }

  .sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
  }

  .logo {
    flex-direction: row;
    gap: 8px;
  }

  .sidebar-bottom {
    display: none;
  }

  .main-header {
    padding: 16px 20px;
  }

  .main-title {
    font-size: 18px;
  }

  .todo-container {
    padding: 16px 16px 48px;
  }

  .btn-primary {
    font-size: 11px;
    padding: 8px 14px;
  }

  .detail-panel.open {
    position: fixed;
    inset: 0;
    width: 100% !important;
    z-index: 50;
  }

  .todo-title {
    max-width: 200px;
  }
}