:root {
  --ground: #E4E5E7;
  --surface: #F5F5F6;
  --ink: #1B1C1F;
  --ink-2: #565A61;
  --line: #C9CBCF;
  --tag: #F5C518;
  --tag-ink: #1B1C1F;
  --tag-line: #8F7000;
  --danger: #B3261E;
  --urgent: #9C1C12;
  --spent: #CFD1D4;
  --shadow: 0 1px 2px rgba(27, 28, 31, .08), 0 6px 18px rgba(27, 28, 31, .06);
  --r-btn: 8px;
  --r-chip: 10px;
  --r-panel: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #1E1F22;
    --surface: #2A2B2F;
    --ink: #EDEEF0;
    --ink-2: #A9ADB4;
    --line: #45474D;
    --danger: #F2968F;
    --spent: #3A3C41;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 16px/1.55 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
h1 { font-size: 30px; line-height: 1.25; font-weight: 700; margin: 0 0 24px; letter-spacing: -.01em; }
h2 { font-size: 17px; line-height: 1.4; font-weight: 600; margin: 0; }
p { margin: 0; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button, label[for], .switch, a { touch-action: manipulation; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tag :focus-visible { outline-color: var(--tag-ink); }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.sr { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.hint, .sub { color: var(--ink-2); font-size: 14px; }
.err { color: var(--danger); font-size: 14px; }
.err:empty { display: none; }
.err:not(:empty) { margin-top: 6px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 20px; }
.brand .i { width: 22px; height: 22px; transform: rotate(-12deg); }

/* 입장 화면 */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 32px 16px; }
.gate-in { width: 100%; max-width: 620px; }
.gate h1 { margin: 40px 0 20px; }
.gate-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.door {
  display: grid; gap: 4px; justify-items: start; text-align: left;
  padding: 20px; min-height: 168px; align-content: end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel);
  box-shadow: var(--shadow); transition: border-color .15s;
}
.door:hover { border-color: var(--ink); }
.door .i { width: 26px; height: 26px; margin-bottom: auto; }
.door strong { font-size: 19px; font-weight: 600; }
.door span { color: var(--ink-2); font-size: 14px; }
.gate .hint { margin-top: 16px; }
@media (max-width: 480px) { .gate-choice { grid-template-columns: 1fr; } .door { min-height: 128px; } }

/* 뼈대 */
.app { min-height: 100dvh; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav .brand { display: none; }
.nav a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 58px; text-decoration: none; color: var(--ink-2); font-size: 13px; font-weight: 500;
}
.nav a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.nav a[aria-current="page"] .i { stroke-width: 2.25; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--tag); color: var(--tag-ink); border: 1px solid var(--tag-line);
  font-size: 12px; line-height: 18px; font-weight: 700; text-align: center;
}
.main { max-width: 680px; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top, 0px)) 16px calc(96px + env(safe-area-inset-bottom, 0px)); }

