:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --raised: #FFFFFF;
  --label: #000000;
  --label-2: rgba(60, 60, 67, .6);
  --label-3: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .16);
  --fill: rgba(118, 118, 128, .12);
  --fill-2: rgba(120, 120, 128, .2);
  --tint: #007AFF;
  --tint-soft: rgba(0, 122, 255, .1);
  --red: #FF3B30;
  --green: #34C759;
  --bar: rgba(242, 242, 247, .72);
  --glass: rgba(255, 255, 255, .72);
  --glass-line: rgba(255, 255, 255, .6);
  --scrim: rgba(0, 0, 0, .3);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo", "Pretendard Variable", Pretendard, "Noto Sans KR", sans-serif;
  --spring: cubic-bezier(.32, .72, 0, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1C1C1E;
    --raised: #2C2C2E;
    --label: #FFFFFF;
    --label-2: rgba(235, 235, 245, .6);
    --label-3: rgba(235, 235, 245, .3);
    --sep: rgba(84, 84, 88, .5);
    --fill: rgba(118, 118, 128, .24);
    --fill-2: rgba(120, 120, 128, .36);
    --tint: #0A84FF;
    --tint-soft: rgba(10, 132, 255, .18);
    --red: #FF453A;
    --green: #30D158;
    --bar: rgba(0, 0, 0, .68);
    --glass: rgba(44, 44, 46, .72);
    --glass-line: rgba(255, 255, 255, .1);
    --scrim: rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--label);
  font: 400 17px/1.47 var(--font);
  letter-spacing: -.012em;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; }
svg { display: block; flex: none; }

#app { display: flex; height: 100dvh; }
.pane { height: 100dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
#list-pane { flex: 1 1 100%; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
#editor-pane { flex: 1 1 100%; display: none; }
body[data-view="editor"] #list-pane { display: none; }
body[data-view="editor"] #editor-pane { display: flex; flex-direction: column; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 50px; padding: 0 20px; border-radius: 14px;
  font-weight: 600; font-size: 17px; white-space: nowrap;
  transition: opacity .15s, transform .15s var(--spring);
}
.btn:active:not(:disabled) { opacity: .7; transform: scale(.98); }
.btn-solid { background: var(--tint); color: #fff; }
.btn-solid:disabled { background: var(--fill); color: var(--label-3); }
.btn-line { background: var(--fill); color: var(--tint); }
.btn-line:disabled { color: var(--label-3); }
.btn-danger { background: var(--fill); color: var(--red); }
.icon-btn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--tint); transition: opacity .15s; }
.icon-btn:active { opacity: .35; }

/* 목록 */
.list-head { padding: max(10px, env(safe-area-inset-top)) 20px 12px; }
.list-top { display: flex; justify-content: flex-end; min-height: 44px; margin: 0 -10px; }
.brand { margin: 0 0 10px; font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: -.022em; }
.search-wrap { position: relative; color: var(--label-2); }
.search-wrap svg { position: absolute; left: 9px; top: 9px; pointer-events: none; }
.search {
  width: 100%; height: 36px; padding: 0 12px 0 32px; font-size: 17px;
  background: var(--fill); border: 0; border-radius: 10px; outline: none; -webkit-appearance: none;
}
.search::placeholder { color: var(--label-2); }
.search::-webkit-search-cancel-button { -webkit-appearance: none; }

