:root {
  --main: #5b6abf;
  --main-dark: #47539c;
  --bg: #f6f5f2;
  --card: #fff;
  --line: #ddd9d2;
  --text: #2a2a2a;
  --sub: #777;
  --danger: #c0392b;
  --tabs: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; }
body { padding-bottom: calc(var(--tabs) + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; background: var(--main); color: #fff; padding: 12px 16px; }
.top h1 { margin: 0; font-size: 20px; }
main { max-width: 720px; margin: 0 auto; padding: 12px 12px 90px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips.pick { flex-wrap: wrap; overflow: visible; }
.chip { flex: none; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 999px; padding: 7px 14px; font-size: 15px; }
.chip.active { background: var(--main); border-color: var(--main); color: #fff; }
.chip .n { opacity: .7; font-size: 12px; margin-left: 3px; }
.filters { margin-bottom: 4px; }
.filters .chips { padding-bottom: 6px; }
.filters .chips.sub .chip { padding: 4px 11px; font-size: 13px; }
.sheet h3 .small { font-weight: normal; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 12px; aspect-ratio: 1; padding: 6px; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.tile img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tile .cat { position: absolute; left: 4px; bottom: 4px; font-size: 11px; background: rgba(255,255,255,.85); border-radius: 6px; padding: 1px 5px; color: var(--sub); }
.grid.outfits { grid-template-columns: repeat(2, 1fr); }
.outfit-tile { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.outfit-tile img { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; display: block; background: #fff; }
.outfit-tile .name { padding: 6px 8px; font-size: 14px; border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--sub); margin: 48px 0; line-height: 1.8; }

.add-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs) + env(safe-area-inset-bottom)); display: flex; gap: 10px; justify-content: center; padding: 10px; background: linear-gradient(transparent, var(--bg) 30%); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 12px; padding: 12px 18px; font-size: 16px; cursor: pointer; font-family: inherit; }
.btn.primary { background: var(--main); border-color: var(--main); color: #fff; font-weight: bold; }
.btn.primary:active { background: var(--main-dark); }
.btn.danger { color: var(--danger); border-color: #e8b4ae; }
.btn:disabled { opacity: .45; }
.small-btn { padding: 8px 10px; font-size: 14px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; height: calc(var(--tabs) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: #fff; border-top: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--sub); font-family: inherit; }
.tabs button b { font-size: 22px; font-weight: normal; filter: grayscale(1); opacity: .6; }
.tabs button.active { color: var(--main); font-weight: bold; }
.tabs button.active b { filter: none; opacity: 1; }

.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 17px; margin: 0 0 6px; }
.card p { line-height: 1.7; margin: 6px 0 10px; }
.card .btn { margin: 4px 6px 4px 0; }
.small { font-size: 13px; color: var(--sub); line-height: 1.6; }

.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet-body { background: var(--bg); width: 100%; max-width: 720px; max-height: 94vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet.full .sheet-body { max-height: 100vh; height: 100%; border-radius: 0; }
.sheet h2 { margin: 0 0 10px; font-size: 18px; }
.sheet h3 { margin: 14px 0 6px; font-size: 15px; }
.sheet input[type=text] { width: 100%; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-family: inherit; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.actions .danger { margin-right: auto; }

.preview { height: 42vh; border-radius: 12px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.checker { background-color: #fff; background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }
.status { margin: 10px 0 0; }
.status p { margin: 0 0 6px; font-size: 14px; line-height: 1.6; }
.bar { height: 6px; background: #e4e1da; border-radius: 3px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--main); transition: width .2s; }
.seg { display: flex; margin-top: 10px; border: 1px solid var(--main); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; color: var(--main); padding: 9px; font-size: 15px; font-family: inherit; }
.seg button.active { background: var(--main); color: #fff; }
.seg button small { display: block; font-size: 11px; opacity: .8; }
.recut-btn { width: 100%; margin-top: 10px; }
.recut-area { position: relative; touch-action: none; user-select: none; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #fff; line-height: 0; text-align: center; }
.recut-area canvas { max-width: 100%; max-height: 50vh; touch-action: none; }
.recut-frame { position: absolute; border: 3px dashed var(--main); background: rgba(91,106,191,.12); box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
#recut-clear { margin-top: 8px; }

.board { position: relative; width: 100%; max-width: 420px; margin: 10px auto 6px; aspect-ratio: 3 / 4; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; touch-action: none; }
.board .piece { position: absolute; transform: translate(-50%, -50%); user-select: none; -webkit-user-drag: none; touch-action: none; }
.board .piece.selected { outline: 2px dashed var(--main); outline-offset: 2px; }
.tools { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.tools.off .btn { opacity: .4; pointer-events: none; }
.hint { text-align: center; margin: 6px 0; }
.picker { display: grid; grid-auto-flow: column; grid-auto-columns: 76px; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.picker .tile { height: 76px; padding: 4px; }
.picker .tile.used { border-color: var(--main); box-shadow: inset 0 0 0 2px var(--main); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabs) + 80px); transform: translateX(-50%); z-index: 30; background: rgba(30,30,30,.9); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; max-width: 90vw; }
