:root {
  --bg: #111318;
  --surface: #1b1e26;
  --surface-2: #242833;
  --border: #2f3441;
  --text: #e8eaf0;
  --muted: #8b91a3;
  --primary: #6c7cff;
  --primary-2: #5563e6;
  --danger: #ff5d6c;
  --success: #3ecf8e;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 15px; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: .9em; }
.error { color: var(--danger); margin: 8px 0 0; font-size: .9em; }
.ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---- auth ---- */
.auth-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 24px; }
.auth-card h1 { margin: 0 0 12px; font-size: 1.4rem; }
.qr { background: #fff; border-radius: 12px; padding: 12px; margin: 12px auto; width: 220px; }
.qr svg { width: 100%; height: auto; display: block; }
details { margin: 8px 0 12px; font-size: .85em; color: var(--muted); }
details code { word-break: break-all; display: block; margin-top: 6px; color: var(--text); }

/* ---- form controls ---- */
label { display: block; margin: 12px 0 0; font-size: .9em; color: var(--muted); }
label.check, label.toggle { display: flex; align-items: center; gap: 8px; color: var(--text); }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; margin-top: 6px; padding: 11px 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; outline: none; color: var(--text); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; line-height: 1.5; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px;
  border-radius: 10px; border: 1px solid transparent; background: var(--surface-2); cursor: pointer;
  white-space: nowrap; transition: background .15s; }
