/* ===== 基礎 ===== */

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

/* hidden 屬性永遠優先於任何 display 設定 */
[hidden] { display: none !important; }

:root {
  --bg: #f7f3ee;
  --card: #ffffff;
  --ink: #3b3530;
  --ink-soft: #8d8378;
  --accent: #c96f4a;
  --accent-soft: #f3ddd2;
  --line: #e7ded4;
  --danger: #c0392b;
  --tab-h: 56px;
}

html, body { height: 100%; }

body {
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll { overflow: hidden; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

input, select, textarea {
  font: inherit;
  color: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

/* ===== 頁首 ===== */

.page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 14px 14px 8px;
  border-bottom: 1px solid var(--line);
}

.page-header h1 {
  font-size: 20px;
  margin-bottom: 10px;
}

#search-input { margin-bottom: 10px; }

/* ===== 分類籤 ===== */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--ink-soft);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ===== 衣櫥格狀清單 ===== */

.item-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 14px;
}

.item-card {
  position: relative;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(60, 50, 40, .08);
  display: flex;
  flex-direction: column;
  text-align: left;
}

.item-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.item-name {
  font-size: 13px;
  padding: 6px 8px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-cat {
  font-size: 11px;
  color: var(--ink-soft);
  padding: 0 8px 8px;
}

.view-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 10px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  padding: 2px 6px;
  border-radius: 999px;
}

.empty-hint {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 24px;
  font-size: 15px;
}

/* ===== 浮動新增鈕、底部分頁 ===== */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(201, 111, 74, .45);
  z-index: 20;
}

.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 30;
}

.tab {
  flex: 1;
  font-size: 15px;
  color: var(--ink-soft);
}

.tab.active {
  color: var(--accent);
  font-weight: 600;
}

/* ===== 衣物編輯視窗 ===== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 25, .45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-photo {
  /* 淺灰棋盤格：去背後的透明區與白色貼紙邊才看得出來 */
  background:
    repeating-conic-gradient(#f1ece5 0% 25%, #ffffff 0% 50%)
    0 0 / 20px 20px;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  max-height: 36vh;
}

.modal-photo img {
  max-width: 100%;
  max-height: 36vh;
  object-fit: contain;
  display: block;
}

.photo-empty {
  color: var(--ink-soft);
  font-size: 14px;
}

.view-tabs {
  display: flex;
  gap: 6px;
}

.view-tab {
  flex: 1;
  padding: 8px 0;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-soft);
}

.view-tab.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.photo-actions {
  display: flex;
  gap: 8px;
}

.modal-sheet label {
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.btn {
  flex: 1;
  padding: 11px 0;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 15px;
}

.btn.small { padding: 8px 10px; font-size: 13px; flex: 1; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); flex: 0 0 auto; padding: 11px 16px; }
.danger-text { color: var(--danger); }

/* ===== 貼紙書編輯器 ===== */

.editor {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 40;
  display: flex;
  flex-direction: column;
}

.editor-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.editor-bar input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
}

.bar-btn {
  flex: 0 0 auto;
  font-size: 18px;
  padding: 8px 10px;
  border-radius: 10px;
}

.bar-btn.save {
  font-size: 15px;
  background: var(--accent);
  color: #fff;
}

#stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
}

#stage {
  /* 寬高由 board.js 的 fitStage() 依可用空間計算，固定 3:4 */
  position: relative;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(60, 50, 40, .12);
  touch-action: none;
  overflow: hidden;
}

.sticker {
  position: absolute;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.sticker img {
  width: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  /* 陰影沿著去背輪廓走，更有貼紙感 */
  filter: drop-shadow(0 2px 4px rgba(60, 50, 40, .22));
}

.sticker.selected {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.handle {
  position: absolute;
  right: -16px;
  bottom: -16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  touch-action: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

#sticker-toolbar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  visibility: hidden; /* 永遠佔位，選取貼紙時才顯示 */
}

#sticker-toolbar.show { visibility: visible; }

#sticker-toolbar button {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 13px;
}

#tray {
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
}

#tray .chips { margin-bottom: 6px; }

#tray-items {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
#tray-items::-webkit-scrollbar { display: none; }

.tray-item {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  padding: 0;
}

.tray-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tray-empty {
  color: var(--ink-soft);
  font-size: 13px;
  padding: 20px 8px;
}

/* ===== 穿搭簿 ===== */

.board-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 12px 14px;
}

.board-card {
  position: relative;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(60, 50, 40, .08);
  cursor: pointer;
}

.board-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}

.board-name {
  display: block;
  padding: 8px 10px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  font-size: 13px;
}

/* ===== 提示訊息 ===== */

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom));
  background: rgba(40, 32, 25, .88);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

/* 桌機上置中、限制寬度，方便在電腦整理 */
@media (min-width: 700px) {
  #closet-page, #boards-page { max-width: 640px; margin: 0 auto; }
  .item-grid { grid-template-columns: repeat(4, 1fr); }
  .board-grid { grid-template-columns: repeat(3, 1fr); }
}
