/* ── CSS 변수 (다크 기본) ── */
:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0d0d1a;
  --border: #0f3460;
  --text: #e0e0e0;
  --text-menu: #c0c0e0;
  --text-muted: #aaa;
  --accent: #e94560;
  --minus-bg: #0f3460;
  --result-color: #ffffff;
  --cat-delete-bg: transparent;
  --cat-delete-color: #aaa;
}

body.light {
  --bg: #f4f5f7;
  --bg-card: #ffffff;
  --bg-input: #e8eaf0;
  --border: #d8dce8;
  --text: #1a1a2e;
  --text-menu: #2a2a50;
  --text-muted: #999;
  --accent: #e94560;
  --minus-bg: #e0e3ef;
  --result-color: #1a1a2e;
  --cat-delete-bg: transparent;
  --cat-delete-color: #999;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Apple SD Gothic Neo', sans-serif;
  min-height: 100vh;
  padding-bottom: 100px;
  transition: background-color 0.25s, color 0.25s;
}

/* ── 헤더 ── */
header {
  background-color: var(--bg-card);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  transition: background-color 0.25s, border-color 0.25s;
}

.header-spacer { width: 44px; }

.header-center { text-align: center; }

header h1 {
  font-size: 1.4rem;
  color: var(--accent);
  letter-spacing: 2px;
}

header p {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-theme {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.1s;
}

.btn-theme:active { opacity: 0.5; }

/* ── 메인 ── */
main {
  padding: 16px;
  max-width: 480px;
  margin: 0 auto;
}

/* ── 분류 섹션 ── */
.category-section { margin-bottom: 20px; }

/* ── 카테고리 헤더 & 카드 상단 바 공통 구조 ── */
.category-header,
.card-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 10px;
}

.category-header {
  padding: 4px 6px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: background-color 0.25s, border-color 0.25s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── 아코디언 콘텐츠 래퍼 ── */
.category-content {
  overflow: hidden;
  transition: max-height 0.3s ease-in-out;
}

/* ── 토글 아이콘 ── */
.toggle-icon {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--accent);
  margin-left: 5px;
  transition: transform 0.3s ease-in-out;
  vertical-align: middle;
}

/* 접힌 상태 — 아이콘 -90도 회전 */
.category-header.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

/* ── 드래그 & 더보기 버튼 공통 ── */
.btn-drag,
.btn-more {
  width: 32px;
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s;
  flex-shrink: 0;
}

