:root {
  --bg: #fbefe8;
  --paper: #fffaf6;
  --card: #ffffff;
  --ink: #4a3a36;
  --ink-soft: #8a746c;
  --line: #f0dcd2;
  --pink: #ff8fb8;
  --pink-deep: #e7679a;
  --mint: #7fd9ad;
  --sky: #8fd3ff;
  --butter: #ffd36e;
  --lav: #c3a6ff;
  --shadow: 0 6px 20px rgba(150, 90, 70, 0.14);
  --radius: 18px;
  --font-title: "Jua", "Gowun Dodum", system-ui, sans-serif;
  --font: "Gowun Dodum", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  height: 100dvh;
}

/* ───────── 오피스 ───────── */
.office { position: relative; overflow: hidden; background: #f3dccf; }

.office-head {
  position: absolute; z-index: 5; top: 14px; left: 14px;
  background: rgba(255, 250, 246, 0.92);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
  padding: 10px 16px 10px;
  box-shadow: var(--shadow);
  max-width: calc(100% - 90px);
}
.office-head h1 { font-family: var(--font-title); font-weight: 400; font-size: 22px; margin: 0; letter-spacing: -0.5px; }
.office-head h1::before { content: "🏢 "; }
.office-status { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 4px; font-size: 12.5px; color: var(--ink-soft); }
.office-status .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }
.dot.desk { background: #4fcf86; }
.dot.lounge { background: #ffb547; }
.dot.away { background: #c8b8b2; }
.sync-pill { padding: 1px 8px; border-radius: 99px; background: #f6e6de; font-size: 11.5px; }
.sync-pill.err { background: #ffe0e0; color: #b8434f; }
.sync-pill button { border: 0; background: none; padding: 0; text-decoration: underline; color: inherit; font-size: inherit; }

.map { position: absolute; inset: 0; touch-action: none; cursor: grab; outline: none; }
.map.dragging { cursor: grabbing; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.stage .bg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.actors { position: absolute; inset: 0; }

.actor {
  position: absolute;
  width: 7.2%;
  transform: translate(-50%, -100%) scale(var(--s, 1));
  transform-origin: 50% 100%;
  transition: left 0.9s cubic-bezier(.5,.1,.3,1), top 0.9s cubic-bezier(.5,.1,.3,1), opacity 0.4s, filter 0.4s;
  border: 0; background: none; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.actor .body { display: block; animation: bob 2.6s ease-in-out infinite; animation-delay: var(--delay, 0s); }
.actor svg { display: block; width: 100%; height: auto; filter: drop-shadow(0 3px 2px rgba(120, 70, 50, 0.18)); }
.actor:hover .body, .actor:focus-visible .body { animation-duration: 0.9s; }
.actor:focus-visible { outline: 3px solid var(--pink); outline-offset: 4px; border-radius: 12px; }
.actor.away .body { opacity: 0.45; filter: grayscale(0.55); animation: none; }
.actor.away .name { opacity: 0.7; }
.actor.selected .name { background: var(--pink-deep); color: #fff; }

.actor .name {
  position: absolute; left: 50%; top: 100%; transform: translate(-50%, 2px);
  white-space: nowrap;
  font-family: var(--font-title); font-size: max(calc(11px / var(--z, 1)), calc(var(--u, 10px) * 0.78));
  background: rgba(255, 255, 255, 0.92); border-radius: 99px; padding: 0.1em 0.7em;
  box-shadow: 0 2px 6px rgba(120, 70, 50, 0.15);
}
.actor .name .dot { display: inline-block; width: 0.6em; height: 0.6em; border-radius: 50%; margin-right: 0.3em; vertical-align: 0.05em; }

.bubble {
  position: absolute; left: 50%; bottom: 100%;
  transform: translate(-50%, -6px);
  white-space: nowrap;
  background: #fff; color: var(--ink);
  border: 2px solid var(--pink); border-radius: 14px;
  padding: 0.25em 0.75em; font-size: max(calc(11px / var(--z, 1)), calc(var(--u, 10px) * 0.74)); font-weight: 700;
  box-shadow: 0 4px 10px rgba(231, 103, 154, 0.25);
  animation: pop 0.35s ease-out, float 2.2s ease-in-out 0.35s infinite;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; top: 100%; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: var(--pink);
}
.bubble small { font-weight: 400; color: var(--ink-soft); margin-left: 4px; }

@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5%); } }
@keyframes float { 0%, 100% { transform: translate(-50%, -6px); } 50% { transform: translate(-50%, -11px); } }
@keyframes pop { from { transform: translate(-50%, 4px) scale(0.6); opacity: 0; } }

.zoom { position: absolute; z-index: 5; top: 14px; right: 14px; display: flex; flex-direction: column; gap: 6px; }
.zoom button {
  width: 38px; height: 38px; border: 0; border-radius: 12px;
  background: rgba(255, 250, 246, 0.94); box-shadow: var(--shadow); font-size: 18px;
}
.zoom button:hover { background: #fff; }

/* 하단 아바타 스트립 */
.strip {
  position: absolute; z-index: 5; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 8px 10px;
  background: rgba(255, 250, 246, 0.94); backdrop-filter: blur(6px);
  border-radius: 22px; box-shadow: var(--shadow);
  max-width: calc(100% - 28px); overflow-x: auto;
}
.strip button {
  position: relative; flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 66px; padding: 4px 2px 3px; border: 2px solid transparent; border-radius: 16px; background: none;
}
.strip button:hover { background: #fdeee6; }
.strip button[aria-pressed="true"] { border-color: var(--pink); background: #fff0f5; }
.strip .av { width: 40px; }
.strip .av svg { width: 100%; height: auto; display: block; }
.strip .nm { font-family: var(--font-title); font-size: 13px; line-height: 1.1; }
.strip .st { font-size: 10.5px; color: var(--ink-soft); white-space: nowrap; }
.strip .away .av { opacity: 0.5; filter: grayscale(0.5); }
.strip .badge { position: absolute; top: 0; right: 6px; }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--pink-deep); color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
}

/* 캐릭터 클릭 시 최근 우편 카드 */
.mail-card {
  position: absolute; z-index: 8; right: 66px; top: 14px;
  width: min(340px, calc(100% - 28px));
  max-height: calc(100% - 150px); overflow: auto;
  background: var(--paper); border-radius: var(--radius); box-shadow: 0 12px 34px rgba(120, 70, 50, 0.25);
  padding: 14px;
  animation: pop-card 0.2s ease-out;
}
@keyframes pop-card { from { opacity: 0; transform: translateY(-6px); } }
.mail-card .mc-head { display: flex; gap: 10px; align-items: center; }
.mail-card .mc-head .av { width: 46px; flex: 0 0 auto; }
.mail-card .mc-head h3 { margin: 0; font-family: var(--font-title); font-weight: 400; font-size: 18px; }
.mail-card .mc-head p { margin: 1px 0 0; font-size: 12px; color: var(--ink-soft); }
.mail-card .close { margin-left: auto; align-self: flex-start; border: 0; background: none; font-size: 18px; color: var(--ink-soft); }
.mail-card .mc-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* ───────── 패널 ───────── */
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--paper); border-left: 1px solid var(--line); }
.panel-tabs { display: flex; gap: 4px; padding: 10px 10px 0; border-bottom: 1px solid var(--line); }
.panel-tabs button {
  flex: 1; border: 0; background: none; padding: 9px 4px 10px; border-radius: 12px 12px 0 0;
  font-family: var(--font-title); font-size: 15px; color: var(--ink-soft); white-space: nowrap;
}
.panel-tabs button[aria-selected="true"] { background: #fde9ef; color: var(--ink); }
.panel-tabs .badge { margin-left: 2px; }
.panel-body { flex: 1; min-height: 0; overflow: auto; padding: 14px; }

/* 대화 */
.chat { display: flex; flex-direction: column; height: 100%; }
.chat-who { display: flex; gap: 12px; align-items: center; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.chat-who .av { width: 58px; flex: 0 0 auto; }
.chat-who h2 { margin: 0; font-family: var(--font-title); font-weight: 400; font-size: 21px; }
.chat-who p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.chat-log { flex: 1; overflow: auto; padding: 12px 2px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 86%; padding: 8px 12px; border-radius: 16px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.me { align-self: flex-end; background: #ffe1ec; border-bottom-right-radius: 4px; }
.msg time { display: block; font-size: 10.5px; color: var(--ink-soft); margin-top: 2px; }
.msg.mailmsg { border-color: var(--pink); cursor: pointer; }
.msg a { color: var(--pink-deep); }
.chat-form { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.chat-form textarea { resize: none; min-height: 44px; }
.chat-form .row { display: flex; gap: 6px; }
.chat-form .row button { flex: 1; }
.hint { font-size: 11.5px; color: var(--ink-soft); margin: 0; }

/* 공통 폼·버튼 */
input[type="text"], input[type="url"], input[type="password"], select, textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 8px 10px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--pink); }
.btn {
  border: 0; border-radius: 12px; padding: 8px 12px; background: #f6e6de; font-size: 13.5px; white-space: nowrap;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--pink-deep); color: #fff; }
.btn.small { padding: 4px 9px; font-size: 12px; border-radius: 10px; }
.btn.ghost { background: none; color: var(--ink-soft); }

.section-title { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; font-family: var(--font-title); font-weight: 400; font-size: 17px; }
.section-title .count { font-family: var(--font); font-size: 12px; color: var(--ink-soft); }
.empty { text-align: center; color: var(--ink-soft); padding: 22px 10px; font-size: 13.5px; line-height: 1.6; }
.empty .big { font-size: 34px; display: block; margin-bottom: 4px; }

/* 우편함 */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 10px; font-size: 12.5px; }
.chip[aria-pressed="true"] { border-color: var(--pink); background: #fff0f5; }
.mail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mail-item {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: start;
  background: #fff; border: 1.5px solid var(--line); border-radius: 14px; padding: 9px 10px;
}
.mail-item.unread { border-color: var(--pink); background: #fff7fa; }
.mail-item .av { width: 34px; }
.mail-item h4 { margin: 0; font-size: 14px; display: flex; gap: 6px; align-items: baseline; }
.mail-item.unread h4::before { content: ""; flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--pink-deep); transform: translateY(-1px); }
.mail-item .meta { font-size: 11.5px; color: var(--ink-soft); margin-top: 1px; }
.mail-item .body { font-size: 13px; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.mail-item a { color: var(--pink-deep); font-size: 12.5px; }
.mail-item .acts { display: flex; flex-direction: column; gap: 4px; }
details.add { background: #fff; border: 1.5px dashed var(--line); border-radius: 14px; padding: 8px 12px; margin-bottom: 12px; }
details.add summary { cursor: pointer; font-size: 13.5px; color: var(--ink-soft); }
details.add form { display: grid; gap: 6px; margin-top: 8px; }
details.add .two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* 업무 */
.task-form { display: grid; grid-template-columns: 110px 1fr auto; gap: 6px; margin-bottom: 14px; }
.lanes { display: flex; flex-direction: column; gap: 14px; }
.lane h3 { margin: 0 0 6px; font-family: var(--font-title); font-weight: 400; font-size: 15px; display: flex; gap: 6px; align-items: center; }
.lane ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.task {
  display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: center;
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 7px 9px;
}
.task .av { width: 28px; }
.task .t { font-size: 13.5px; word-break: break-word; }
.task .m { font-size: 11px; color: var(--ink-soft); }
.task .acts { grid-column: 2; display: flex; gap: 4px; flex-wrap: wrap; }
.lane.done .task .t { text-decoration: line-through; color: var(--ink-soft); }
.lane-empty { font-size: 12px; color: var(--ink-soft); padding: 4px 2px; }

/* 메모판 */
.memo-form { display: grid; gap: 6px; margin-bottom: 14px; }
.memo-form .row { display: flex; gap: 6px; align-items: center; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--line); padding: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2.5px var(--pink-deep); }
.memo-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.memo {
  position: relative; min-height: 110px; padding: 14px 12px 28px; border-radius: 6px 6px 16px 6px;
  box-shadow: 0 4px 10px rgba(120, 70, 50, 0.14); font-size: 13.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.memo:nth-child(odd) { transform: rotate(-1.2deg); }
.memo:nth-child(even) { transform: rotate(1deg); }
.memo::before { content: "📌"; position: absolute; top: -8px; left: 50%; transform: translateX(-50%); font-size: 16px; }
.memo time { position: absolute; left: 12px; bottom: 7px; font-size: 10.5px; color: rgba(74, 58, 54, 0.6); }
.memo .del { position: absolute; right: 6px; bottom: 4px; border: 0; background: none; font-size: 12px; color: rgba(74, 58, 54, 0.6); }
.memo[data-color="yellow"], .swatch[data-color="yellow"] { background: #fff3b8; }
.memo[data-color="pink"], .swatch[data-color="pink"] { background: #ffd9e6; }
.memo[data-color="mint"], .swatch[data-color="mint"] { background: #d4f5e4; }
.memo[data-color="sky"], .swatch[data-color="sky"] { background: #d8eeff; }
.memo[data-color="lav"], .swatch[data-color="lav"] { background: #e8dcff; }

.mobile-tabs { display: none; }

/* 대화상자 */
.dialog { border: 0; border-radius: var(--radius); padding: 18px; width: min(360px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(74, 58, 54, 0.35); }
.dialog h2 { margin: 0 0 6px; font-family: var(--font-title); font-weight: 400; }
.dialog p { font-size: 13px; color: var(--ink-soft); margin: 0 0 10px; }
.dialog menu { display: flex; justify-content: flex-end; gap: 6px; padding: 0; margin: 12px 0 0; }
.dialog menu button { border: 0; border-radius: 12px; padding: 8px 14px; background: #f6e6de; }
.dialog menu .primary { background: var(--pink-deep); color: #fff; }

/* ───────── 모바일: 오피스 | 대화 탭 ───────── */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .office, .panel { grid-row: 1; grid-column: 1; }
  .app[data-tab="office"] .panel { display: none; }
  .app[data-tab="panel"] .office { display: none; }
  .panel { border-left: 0; }
  .mobile-tabs {
    display: flex; grid-row: 2;
    background: var(--paper); border-top: 1px solid var(--line);
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .mobile-tabs button {
    flex: 1; border: 0; border-radius: 14px; padding: 10px; background: none;
    font-family: var(--font-title); font-size: 16px; color: var(--ink-soft);
  }
  .mobile-tabs button[aria-pressed="true"] { background: #fde9ef; color: var(--ink); }
  .office-head { top: 10px; left: 10px; padding: 8px 12px; max-width: calc(100% - 70px); }
  .office-head h1 { font-size: 19px; }
  .zoom { top: 10px; right: 10px; }
  .zoom button { width: 36px; height: 36px; }
  .strip { bottom: 10px; gap: 2px; padding: 6px; }
  .strip button { width: 58px; }
  .strip .av { width: 34px; }
  .mail-card { right: 10px; left: 10px; width: auto; top: auto; bottom: 108px; max-height: 60%; }
  .panel-tabs button { font-size: 14px; }
  .task-form { grid-template-columns: 1fr auto; }
  .task-form select { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .actor, .actor .body, .bubble { animation: none !important; transition: none !important; }
}
