:root {
  --bg: #14161c; --panel: #1d2029; --panel2: #262a35; --line: #333846;
  --text: #e8e9ee; --muted: #9aa0b0; --accent: #c9a24a; --err: #ef5b5b; --warn: #e9b949; --ok: #4cc27a;
  --deck-w: 380px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: #1a1406; border-color: var(--accent); font-weight: 700; }
input[type=search], input[type=password], input:not([type]), select, textarea {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.hint { color: var(--muted); font-size: 12px; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: #101217; border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; white-space: nowrap; }
.brand span { color: var(--accent); }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs button { border: none; background: none; color: var(--muted); padding: 8px 12px; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom: 2px solid var(--accent); border-radius: 0; }

.view { display: none; }
.view.on { display: block; }
#build.on { display: grid; grid-template-columns: 1fr var(--deck-w); grid-template-rows: auto 1fr; height: calc(100vh - 50px); }
#build.on > .gallery-pane, #build.on > .deck-pane { grid-row: 2; min-height: 0; }

.gallery-pane { overflow-y: auto; padding: 12px 16px 80px; }
.filters { display: grid; gap: 8px; margin-bottom: 12px; position: sticky; top: -12px; z-index: 5;
  background: var(--bg); padding: 12px 0 8px; }
.filters input[type=search] { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.chip.on { background: var(--accent); color: #1a1406; border-color: var(--accent); }
.chip .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.row.end { justify-content: flex-end; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { position: relative; border-radius: 10px; overflow: hidden; background: var(--panel); cursor: pointer;
  transition: transform .08s; }
.tile:hover { transform: translateY(-2px); }
.tile img { width: 100%; display: block; aspect-ratio: 744/1039; object-fit: cover; background: #0c0d11; }
.tile.wide img { aspect-ratio: 1039/744; }
.tile .cnt { position: absolute; top: 6px; right: 6px; background: var(--accent); color: #1a1406;
  font-weight: 800; border-radius: 999px; min-width: 26px; height: 26px; display: grid; place-items: center; }
.tile .own { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.7); font-size: 11px;
  padding: 2px 7px; border-radius: 999px; }
.tile .cap { padding: 5px 8px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .btns { position: absolute; bottom: 30px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .1s; }
.tile:hover .btns { opacity: 1; }
.tile .btns button { padding: 2px 10px; font-weight: 800; background: rgba(0,0,0,.75); }
.tile.off { opacity: .35; }

.deck-pane { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px 14px 80px; }
.deck-head { display: grid; gap: 8px; }
.deck-head input { width: 100%; font-weight: 700; font-size: 16px; }
.deck-actions { display: flex; gap: 6px; }
.validation { margin: 10px 0; display: grid; gap: 4px; font-size: 13px; }
.validation .error { color: var(--err); }
.validation .warn { color: var(--warn); }
.validation .ok { color: var(--ok); font-weight: 700; }
.stats { display: grid; gap: 8px; margin-bottom: 10px; }
.curve { display: flex; align-items: flex-end; gap: 4px; height: 70px; padding-top: 14px; }
.curve div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; position: relative; min-height: 2px; }
.curve div span { position: absolute; top: -15px; width: 100%; text-align: center; font-size: 10px; color: var(--muted); }
.curve-x { display: flex; gap: 4px; font-size: 10px; color: var(--muted); }
.curve-x span { flex: 1; text-align: center; }
.kv { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.kv b { color: var(--text); }

.deck-list h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.dl-row { display: grid; grid-template-columns: 26px 30px 1fr auto; align-items: center; gap: 6px;
  padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.dl-row:hover { background: var(--panel2); }
.dl-row .n { font-weight: 800; color: var(--accent); text-align: right; }
.dl-row .c { font-size: 11px; text-align: center; background: var(--panel2); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
.dl-row .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-row .nm.miss { color: var(--warn); }
.dl-row .ctl { display: flex; gap: 2px; }
.dl-row .ctl button { padding: 0 7px; font-size: 12px; }
.slot { border: 1px dashed var(--line); border-radius: 8px; padding: 8px; color: var(--muted); font-size: 13px; }

.deck-toggle { display: none; }

.decks-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 0; }
.deck-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; padding: 16px; }
.dcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.dcard img { width: 100%; height: 150px; object-fit: cover; object-position: top; display: block; }
.dcard .body { padding: 10px 12px; display: grid; gap: 6px; }
.dcard .row button { padding: 4px 10px; }
.soon { max-width: 560px; margin: 60px auto; text-align: center; color: var(--muted); }
.soon h2 { color: var(--text); }

.an-wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.an-wrap h2 { margin: 4px 0 14px; }
.an-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.an-form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.an-form select { min-width: 180px; }
.progress { position: relative; height: 22px; background: var(--panel2); border-radius: 999px; margin: 14px 0; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.an-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 14px; }
.wr-bar { display: flex; height: 34px; border-radius: 8px; overflow: hidden; font-weight: 800; margin: 8px 0 12px; }
.wr-bar div { display: grid; place-items: center; min-width: 40px; }
.wr-bar .a { background: var(--accent); color: #1a1406; }
.wr-bar .b { background: #4b5263; }
.an-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.an-table th, .an-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: center; }
.an-table th:first-child, .an-table td:first-child { text-align: left; }
.an-table .hi { color: var(--ok); font-weight: 700; }
.an-table .lo { color: var(--err); }
.an-log { max-height: 320px; overflow: auto; font: 12px/1.5 Consolas, monospace; background: #0e1015; padding: 10px; border-radius: 8px; white-space: pre-wrap; }
.an-note { margin-top: 18px; }
@media (max-width: 860px) { .an-form select { min-width: 140px; } .an-table { font-size: 12px; } }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 0; max-width: min(860px, 94vw); width: 100%; }
dialog::backdrop { background: rgba(0,0,0,.65); }
#textDlg form { padding: 16px; display: grid; gap: 10px; }
#textDlg textarea { width: 100%; font-family: Consolas, monospace; font-size: 13px; }
.det { display: grid; grid-template-columns: minmax(220px, 340px) 1fr; gap: 18px; padding: 18px; }
.det img { width: 100%; border-radius: 12px; }
.det h3 { margin: 0 0 2px; font-size: 20px; }
.det .en { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.det .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag { background: var(--panel2); border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.det .txt { background: var(--panel2); border-radius: 10px; padding: 12px; white-space: pre-wrap; line-height: 1.7; }
.det .txt.en { color: var(--muted); font-size: 13px; }
.det .add-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.det .close { position: absolute; top: 8px; right: 10px; border: none; background: none; font-size: 22px; }
.kw { color: var(--accent); font-weight: 700; }
.ic-e { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  background: #eee; color: #111; font-size: 11px; font-weight: 800; vertical-align: -3px; }
.ic-r { display: inline-block; width: 14px; height: 14px; border-radius: 3px; transform: rotate(45deg) scale(.8); vertical-align: -2px; }
.ic-r.rainbow { background: conic-gradient(#d9463b, #e08a2c, #d6b82f, #3fa45b, #3b7bd9, #8e4fd1, #d9463b); }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000c; padding: 10px 18px;
  border-radius: 999px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
#toast.on { opacity: 1; }

@media (max-width: 860px) {
  .top { flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 10px 0; }
  #build.on { display: block; height: auto; }
  .gallery-pane { padding: 8px 10px 90px; overflow: visible; }
  /* 폰에서는 필터를 고정하지 않는다 — 고정하면 화면 절반을 덮고 첫 줄 카드를 가린다 */
  .filters { position: static; padding: 4px 0; gap: 6px; }
  .chip { padding: 3px 9px; font-size: 12px; }
  .row { gap: 8px; font-size: 13px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .tile .btns { opacity: 1; bottom: 26px; }
  .deck-pane { position: fixed; inset: 70px 0 0 0; z-index: 15; border: none; transform: translateY(100%);
    transition: transform .2s; }
  .deck-pane.open { transform: none; }
  .deck-toggle { display: block; position: fixed; right: 12px; bottom: 16px; z-index: 16; background: var(--accent);
    color: #1a1406; font-weight: 800; border-radius: 999px; padding: 12px 18px; box-shadow: 0 4px 16px #0008; }
  .det { grid-template-columns: 1fr; padding: 14px; }
  .det img { max-width: 300px; margin: 0 auto; }
}


/* ---------- 모바일 편의 (2026-10-01 점검) ---------- */
@media (max-width: 860px) {
  /* 터치 영역 최소 36~40px */
  .chip { min-height: 36px; padding: 6px 12px; font-size: 13px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .row label { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; }
  .row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
  .tile .btns button { min-width: 36px; min-height: 34px; font-size: 16px; }
  .dl-row { grid-template-columns: 26px 26px 1fr auto; padding: 5px 4px; }
  .dl-row .ctl button { min-width: 36px; min-height: 34px; font-size: 15px; }
  .dcard .row button { min-height: 40px; flex: 1; }
  .deck-actions button { min-height: 40px; flex: 1; }
  /* 카드 상세: 그림은 작게, 버튼은 아래에 고정 */
  .det img { max-width: 58%; }
  .det .add-row { position: sticky; bottom: -14px; background: var(--panel); padding: 10px 0 12px; margin-top: 10px; z-index: 2; }
  .det .add-row button { min-height: 44px; flex: 1; font-size: 15px; }
  dialog { max-height: 88vh; overflow: auto; }
  .det .close { top: 6px; right: 6px; width: 40px; height: 40px; background: #000a; border-radius: 50%; z-index: 3; }
  /* 분석·대전 설정 폼: 2열 그리드, 실행 버튼은 가로 전체 */
  .an-wrap { padding: 12px; }
  .an-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .an-form select { min-width: 0; width: 100%; min-height: 42px; }
  .an-form button { grid-column: 1 / -1; min-height: 46px; font-size: 16px; }
  .an-table { font-size: 12px; }
  .an-table th, .an-table td { padding: 6px 4px; }
  .tabs button { padding: 10px 12px; font-size: 15px; }
}

/* 로그인 사용자 */
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.who span { color: var(--text, #e8eaf0); font-weight: 700; }
.owner { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: #ffffff14; color: var(--muted); vertical-align: 2px; }
@media (max-width: 860px) { .who { position: absolute; right: 10px; top: 4px; font-size: 12px; gap: 4px; } .who button { min-height: 32px; padding: 0 8px; } }

/* 덱 수정 상태 */
.deck-mode { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 18px; }
.deck-mode.dirty b { color: var(--warn); }
.deck-mode .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
#saveDeck:disabled { opacity: .55; cursor: default; }

/* 수정 막대: PC는 화면 위, 폰은 화면 아래 고정 */
.edit-bar { grid-column: 1 / -1; grid-row: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap;
  padding: 10px 16px; background: #2a2416; border-bottom: 2px solid var(--accent); }
.edit-bar.dirty { background: #33230f; border-bottom-color: var(--warn); }
.edit-bar.shared { background: #1d2433; border-bottom-color: #5b8def; }
.edit-bar[hidden] { display: none; }
.eb-text { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.eb-tag { font-size: 12px; font-weight: 800; letter-spacing: .04em; padding: 3px 9px; border-radius: 999px; background: var(--accent); color: #1a1406; flex: none; }
.edit-bar.shared .eb-tag { background: #5b8def; color: #fff; }
.edit-bar.new .eb-tag { background: var(--panel2); color: var(--text); }
#ebName { font-size: 16px; overflow-wrap: anywhere; }
.eb-dirty { color: var(--warn); font-weight: 800; font-size: 13px; }
#ebHint { color: var(--muted); font-size: 12.5px; }
.eb-actions { display: flex; gap: 8px; flex: none; }
.eb-actions button { min-height: 38px; }
.eb-actions button:disabled { opacity: .5; cursor: default; }
.deck-mode { display: none; }
@media (max-width: 860px) {
  .edit-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 17; border-bottom: none; border-top: 2px solid var(--accent);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)); gap: 6px 10px; }
  .edit-bar.dirty { border-top-color: var(--warn); }
  .edit-bar.shared { border-top-color: #5b8def; }
  #ebName { font-size: 14px; }
  #ebHint { display: none; }
  .eb-actions { width: 100%; }
  .eb-actions button { flex: 1; min-height: 42px; }
  body.editing .deck-toggle { bottom: 118px; }
  body.editing .gallery-pane { padding-bottom: 190px; }
  body.editing .deck-pane { bottom: 104px; }
  body.editing #toast { bottom: 128px; }
}
