:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --sub: #4b5563;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --chip: #e0e7ff;
  --chip-text: #3730a3;
  --today: #fef3c7;
  --danger: #dc2626;
  --head: #f9fafb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #f3f4f6;
    --sub: #b6bcc6;
    --line: #2d323c;
    --accent: #3b82f6;
    --chip: #262f4d;
    --chip-text: #c7d2fe;
    --today: #3a3214;
    --danger: #f87171;
    --head: #20242c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Pretendard, "Malgun Gothic", system-ui, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text);
  font: inherit; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.busy { opacity: .5; pointer-events: none; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.small { min-height: 28px; padding: 0 8px; font-size: 13px; }
.spacer { flex: 1; }

/* 위 막대 */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 8px; align-items: center;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
@media (max-width: 440px) {
  .top { gap: 6px; padding: 8px 10px; }
  .top .btn { padding: 0 10px; }
}
.top select {
  flex: 0 1 auto; min-width: 0;
  min-height: 38px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; font-size: 15px;
}
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; right: 0; top: 44px; min-width: 170px;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}
.menu-body button, .menu-body a {
  padding: 12px 14px; border: 0; background: none; color: var(--text);
  font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.menu-body .ver { padding: 8px 14px; color: var(--sub); font-size: 12px; }

#status { margin: 10px 16px 0; padding: 10px 14px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); }
#status.err { color: var(--danger); }
#empty { margin: 40px 16px; color: var(--sub); text-align: center; }

/* 블럭 */
.board {
  display: grid; gap: 14px; padding: 14px 16px;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  align-items: start;
}
#doneBoard { padding-bottom: 60px; }
.done-head {
  margin: 10px 16px 0; padding-top: 12px; border-top: 2px solid var(--line);
  color: var(--sub); font-size: 15px; font-weight: 600;
}
@media (max-width: 440px) {
  .board { grid-template-columns: 1fr; padding: 12px 10px; gap: 12px; }
  .done-head { margin: 8px 10px 0; }
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px 14px;
}
/* 완료: 내용만 흐리게 - 체크 칸은 또렷하게 둬서 다시 풀기 쉽게 */
.card.dim > :not(.card-head), .card.dim .chip, .card.dim .card-head .btn { opacity: .3; }
.card.dim { background: var(--bg); }
.done-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; cursor: pointer; user-select: none;
}
.done-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.card.dim .done-toggle { border-color: var(--accent); color: var(--accent); }
.card.ghost { opacity: .4; outline: 2px dashed var(--accent); }
.card-head { display: flex; align-items: center; gap: 8px; }
.handle {
  cursor: grab; touch-action: none; user-select: none;
  padding: 6px 4px; margin-left: -4px; color: var(--sub); font-size: 20px; line-height: 1;
}
.chip { padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--chip-text); font-size: 13px; white-space: nowrap; }
.card h2 { margin: 6px 0 8px; font-size: 22px; line-height: 1.3; word-break: keep-all; }
.card-head .btn { min-height: 32px; padding: 0 10px; font-size: 14px; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 15px; }
.meta dt { color: var(--sub); }
.meta dd { margin: 0; }

.meals { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 15px; text-align: center; }
.meals th, .meals td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.meals th { background: var(--head); color: var(--sub); font-weight: 500; font-size: 13px; }
.meals td:first-child { text-align: left; white-space: nowrap; }
.meals tr.today td { background: var(--today); }
.meals td.num { font-weight: 600; font-variant-numeric: tabular-nums; }

.notes { margin: 10px 0 0; padding-left: 18px; font-size: 15px; line-height: 1.5; }

/* 수정 창 */
dialog {
  width: min(640px, calc(100vw - 20px)); max-height: calc(100vh - 20px);
  padding: 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h3 { margin: 0 0 12px; }
dialog h4 { display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 .wide { grid-column: span 2; }
dialog label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--sub); }
dialog input, dialog textarea {
  width: 100%; min-height: 34px; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 15px;
}
.meal-edit { width: 100%; border-collapse: collapse; }
.meal-edit th { font-size: 12px; color: var(--sub); font-weight: 500; }
.meal-edit td { padding: 2px; }
.meal-edit td:first-child { width: 34%; }
.dlg-actions { display: flex; gap: 8px; margin-top: 14px; }

/* 원본 보기 */
dialog.orig { width: calc(100vw - 20px); height: calc(100vh - 20px); padding: 0; display: none; flex-direction: column; }
dialog.orig[open] { display: flex; }
.orig-bar { display: flex; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); }
.orig-body { flex: 1; overflow: auto; }
.orig-body img { display: block; max-width: none; }

/* 검색 */
dialog.search { align-self: start; margin-top: 10px; }
.search-bar { display: flex; gap: 8px; }
.search-bar input { flex: 1; min-width: 0; min-height: 40px; font-size: 16px; }
.search-info { margin: 10px 2px 6px; color: var(--sub); font-size: 14px; }
.search-results { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; }
.search-results button {
  display: flex; flex-direction: column; gap: 2px; width: 100%;
  padding: 10px 8px; border: 0; border-bottom: 1px solid var(--line);
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.search-results button:hover { background: var(--head); }
.search-results .r-name { font-size: 17px; font-weight: 600; }
.search-results .r-sub { color: var(--sub); font-size: 14px; }
.card.flash { outline: 3px solid var(--accent); outline-offset: 2px; }

#dropHint {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(37, 99, 235, .15); border: 4px dashed var(--accent);
  font-size: 24px; pointer-events: none;
}
#dropHint[hidden] { display: none; }

/* 로그인 */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-box { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); }
.login-box h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.login-box input { min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; }
.err { color: var(--danger); text-align: center; }
.login-box input[readonly] { text-align: center; font-size: 22px; letter-spacing: 6px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 6px; }
.keypad[hidden] { display: none; }
.key {
  min-height: 60px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit; font-size: 24px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.key:active { background: var(--chip); }
.key.alt { font-size: 16px; color: var(--sub); }