.btn:hover { background: var(--border); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; margin-top: 16px; }
.btn.small { padding: 7px 12px; font-size: .85em; }
.btn.danger { background: transparent; border-color: var(--border); color: var(--danger); }
.btn.danger:hover { background: rgba(255,93,108,.12); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: transparent; border: none; color: var(--text); font-size: 1.25rem; width: 40px; height: 40px;
  border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.danger { color: var(--danger); }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row-end { display: flex; gap: 12px; justify-content: flex-end; align-items: center; margin-top: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two-col label.check { margin-top: 30px; }
.two-col > div > label { margin-top: 12px; }

/* ---- layout ---- */
.view { padding-bottom: calc(80px + var(--safe-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: calc(10px + var(--safe-top)) 12px 10px; background: rgba(17,19,24,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); }
.topbar h1 { flex: 1; margin: 0 6px; font-size: 1.2rem; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
@media (max-width: 639px) {
  .pc-only { display: none !important; }
  .list-tools { padding: 6px 10px; gap: 6px; flex-wrap: wrap; }
  .list-tools-right { gap: 6px; margin-left: auto; }
  #list-count { display: none; }
  .chips { gap: 3px; }
  .chip { padding: 4px 8px; font-size: .75em; }
  .sort-select { font-size: .75em; padding: 4px 22px 4px 6px; background-position: right 6px center; }
  .view-btn { width: 30px; height: 26px; font-size: .85rem; }
}
.modal-card.wide { max-width: 860px; }
.import-summary { margin-top: 12px; font-size: .9em; display: flex; gap: 14px; flex-wrap: wrap; }
.import-summary .ok { color: var(--success); }
.import-summary .bad { color: var(--danger); }
.table-wrap { margin-top: 10px; overflow: auto; max-height: 45vh; border: 1px solid var(--border); border-radius: 10px; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: .82em; white-space: nowrap; }
.table-wrap th, .table-wrap td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.table-wrap th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.table-wrap tr.err td { background: rgba(255,93,108,.08); }
.table-wrap tr.skip td { color: var(--muted); }
.table-wrap td.msg { color: var(--danger); white-space: normal; min-width: 180px; }
.tabs { display: flex; gap: 6px; padding: 10px 12px 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: transparent;
  color: var(--muted); cursor: pointer; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.list-tools { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px; }
.chips { display: flex; gap: 4px; }
.chip { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--muted);
  font-size: .8em; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--surface-2); border-color: var(--text); color: var(--text); }
.list-tools-right { display: flex; align-items: center; gap: 10px; }
.sort-select { width: auto; margin: 0; padding: 4px 26px 4px 8px; font-size: .8em; border-radius: 8px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text); appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%238b91a3' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat; background-position: right 8px center; }
.view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.view-btn { background: transparent; border: none; color: var(--muted); width: 34px; height: 28px; cursor: pointer; font-size: .95rem; }
.view-btn.active { background: var(--surface-2); color: var(--text); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; line-height: 1.7; }

/* ---- cards ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; padding: 8px 12px; }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; cursor: pointer; transition: transform .1s, border-color .15s; }
.card:hover { border-color: var(--primary); }
.card:active { transform: scale(.98); }
.card.completed { opacity: .75; }
.thumb { aspect-ratio: 2 / 3; background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 2rem; overflow: hidden; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 10px; display: flex; flex-direction: column; gap: 5px; }
.card-title { font-weight: 600; font-size: .95rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.card-sub { display: flex; align-items: center; gap: 6px; font-size: .78em; color: var(--muted); flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: .75em; background: var(--surface-2);
  color: var(--muted); }
.badge.type { color: var(--text); }
.badge.done { background: rgba(62,207,142,.15); color: var(--success); }
.badge.doing { background: rgba(108,124,255,.15); color: var(--primary); }
.badge.todo { background: rgba(139,145,163,.18); color: var(--muted); }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 4px; }
.episode { font-variant-numeric: tabular-nums; font-weight: 600; }
.episode .total { color: var(--muted); font-weight: 400; }
.reaction { font-size: .95em; line-height: 1; }
.reaction-line { font-size: 1rem; }
.seg { display: inline-flex; margin-top: 6px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; width: 100%; }
.seg button { flex: 1; padding: 9px 0; background: var(--surface-2); border: none; color: var(--muted); cursor: pointer; font-size: .95em; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--primary); color: #fff; }
.step-group { display: inline-flex; gap: 4px; }
.step { min-width: 40px; height: 34px; padding: 0 10px; border-radius: 9px; border: none; font-weight: 700; cursor: pointer;
  font-variant-numeric: tabular-nums; }
.step.plus { background: var(--primary); color: #fff; }
.step.plus:hover { background: var(--primary-2); }
.step.minus { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.step.minus:hover { background: var(--border); color: var(--text); }
.step:disabled { opacity: .4; cursor: default; }
.check-icon { color: var(--success); font-size: 1.2rem; width: 44px; text-align: center; }
.link-icon { color: var(--muted); font-size: .9em; }
.link-icon:hover { color: var(--primary); }

/* ---- list rows ---- */
.rows { display: flex; flex-direction: column; gap: 6px; padding: 6px 10px; }
.row-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; min-height: 60px; }
.row-item:hover { border-color: var(--primary); }
.row-item.completed { opacity: .7; }
.thumb.small { width: 38px; height: 52px; aspect-ratio: auto; flex: none; border-radius: 6px; font-size: 1.1rem; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-title { font-weight: 600; font-size: .92rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-item .card-sub { flex-wrap: nowrap; overflow: hidden; }
.row-item .episode { font-size: .9rem; white-space: nowrap; }
.row-item .step { min-width: 34px; height: 30px; padding: 0 6px; font-size: .85em; }
.row-item .check-icon { width: 34px; }

/* ---- mobile grid density ---- */
@media (max-width: 639px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 6px 8px; }
  .thumb { aspect-ratio: 3 / 4; font-size: 1.5rem; }
  .card-body { padding: 7px 7px 8px; gap: 3px; }
  .card-title { font-size: .82rem; -webkit-line-clamp: 1; min-height: 1.3em; }
  .card-sub { font-size: .7em; gap: 4px; }
  .badge { padding: 1px 5px; }
  .card .episode { font-size: .85rem; }
  .card .step { min-width: 28px; height: 26px; padding: 0 5px; font-size: .78em; border-radius: 7px; }
  .card .step-group { gap: 3px; }
  .card .check-icon { width: 28px; font-size: 1rem; }
  .card-foot { gap: 4px; flex-wrap: wrap; }
  .card .step-group, .card .check-icon { margin-left: auto; }
}

.fab { position: fixed; right: 20px; bottom: calc(20px + var(--safe-bottom)); width: 56px; height: 56px;
  border-radius: 50%; border: none; background: var(--primary); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 20px rgba(108,124,255,.45); cursor: pointer; z-index: 6; }
.fab:hover { background: var(--primary-2); }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal { align-items: center; } }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-card { position: relative; width: 100%; max-width: 520px; max-height: calc(100vh - 24px); background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px 18px 0 0; display: flex; flex-direction: column; }
@media (min-width: 640px) { .modal-card { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 0; }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 4px 16px 12px; overflow-y: auto; }
.spacer { flex: 1; }
.modal-foot { display: flex; gap: 10px; align-items: center; padding: 12px 16px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border); }
.paste-zone { margin-top: 6px; min-height: 120px; border: 2px dashed var(--border); border-radius: 12px; display: flex;
  align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: .85em; padding: 12px;
  cursor: pointer; outline: none; overflow: hidden; }
.paste-zone:focus { border-color: var(--primary); color: var(--text); }
.paste-zone img { max-height: 220px; max-width: 100%; border-radius: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; z-index: 30;
  font-size: .9em; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.error { border-color: var(--danger); color: var(--danger); }