.btn-drag {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.btn-drag:active { cursor: grabbing; color: var(--accent); }
.btn-more:active { color: var(--accent); }

/* ── 가운데 텍스트 ── */
.title-text {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 1px;
}

.title-text.category-title { color: var(--accent); }
.title-text.item-title { color: var(--text-menu); }

/* ── 더보기 버튼 래퍼 (팝업 기준점) ── */
.more-wrapper {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── 팝업 메뉴 ── */
.popup-menu {
  display: flex;
  gap: 4px;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background-color: rgba(255, 255, 255, 0.12);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  opacity: 0;
  transform: scaleY(0) translateY(-4px);
  transform-origin: top right;
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
}

body.light .popup-menu {
  background-color: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.popup-menu.visible {
  opacity: 1;
  transform: scaleY(1) translateY(0);
  pointer-events: auto;
}

.btn-popup-edit,
.btn-popup-delete {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 6px 8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.btn-popup-edit:active,
.btn-popup-delete:active {
  color: #e0e0e0;
  transform: scale(0.95);
}

body.light .btn-popup-edit,
body.light .btn-popup-delete {
  color: #e94560;
}

body.light .btn-popup-edit:active,
body.light .btn-popup-delete:active {
  color: #ff6b85;
}

/* ── 아이템 그리드 ── */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
}

/* ── 반응형: 480px 이하 (모바일) ── */
@media (max-width: 480px) {
  main {
    padding: 12px;
  }

  .action-bar {
    padding: 12px 12px;
  }

  .card {
    padding: 10px 10px 12px;
  }

  .menu-grid {
    gap: 10px;
  }

  .btn-count {
    width: 48px;
    height: 48px;
    font-size: 1.3rem;
  }

  .count-display {
    font-size: 1.8rem;
    min-width: 28px;
  }

  .counter-row {
    gap: 8px;
  }
}

/* ── 품목 카드 ── */
.card {
  width: 100%;
  max-width: 100%;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
  transition: background-color 0.25s, border-color 0.25s;
  overflow: hidden;
}

.counter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.btn-count {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-count:active { transform: scale(0.90); opacity: 0.75; }

.btn-minus { background-color: var(--minus-bg); color: var(--text); }
.btn-plus  { background-color: var(--accent);   color: #fff; }

.count-display {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  min-width: 32px;
  text-align: center;
  line-height: 1;
}

/* ── 품목 추가 버튼 ── */
.btn-add-item {
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  background: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s;
}

.btn-add-item:active { border-color: var(--accent); color: var(--accent); }

/* ── 분류 추가 버튼 ── */
.btn-add-cat {
  width: 100%;
  padding: 14px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: none;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 20px;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.1s;
}

.btn-add-cat:active { opacity: 0.6; }

/* ── 결과 텍스트 ── */
.result-section { margin-bottom: 20px; }

.result-section label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.result-box {
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  min-height: 56px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--result-color);
  word-break: break-all;
  letter-spacing: 1px;
  transition: background-color 0.25s, border-color 0.25s;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-box.placeholder {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
}

/* ── 결과 래퍼 & 복사 버튼 ── */
.result-wrapper {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.result-box {
  flex: 1;
}

.btn-result-copy {
  width: 50px;
  height: auto;
  min-height: 56px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background-color: var(--bg-input);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, opacity 0.1s, background-color 0.25s, border-color 0.25s, color 0.25s;
  flex-shrink: 0;
}

body.light .btn-result-copy {
  color: #1a1a2e;
}

.btn-result-copy svg {
  display: block;
  transition: opacity 0.2s;
}

.btn-result-copy .copy-text {
  color: #4ade80;
  font-weight: 700;
  font-size: 1.2rem;
}

.btn-result-copy:active {
  transform: scale(0.95);
  opacity: 0.8;
}

.btn-result-copy.copied svg {
  opacity: 0;
  display: none;
}

.btn-result-copy:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── 하단 고정 바 ── */
.action-bar-wrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 10;
  transition: background-color 0.25s, border-color 0.25s;
}

.action-bar {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  padding: 12px 16px;
}

.btn-action {
  flex: 1;
  height: 52px;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-action:active { transform: scale(0.97); opacity: 0.8; }

.btn-copy  { background-color: var(--accent); color: #fff; }
.btn-reset { background-color: var(--minus-bg); color: var(--text); }

/* ── 모달 ── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 100;
  animation: fadeIn 0.15s ease-out;
}

.modal-overlay.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 101;
  display: none;
  animation: slideUp 0.2s ease-out;
}

.modal.active { display: block; }

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, -40%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.modal-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  max-width: 90vw;
  width: 320px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transition: background-color 0.25s, border-color 0.25s;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  text-align: center;
  letter-spacing: 0.5px;
}

.modal-message {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 20px;
  text-align: center;
  line-height: 1.5;
  white-space: pre-line;
}

.modal-input-field {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 18px;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.modal-input-field:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-input-field::placeholder {
  color: var(--text-muted);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.5px;
}

.modal-btn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

.modal-btn-cancel {
  background-color: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.modal-btn-confirm {
  background-color: var(--accent);
  color: #fff;
}

/* ── 드래그 앤 드롭 고스트 ── */
.sortable-ghost {
  opacity: 0.4;
  background-color: var(--accent);
  border-color: var(--accent);
}

.sortable-ghost .card {
  opacity: 0.5;
}