.group { margin: 0 16px; background: var(--card); border-radius: 12px; overflow: hidden; list-style: none; padding: 0; }
.group > li, .group > .cell { position: relative; }
.group > li + li::before, .group > .cell + .cell::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--sep); z-index: 1;
}
.rows { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 68px; transition: background-color .15s; }
.row:active { background: var(--fill-2); }
.row-text { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 17px; line-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { margin-top: 2px; font-size: 15px; line-height: 20px; color: var(--label-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { color: var(--label); margin-right: 8px; opacity: .85; }
.row-thumb { flex: none; width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: var(--fill); }
.list-empty { padding: 44px 24px; text-align: center; color: var(--label-2); font-size: 15px; }
.list-empty strong { display: block; margin-bottom: 4px; font-size: 20px; font-weight: 600; color: var(--label); letter-spacing: -.02em; }

.group-title { margin: 28px 32px 6px; font-size: 13px; line-height: 18px; color: var(--label-2); }
.foot-note { margin: 7px 32px 0; font-size: 13px; line-height: 18px; color: var(--label-2); }
.cell { display: flex; align-items: center; width: 100%; min-height: 44px; padding: 10px 16px; text-align: left; font-size: 17px; transition: background-color .15s; }
.cell:active:not(:disabled) { background: var(--fill-2); }
.cell:disabled { color: var(--label-3); }
.cell.tinted { color: var(--tint); }
.cell.danger { color: var(--red); }
.cell-value { margin-left: auto; padding-left: 12px; font-size: 17px; color: var(--label-2); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cell-value svg { color: var(--label-3); }

.hint { display: flex; gap: 12px; margin: 10px 16px 0; padding: 14px 16px; background: var(--card); border-radius: 12px; font-size: 15px; line-height: 20px; color: var(--label-2); }
.hint strong { display: block; margin-bottom: 2px; font-weight: 600; color: var(--label); }
.hint button { display: block; margin-top: 6px; color: var(--tint); font-size: 15px; }

/* 편집 화면 */
.ed-top {
  position: sticky; top: 0; z-index: 3; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: env(safe-area-inset-top) 6px 0; min-height: 44px;
  background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 .5px 0 var(--sep);
}
.back { display: inline-flex; align-items: center; justify-self: start; min-height: 44px; padding-right: 8px; color: var(--tint); font-size: 17px; transition: opacity .15s; }
.back:active { opacity: .35; }
.saved { font-size: 13px; color: var(--label-2); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-top .icon-btn { justify-self: end; }
.ed-body { flex: 1 0 auto; width: 100%; max-width: 680px; margin: 0 auto; padding: 16px 16px 24px; }
.ed-none { margin: auto; padding: 24px; text-align: center; color: var(--label-2); font-size: 17px; }
.ed-none strong { display: block; margin-bottom: 4px; font-size: 22px; font-weight: 600; color: var(--label); letter-spacing: -.02em; }

.sec { position: relative; padding: 14px 16px 8px; background: var(--card); border-radius: 20px; }
.sec + .sec, .add-thread { margin-top: 14px; }
.sec + .sec::before { content: ""; position: absolute; left: 26px; top: -14px; width: 2px; height: 14px; background: var(--fill-2); }
.sec-head { display: flex; align-items: center; justify-content: space-between; min-height: 24px; margin-bottom: 4px; }
.sec-head h2 { margin: 0; font-size: 15px; line-height: 20px; font-weight: 600; color: var(--label-2); letter-spacing: -.01em; }
.count { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; line-height: 18px; font-variant-numeric: tabular-nums; color: var(--label-2); }
.count.over { color: var(--red); font-weight: 600; }
.ring { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 2.5; }
.ring .track { stroke: var(--fill-2); }
.ring .value { stroke: var(--tint); stroke-linecap: round; transition: stroke-dashoffset .2s var(--spring); }
.count.near .ring .value { stroke: #FF9500; }
.count.over .ring .value { stroke: var(--red); }

.grow { display: grid; }
.grow::after { content: attr(data-v) " "; white-space: pre-wrap; overflow-wrap: anywhere; visibility: hidden; grid-area: 1 / 1; padding: 2px 0 10px; font-size: 17px; line-height: 25px; min-height: 62px; }
.grow textarea {
  grid-area: 1 / 1; width: 100%; padding: 2px 0 10px; border: 0; border-radius: 0; background: none; resize: none; overflow: hidden;
  font-size: 17px; line-height: 25px; overflow-wrap: anywhere; outline: none; caret-color: var(--tint); -webkit-appearance: none;
}
.grow textarea::placeholder { color: var(--label-3); }

/* X 사진: 여러 장은 옆으로 넘기기, 한 장은 원본 비율 */
.sec { container-type: inline-size; }
.strip {
  display: flex; gap: 6px; margin: 4px -16px 6px; padding: 0 16px; overflow-x: auto;
  scroll-snap-type: x proximity; scroll-padding: 0 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.strip::-webkit-scrollbar { display: none; }
.strip button { flex: none; position: relative; height: var(--h); border-radius: 14px; overflow: hidden; background: var(--fill); scroll-snap-align: start; }
.strip.solo { overflow: visible; }
.strip img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity .15s; }
.strip button:active img { opacity: .75; }

.sec-bar { display: flex; align-items: center; gap: 2px; margin: 0 -8px; min-height: 44px; }
.tool {
  display: inline-flex; align-items: center; gap: 5px; min-height: 44px; padding: 0 8px;
  color: var(--tint); font-size: 15px; font-weight: 500; white-space: nowrap; transition: opacity .15s;
}
.tool:active { opacity: .35; }
.tool small { font-size: 13px; font-weight: 400; color: var(--label-2); font-variant-numeric: tabular-nums; }
.tool.done { color: var(--green); }
.sec-bar .spacer { flex: 1; }

.add-thread { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 50px; background: var(--card); border-radius: 14px; color: var(--tint); font-size: 17px; font-weight: 500; transition: opacity .15s; }
.add-thread:active { opacity: .5; }

/* 떠 있는 유리 막대 */
.dock { position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 3; display: flex; justify-content: center; padding: 0 16px 10px; pointer-events: none; transition: opacity .2s, transform .3s var(--spring); }
.dock-glass {
  display: flex; padding: 4px; border-radius: 999px; pointer-events: auto;
  background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .14), 0 0 0 .5px var(--sep), inset 0 .5px 0 var(--glass-line);
}
.dock button { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 18px; border-radius: 999px; font-size: 15px; font-weight: 600; color: var(--label); white-space: nowrap; transition: background-color .15s; }
.dock button:active { background: var(--fill-2); }
body.typing .dock { opacity: 0; transform: translateY(16px); }
body.typing .dock-glass { pointer-events: none; }

/* 시트 */
dialog.sheet {
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; padding: 0; border: 0;
  border-radius: 28px 28px 0 0; background: var(--bg); color: var(--label); overflow: hidden;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: rise .42s var(--spring); }
dialog.sheet::backdrop { background: var(--scrim); animation: fade .3s ease; }
@keyframes rise { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.grabber { width: 36px; height: 5px; margin: 6px auto 0; border-radius: 3px; background: var(--fill-2); flex: none; }
.sheet-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; padding: 4px 10px 6px; flex: none; }
.sheet-head h3 { grid-column: 2; margin: 0; text-align: center; font-size: 17px; line-height: 22px; font-weight: 600; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.close-x { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; color: var(--label-2); }
.close-x span { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; background: var(--fill); }
.close-x:active { opacity: .5; }
.sheet-body { overflow-y: auto; padding: 6px 16px 16px; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.sheet-body .group { margin: 0; }
.sheet-foot { display: flex; flex-direction: column; gap: 8px; padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); flex: none; }
.sheet-foot .btn { width: 100%; }
.sheet-note { margin: 2px 4px 14px; font-size: 13px; line-height: 18px; color: var(--label-2); }

@media (min-width: 760px) {
  .pane { overscroll-behavior-y: auto; }
  #list-pane { display: block !important; flex: 0 0 340px; box-shadow: .5px 0 0 var(--sep); }
  #editor-pane { display: flex !important; flex-direction: column; flex: 1 1 auto; }
  .back { visibility: hidden; }
  .row[aria-current="page"] { background: var(--tint); color: #fff; }
  .row[aria-current="page"] .row-meta, .row[aria-current="page"] .row-time { color: rgba(255, 255, 255, .85); opacity: 1; }
  dialog.sheet { max-width: 540px; margin: auto; border-radius: 22px; max-height: 84dvh; }
  dialog.sheet[open] { animation: pop .34s var(--spring); }
  .grabber { visibility: hidden; height: 2px; }
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } }

.seg { position: relative; display: flex; padding: 2px; margin-bottom: 12px; background: var(--fill); border-radius: 9px; }
.seg button { flex: 1; min-height: 32px; border-radius: 7px; font-size: 13px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--raised); font-weight: 600; box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }

.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; }
.shot { margin: 0; }
.shot img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--fill); }
.shot figcaption { margin-top: 5px; font-size: 11px; line-height: 14px; color: var(--label-2); overflow-wrap: anywhere; }
.busy { grid-column: 1 / -1; padding: 36px 0; text-align: center; color: var(--label-2); font-size: 15px; }

.cap-preview { display: flex; flex-direction: column; gap: 10px; }
.cap-preview img { display: block; width: 100%; border-radius: 14px; box-shadow: 0 2px 16px rgba(0, 0, 0, .08); }
.check { margin-bottom: 14px; background: var(--card); border-radius: 12px; cursor: pointer; }
.switch { position: relative; flex: none; margin-left: auto; width: 51px; height: 31px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch i { display: block; width: 100%; height: 100%; border-radius: 16px; background: var(--fill-2); transition: background-color .22s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 3px 1px rgba(0, 0, 0, .06); transition: transform .28s var(--spring); }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--tint); outline-offset: 2px; }

.frame { position: relative; overflow: hidden; border-radius: 14px; background: var(--fill); touch-action: none; cursor: grab; margin-bottom: 8px; }
.frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; user-select: none; -webkit-user-select: none; }
.row-btns { display: flex; gap: 8px; }
.row-btns .btn { flex: 1; min-height: 44px; font-size: 15px; }

.code-input {
  width: 100%; height: 50px; padding: 0 14px; text-align: center; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .03em;
  background: var(--card); border: 0; border-radius: 12px; outline: none; -webkit-appearance: none;
}
.code-input::placeholder { color: var(--label-3); font-weight: 400; }
.code-show { margin: 0; padding: 16px; text-align: center; font-size: 19px; font-weight: 600; letter-spacing: .03em; font-variant-numeric: tabular-nums; background: var(--card); border-radius: 12px; user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; }

#toast {
  position: fixed; z-index: 2147483647; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px) scale(.96);
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); width: max-content; padding: 11px 18px;
  background: var(--glass); color: var(--label); border-radius: 999px; font-size: 15px; font-weight: 500;
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .16), 0 0 0 .5px var(--sep);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .35s var(--spring);
}
#toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); pointer-events: auto; }
#toast button { font-weight: 600; color: var(--tint); min-height: 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