@media (min-width: 820px) {
  .nav {
    inset: 0 auto 0 0; width: 208px; display: flex; flex-direction: column; gap: 4px;
    padding: 28px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav .brand { display: flex; padding: 0 12px 24px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: var(--r-btn); font-size: 15px; }
  .nav a:hover { background: var(--ground); }
  .nav a[aria-current="page"] { background: var(--ground); }
  .badge { position: static; margin-left: auto; }
  .app { padding-left: 208px; }
  .main { padding-top: 44px; padding-bottom: 64px; }
}

/* 공통 컨트롤 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 16px; border-radius: var(--r-btn);
  background: transparent; border: 1px solid var(--line); text-decoration: none; font-weight: 500;
  transition: background-color .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:active:not(:disabled) { background: var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--ground); font-weight: 600; }
.btn.primary:active:not(:disabled) { background: var(--ink-2); }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn.danger { color: var(--danger); }
input[type=text], input[type=password], input[type=number] {
  width: 100%; min-height: 46px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-btn); font-size: 16px;
}
input:focus-visible { outline-offset: 0; }
input[aria-invalid=true] { border-color: var(--danger); }

.field { border: 0; margin: 24px 0 0; padding: 0; min-width: 0; }
.field legend, .field > label { display: block; padding: 0; margin-bottom: 8px; font-weight: 600; font-size: 15px; }

.seg { display: flex; gap: 8px; }
.seg.wrap { flex-wrap: wrap; }
.seg button {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 14px; border-radius: var(--r-chip);
  background: var(--surface); border: 1px solid var(--line); font-size: 15px; font-weight: 500;
}
.seg:not(.wrap) button { flex: 1; justify-content: center; }
.seg button:hover { border-color: var(--ink); }
.seg button[aria-pressed=true] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 700; }
.ttl-custom { display: flex; gap: 12px; margin-top: 10px; max-width: 280px; }
.ttl-custom label { flex: 1; font-size: 14px; color: var(--ink-2); }

/* 파일 고르기 */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 188px; padding: 24px; text-align: center; cursor: pointer;
  background: var(--surface); border: 1.5px dashed var(--ink-2); border-radius: var(--r-panel);
  transition: background-color .15s;
}
.drop .i { width: 28px; height: 28px; margin-bottom: 6px; }
.drop strong { font-size: 19px; font-weight: 600; }
.drop span { color: var(--ink-2); font-size: 14px; }
.drop:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.drop.over, body.dragging .drop { background: var(--tag); color: var(--tag-ink); border-color: var(--tag-ink); }
body.dragging .drop span { color: var(--tag-ink); }
@media (hover: none) { .only-fine { display: none; } .drop { min-height: 148px; } }

.picked {
  display: flex; align-items: center; gap: 12px; padding: 12px 8px 12px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); box-shadow: var(--shadow);
}
.picked .meta { flex: 1; min-width: 0; }
.picked .name { font-weight: 600; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border: 0; background: none; border-radius: var(--r-btn); }
.icon-btn:hover { background: var(--ground); }
#directNote { margin-top: 8px; }

.peers { display: flex; flex-wrap: wrap; gap: 8px; }
.peer {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px;
  background: none; border: 1px solid var(--line); border-radius: var(--r-chip); font-size: 14px;
}
button.peer { min-height: 44px; }
button.peer:hover { border-color: var(--ink); }
.peer .i { width: 16px; height: 16px; }

.sendbar { margin-top: 28px; }
.sendbar .btn { width: 100%; min-height: 52px; font-size: 17px; }
.progress { margin-top: 28px; }
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-weight: 500; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; transform: scaleX(0); transform-origin: left; background: var(--ink); transition: transform .2s linear; }

.notice { display: grid; gap: 12px; justify-items: start; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); }

