:root {
  --bg: #faf7f4;
  --card: #ffffff;
  --text: #222;
  --sub: #777;
  --line: #e6e0da;
  --accent: #e8590c;
  --accent-soft: #fff0e6;
  --star: #f5a623;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --card: #221f1c;
    --text: #eee;
    --sub: #a29a92;
    --line: #3a3530;
    --accent: #ff7a2e;
    --accent-soft: #3a2618;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 0; background: none; color: var(--text);
  font-size: 26px; width: 40px; height: 40px; line-height: 1; cursor: pointer;
}

main { max-width: 640px; margin: 0 auto; padding: 14px 16px; }
h2 { font-size: 17px; margin: 24px 0 6px; }
.hint { color: var(--sub); font-size: 14px; margin: 6px 0; }
.note { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.empty { text-align: center; color: var(--sub); margin-top: 60px; }

input, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
label, .field { display: block; margin: 12px 0; font-size: 14px; color: var(--sub); }
label > input, label > textarea { margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 15px; text-decoration: none; white-space: nowrap;
  color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.full { width: 100%; margin: 10px 0; }
.btn.danger { color: #d63c3c; }
.link-btn { display: block; margin: 16px auto; background: none; border: 0; color: var(--sub); text-decoration: underline; font: inherit; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.row input { flex: 1; min-width: 0; }
.row.wrap { flex-wrap: wrap; }

.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big-btn {
  margin: 0; display: flex; align-items: center; justify-content: center;
  height: 84px; border-radius: 14px; cursor: pointer;
  background: var(--card); border: 1px dashed var(--accent); color: var(--text); font-size: 16px;
}
.thumbs { display: flex; gap: 8px; overflow-x: auto; margin: 12px 0; }
.thumbs:empty { display: none; }
.thumb { position: relative; flex: 0 0 auto; }
.thumb img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; display: block; }
.thumb button {
  position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 24px; padding: 0; cursor: pointer;
}
.add-photo { display: inline-block; margin: 0 0 4px; color: var(--accent); cursor: pointer; }

.place {
  display: block; width: 100%; text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; margin: 8px 0;
}
.place b { font-size: 16px; }
.place small { display: block; color: var(--sub); font-size: 13px; }
.guess { border: 2px solid var(--accent); border-radius: 14px; padding: 14px; background: var(--card); }
.guess .q { margin: 0 0 4px; color: var(--sub); font-size: 14px; }
.guess .nm { font-size: 20px; font-weight: 700; }
.guess .row .btn { flex: 1; }

.lookup { background: var(--accent-soft); border-radius: 12px; padding: 8px 12px 4px; margin: 16px 0; }

.rating { display: flex; gap: 2px; margin-top: 2px; }
.rating button { background: none; border: 0; font-size: 30px; line-height: 1; color: var(--line); cursor: pointer; padding: 2px; }
.rating button.on { color: var(--star); }

.card {
  display: flex; gap: 12px; align-items: center; cursor: pointer;
  background: var(--card); border-radius: 14px; padding: 10px; margin: 10px 0;
  border: 1px solid var(--line);
}
.card img, .card .noimg { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex: 0 0 auto; background: var(--accent-soft); }
.card .noimg { display: flex; align-items: center; justify-content: center; font-size: 28px; }
.card .info { min-width: 0; flex: 1; }
.card .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { color: var(--sub); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stars { color: var(--star); letter-spacing: 1px; font-size: 14px; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px; }
.gallery img { height: 260px; max-width: 88%; object-fit: cover; border-radius: 14px; scroll-snap-align: center; flex: 0 0 auto; }
.d-name { font-size: 24px; margin: 14px 0 0; }
.d-sub { color: var(--sub); font-size: 14px; }
.d-rows { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin: 14px 0; }
.d-row { display: flex; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); }
.d-row:first-child { border-top: 0; }
.d-row .k { flex: 0 0 64px; color: var(--sub); font-size: 14px; }
.d-row .v { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-all; }
.d-row a { color: var(--accent); }
.d-memo { white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }

.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: none; font: inherit; font-size: 15px; color: var(--sub); padding: 7px; border-radius: 9px; cursor: pointer; }
.tabs button.on { background: var(--accent); color: #fff; font-weight: 700; }

.cal-head { display: flex; align-items: center; justify-content: space-between; text-align: center; }
.cal-title { display: flex; align-items: center; justify-content: center; font-size: 21px; font-weight: 700; }
.cal-title select {
  appearance: none; -webkit-appearance: none; border: 0; background: none; color: var(--text);
  font: inherit; padding: 2px 4px; border-radius: 8px; cursor: pointer; text-align: center;
  border-bottom: 2px dotted var(--accent);
}
.cal-title select:focus { outline: 2px solid var(--accent); }
.cal-title span { margin-right: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two label { margin: 12px 0; }
.cal-head .hint { margin: 0; font-size: 13px; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.cal-week { font-size: 12px; color: var(--sub); margin: 10px 0 4px; }
.cal-week span:first-child { color: #e03131; }
.cal-week span:last-child { color: #1c7ed6; }
.cal-grid { row-gap: 6px; touch-action: pan-y; }
.cal-cell {
  position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font: inherit; font-size: 14px; color: var(--text); background: none; border: 0; padding: 0;
}
.cal-cell.other { visibility: hidden; }
.cal-cell.today > .num { color: var(--accent); font-weight: 700; }
.cal-cell.has { cursor: pointer; }
.cal-cell .circ {
  position: absolute; inset: 7%; border-radius: 50%; overflow: hidden;
  border: 2px solid var(--accent); background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.cal-cell .circ img { width: 100%; height: 100%; object-fit: cover; }
.cal-cell.has > .num {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  color: #fff; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,.8);
}
.cal-cell.sel .circ { border-width: 3px; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.cal-cell .badge {
  position: absolute; right: 2%; top: 2%; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 4px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; font-weight: 700;
}
#cal-day h3 { font-size: 15px; margin: 18px 0 0; }
#cal-day .hint { margin: 2px 0 6px; font-size: 13px; }
.crown { margin-right: 4px; }
.feat-btn {
  flex: 0 0 auto; align-self: center; font: inherit; font-size: 13px; cursor: pointer;
  padding: 6px 10px; border-radius: 16px; border: 1px solid var(--accent);
  background: none; color: var(--accent);
}
.feat-btn.on { background: var(--accent); color: #fff; font-weight: 700; }
.feat-big { border-color: var(--accent); color: var(--accent); }
.feat-big.on { background: var(--accent-soft); font-weight: 700; }
.feat-big small { font-size: 12px; opacity: .8; margin-left: 4px; }

.fab {
  position: fixed; right: 20px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 34px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer;
}
.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(30,30,30,.92); color: #fff; padding: 10px 16px; border-radius: 20px;
  font-size: 14px; max-width: 90vw; text-align: center; z-index: 50;
}
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