/* 보낸 기록 */
.record { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line); }
.record h2 { margin-bottom: 10px; }
.record .line { display: flex; gap: 10px; align-items: center; }
.record .meta { min-width: 0; flex: 1; }
.record .name { font-weight: 600; }
.stamps { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.stamp {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 2px 10px;
  border: 1px dashed var(--line); border-radius: var(--r-chip); color: var(--ink-2); font-size: 14px;
}
.stamp .i { width: 16px; height: 16px; }
.stamp.on { border: 1px solid var(--ink); color: var(--ink); font-weight: 600; }
.record .hint { margin-top: 10px; }

/* 보관함: 받은 파일 꼬리표 */
#boxList { display: grid; gap: 20px; }
.tag {
  position: relative; color: var(--tag-ink); background: var(--tag);
  border-radius: var(--r-panel); box-shadow: var(--shadow);
  clip-path: polygon(34px 0, 100% 0, 100% 100%, 34px 100%, 0 calc(100% - 34px), 0 34px);
  -webkit-mask: radial-gradient(circle 9px at 30px 50%, transparent 98%, #000 100%);
  mask: radial-gradient(circle 9px at 30px 50%, transparent 98%, #000 100%);
  padding: 20px 20px 16px 58px;
}
.tag .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; font-size: 14px; font-weight: 500; }
.tag .via { display: inline-flex; align-items: center; gap: 6px; }
.tag .via .i { width: 16px; height: 16px; }
.tag .clock { margin-top: 10px; font-size: clamp(44px, 12vw, 64px); line-height: 1.05; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tag .clock-note { display: flex; align-items: center; gap: 6px; min-height: 24px; font-size: 14px; font-weight: 500; }
.tag .clock-note .i { width: 16px; height: 16px; }
.tag.urgent .clock, .tag.urgent .clock-note { color: var(--urgent); }
.tag .file { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1.5px dashed var(--tag-line); }
.tag .file .meta { min-width: 0; }
.tag .file .name { font-weight: 600; font-size: 17px; line-height: 1.35; }
.tag .file .size { font-size: 14px; }
.tag .bar { margin-top: 10px; background: rgba(27, 28, 31, .22); }
.tag .bar i { background: var(--tag-ink); }
.tag .prog-text { margin-top: 4px; font-size: 14px; font-variant-numeric: tabular-nums; }
.tag .acts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.tag .act {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 6px; border-radius: var(--r-btn);
  background: none; color: var(--tag-ink); border: 1.5px solid var(--tag-ink); font-size: 15px; font-weight: 600;
  transition: background-color .15s;
}
.tag .act:hover:not(:disabled) { background: rgba(27, 28, 31, .12); }
.tag .act.main-act { background: var(--tag-ink); color: var(--tag); }
.tag .act.main-act:hover:not(:disabled) { background: #3A3C41; }
.tag .act:disabled { opacity: .55; cursor: not-allowed; }
.tag .act.confirm { background: var(--urgent); border-color: var(--urgent); color: #fff; }
@media (max-width: 480px) { .tag .acts { grid-template-columns: 1fr 1fr; } }

.tag.spent { background: var(--spent); color: var(--ink); }
.tag.spent .act { color: var(--ink); border-color: var(--ink); }
.tag.spent .act.main-act { background: var(--ink); color: var(--ground); }
.tag.spent .file { border-top-color: var(--ink-2); }
.tag.spent .clock { font-size: clamp(36px, 10vw, 48px); }
.tag.spent .acts.one { grid-template-columns: 1fr; }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); border: 1.5px dashed var(--line); border-radius: var(--r-panel); }
.empty .i { width: 28px; height: 28px; margin-bottom: 8px; }
.empty .btn { margin-top: 14px; color: var(--ink); }

/* 설정 */
.panel { padding: 18px 20px; margin-bottom: 12px; background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--shadow); }
.panel input[type=text], .panel input[type=password] { background: var(--ground); margin-top: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.icon-preview { flex: none; border-radius: 13px; border: 1px solid var(--line); }
.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.swatch {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  background: var(--c); color: var(--tag-ink); border: 1px solid var(--line); border-radius: var(--r-btn);
}
.swatch .i { visibility: hidden; }
.swatch:hover { border-color: var(--ink); }
.swatch[aria-pressed=true] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.swatch[aria-pressed=true] .i { visibility: visible; }
.swatch-more { position: relative; cursor: pointer; }
.swatch-more:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.icon-note { margin-top: 12px; }
.switch { position: relative; flex: none; display: block; width: 52px; height: 32px; cursor: pointer; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 16px; background: var(--line); pointer-events: none; transition: background-color .15s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch input:checked + i { background: var(--ink); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--ink); outline-offset: 2px; }

/* 로그인 양식 */
.auth { display: grid; gap: 12px; }
.auth .seg { margin-top: 8px; }
.auth label { display: block; font-size: 14px; font-weight: 500; }
.gate .auth { padding: 20px; background: var(--surface); border-radius: var(--r-panel); box-shadow: var(--shadow); }
.gate .auth input { background: var(--ground); margin-top: 6px; }
.gate .auth .seg { margin-top: 0; }
.pw { position: relative; }
.pw input { padding-right: 48px; }
.pw .icon-btn { position: absolute; right: 1px; bottom: 1px; }
.auth-acts { display: flex; gap: 8px; }
.auth-acts .primary { flex: 1; }

.toasts { position: fixed; z-index: 40; left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { max-width: 440px; padding: 10px 14px; background: var(--ink); color: var(--ground); border-radius: var(--r-chip); font-size: 15px; animation: toast-in .18s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
@media (min-width: 820px) { .toasts { left: 224px; bottom: 24px; } }

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