/* 말랑 데스크 프로토 — 중립 와이어프레임 톤. 색·모서리·그림자는 전부 :root 변수(나중에 테마만 갈아 끼우기). */
:root {
  --bg-desk: #d9dbde;          /* 바탕화면 */
  --bg-desk-2: #c9ccd1;
  --surface: #ffffff;          /* 창·카드 */
  --surface-2: #f3f4f6;        /* 창 안 칸 */
  --surface-3: #e6e8eb;        /* 빈칸·비활성 */
  --line: #c4c8ce;
  --ink: #23262b;
  --ink-2: #5d636c;
  --ink-3: #8c929b;
  --accent: #3c4048;           /* 주요 버튼(중립 진회색) */
  --accent-ink: #ffffff;
  --good: #4f7a5a;
  --danger: #9b4a4a;
  --taskbar: #eceef1;
  --scrim: rgba(30, 32, 36, .38);
  --r-xs: 6px; --r-sm: 10px; --r-md: 14px; --r-lg: 22px; --r-pip: 28px;
  --shadow: 0 6px 24px rgba(20, 22, 26, .16), 0 1px 3px rgba(20, 22, 26, .12);
  --shadow-sm: 0 2px 8px rgba(20, 22, 26, .12);
  --font: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --taskbar-h: 48px;
  --pip-size: 260px;
  --pip-gap: 16px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg-desk); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 6px 12px; }
button:disabled { cursor: default; opacity: .45; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
button.danger { color: var(--danger); }
[hidden] { display: none !important; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--ink-2); font-weight: 600; }
h3 small { font-weight: 400; color: var(--ink-3); margin-left: 6px; }

/* ---------- 바탕화면 ---------- */
#desktop { position: fixed; inset: 0; background: radial-gradient(120% 90% at 30% 20%, var(--bg-desk) 0%, var(--bg-desk-2) 100%); overflow: hidden; }
.desk-icons { list-style: none; margin: 0; padding: 16px 10px; display: flex; flex-direction: column; gap: 8px; width: 92px; }
.desk-icon { width: 76px; display: flex; flex-direction: column; align-items: center; gap: 4px; background: transparent; border: 1px solid transparent; padding: 6px 2px; font-size: 12px; color: var(--ink); }
.desk-icon:hover, .desk-icon:focus-visible { background: rgba(255, 255, 255, .45); border-color: rgba(255, 255, 255, .7); }
.desk-icon .ico { width: 40px; height: 40px; display: grid; place-items: center; font-size: 26px; background: rgba(255, 255, 255, .55); border-radius: var(--r-sm); }
.mallang-ico { display: inline-block; width: 22px; height: 18px; border-radius: 50% 50% 46% 46% / 60% 60% 40% 40%; background: var(--surface); border: 2px solid var(--ink-2); }
.desk-icon .mallang-ico { width: 30px; height: 24px; }

/* ---------- 창 ---------- */
.win { position: absolute; background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow); border: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; z-index: 20; max-width: calc(100vw - 16px); max-height: calc(100vh - var(--taskbar-h) - 16px); }
.win.front { z-index: 30; }
.win-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px 8px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); cursor: move; user-select: none; touch-action: none; }
.win-title { font-weight: 600; font-size: 13px; }
.win-x { border: 0; background: transparent; padding: 2px 8px; color: var(--ink-2); }
.win-btns { display: flex; gap: 6px; } .win-btns i { width: 10px; height: 10px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--line); }
.win-body { padding: 14px; overflow: auto; flex: 1; }
.win.dummy { z-index: 10; }
.notepad { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: var(--ink-2); background: var(--surface); }

/* ---------- PIP ---------- */
#pip { position: absolute; left: 0; top: 0; width: var(--pip-user, var(--pip-size)); height: var(--pip-user, var(--pip-size)); border-radius: var(--r-pip); background: var(--surface-2); box-shadow: var(--shadow); overflow: hidden; z-index: 40; transition: opacity .25s, width .2s, height .2s; touch-action: none; }
#pip.below { z-index: 5; }                 /* 설정: 바탕화면에서만(다른 창 아래) */
#pip.faded { opacity: .38; transition: opacity 5s ease-in, width .2s, height .2s; }   /* 안 만진 지 오래되면 서서히 반투명 */
#pip.dragging, #pip.resizing { transition: none; }
#pip.dragging { opacity: .85; }
#pip.snapping { transition: left .16s ease-out, top .16s ease-out, opacity .25s; }
#pip.tuck-hint { opacity: .45; }
.pip-tab { position: absolute; z-index: 45; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm); padding: 0; font-size: 11px; color: var(--ink-2); display: grid; place-items: center; }
.pip-tab.e-l { left: 0; width: 20px; height: 58px; border-radius: 0 12px 12px 0; border-left: 0; }
.pip-tab.e-r { right: 0; width: 20px; height: 58px; border-radius: 12px 0 0 12px; border-right: 0; }
.pip-tab.e-t { top: 0; width: 58px; height: 20px; border-radius: 0 0 12px 12px; border-top: 0; }
.pip-tab.e-b { width: 58px; height: 20px; border-radius: 12px 12px 0 0; border-bottom: 0; }
.pip-stage, .pip-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pip-still { position: absolute; inset: 8%; width: 84%; height: 84%; object-fit: contain; transition: transform .12s; user-select: none; -webkit-user-drag: none; }
.pip-still.squish { transform: scale(1.08, .86) translateY(6%); }
.pip-bar { position: absolute; left: 34px; right: 34px; top: 0; height: 26px; z-index: 3; display: grid; place-items: center; cursor: grab; opacity: 0; transition: opacity .15s; touch-action: none; }
#pip:hover .pip-bar, #pip.dragging .pip-bar, #pip:hover .pip-resize, #pip.resizing .pip-resize { opacity: 1; }
@media (hover: none) { .pip-bar, .pip-resize { opacity: .8; } }
.pip-resize { position: absolute; left: 0; top: 0; width: 30px; height: 30px; z-index: 3; cursor: nwse-resize; opacity: 0; transition: opacity .15s; touch-action: none; }
.grip-corner { position: absolute; left: 7px; top: 7px; width: 13px; height: 13px; border-left: 4px solid rgba(60, 64, 72, .4); border-top: 4px solid rgba(60, 64, 72, .4); border-top-left-radius: 8px; }
.grip { width: 44px; height: 5px; border-radius: 3px; background: rgba(60, 64, 72, .35); }
.pip-pieces { position: absolute; right: 12px; top: 10px; z-index: 2; display: flex; align-items: center; gap: 4px; font-size: 12px; background: rgba(255, 255, 255, .78); border-radius: 999px; padding: 2px 9px 2px 6px; pointer-events: none; }
.shard { display: inline-block; width: 10px; height: 10px; background: var(--ink-2); clip-path: polygon(50% 0, 100% 40%, 75% 100%, 20% 90%, 0 35%); }
.pip-action { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 2; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, .85); }
.pip-msg { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 18px; text-align: center; background: var(--surface-2); font-size: 13px; }
.pip-msg.over-still { background: linear-gradient(transparent 45%, rgba(243, 244, 246, .96) 70%); justify-content: flex-end; pointer-events: none; }
.pip-msg.over-still .pip-msg-btns { pointer-events: auto; }
.pip-msg span { color: var(--ink-2); font-size: 12px; white-space: pre-line; }
.pip-msg-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.pip-msg-btns button { font-size: 12px; padding: 4px 10px; }
.pip-egg { position: absolute; z-index: 2; pointer-events: none; }
.pip-eggtag { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 2; font-size: 12px; padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, .85); pointer-events: none; white-space: nowrap; }
.pip-stage.wobble { animation: wobble .4s ease-in-out infinite alternate; }
.burst { position: absolute; z-index: 5; width: 14px; height: 14px; background: var(--ink-2); clip-path: polygon(50% 0, 100% 40%, 75% 100%, 20% 90%, 0 35%); pointer-events: none; animation: fly .6s ease-out forwards; }
@keyframes fly { to { transform: translate(var(--dx), var(--dy)) rotate(260deg); opacity: 0; } }
.pip-egg svg, .pip-hatch svg { width: 100%; height: 100%; overflow: visible; }
.pip-hatch { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; cursor: pointer; }
.pip-hatch .egg-big { width: 42%; height: 52%; animation: wobble .28s ease-in-out infinite alternate; }
.pip-hatch.cracked .egg-big { animation: pop .5s ease-out forwards; }
.pip-hatch .hatch-text { position: absolute; bottom: 14%; font-size: 13px; color: var(--ink-2); }
.pip-egg.s4 svg { animation: wobble .4s ease-in-out infinite alternate; }
@keyframes wobble { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
@keyframes pop { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }
.floaters { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.floater { position: absolute; font-weight: 700; font-size: 15px; color: var(--ink); text-shadow: 0 1px 0 #fff; animation: floatUp .9s ease-out forwards; }
@keyframes floatUp { from { transform: translate(-50%, 0); opacity: 1; } to { transform: translate(-50%, -46px); opacity: 0; } }

/* ---------- 작업표시줄·트레이 ---------- */
#taskbar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--taskbar-h); background: var(--taskbar); border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 10px; z-index: 50; }
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; }
.tb-start { font-size: 20px; color: var(--ink-2); }
.tb-search { width: 180px; height: 30px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-3); font-size: 12px; display: flex; align-items: center; padding: 0 12px; }
.tb-app { width: 28px; height: 28px; border-radius: var(--r-xs); background: var(--surface-3); }
.tb-clock { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tb-sys { font-size: 13px; opacity: .6; }
.tray-icon { position: relative; border: 1px solid transparent; background: transparent; padding: 4px 6px; border-radius: var(--r-xs); display: grid; place-items: center; }
.tray-icon:hover, .tray-icon.open { background: var(--surface); border-color: var(--line); }
.tray-icon .mallang-ico { width: 20px; height: 16px; }
.tray-icon .badge { position: absolute; right: 2px; top: 2px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); border: 2px solid var(--taskbar); }

/* ---------- 메뉴 ---------- */
.menu { position: fixed; z-index: 90; min-width: 180px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow); padding: 5px; }
.menu button { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 14px; border: 0; background: transparent; text-align: left; padding: 7px 10px; border-radius: var(--r-xs); }
.menu button:hover:not(:disabled), .menu button:focus-visible, .menu button.open { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.menu .sub { color: var(--ink-3); font-size: 12px; }
.menu .on::after { content: '✓'; color: var(--ink-2); }
.menu .submenu { position: absolute; }

/* ---------- 모달 ---------- */
.scrim { position: fixed; inset: 0; z-index: 80; background: var(--scrim); display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.modal { width: min(420px, 100%); padding: 22px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 32px); overflow: auto; }
.modal h2 { margin: 0; font-size: 18px; }
.modal p { margin: 0; color: var(--ink-2); }
.modal .art { height: 150px; border-radius: var(--r-md); background: var(--surface-2); display: grid; place-items: center; color: var(--ink-3); font-size: 13px; overflow: hidden; }
.modal .art img { height: 150px; width: auto; max-width: 100%; object-fit: contain; }
.modal .art .egg-art { width: 70px; height: 86px; }
.modal .dots { display: flex; gap: 6px; justify-content: center; }
.modal .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--surface-3); }
.modal .dots i.on { background: var(--ink-2); }
.modal .btns { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal .rule { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13px; background: var(--surface-2); padding: 10px 12px; border-radius: var(--r-sm); }
.modal .rule b { text-align: right; }
.modal .reason { font-size: 13px; background: var(--surface-2); padding: 8px 12px; border-radius: var(--r-sm); color: var(--ink-2); }

/* ---------- 토글 행(설정·설정 제안) ---------- */
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--surface-3); }
.opt:last-child { border-bottom: 0; }
.opt .lbl { display: flex; flex-direction: column; } .opt .lbl small { color: var(--ink-3); font-size: 12px; }
.switch { position: relative; width: 40px; height: 22px; flex: none; padding: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line); }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { left: 20px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 4px 10px; background: var(--surface); font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- 선반 ---------- */
#win-shelf { width: 860px; height: 640px; }
.shelf { display: flex; flex-direction: column; gap: 12px; padding: 0; }
.shelf-head { display: flex; align-items: center; gap: 18px; padding: 12px 14px 0; }
.shelf-head .stat { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.shelf-head .stat b { color: var(--ink); font-size: 16px; }
.tabs { margin-left: auto; display: flex; gap: 4px; }
.tabs button { border-radius: 999px; padding: 4px 14px; font-size: 13px; }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.shelf-main { display: grid; grid-template-columns: 1fr 260px; gap: 14px; padding: 0 14px 14px; min-height: 0; flex: 1; }
.shelf-left { overflow: auto; min-height: 0; padding-right: 4px; }
.eggs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.egg-card { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; background: var(--surface); }
.egg-card .egg-art { width: 40px; height: 50px; }
.egg-card .fam { font-weight: 600; } .egg-card small { color: var(--ink-3); font-size: 12px; }
.egg-card button { font-size: 12px; padding: 4px 10px; width: 100%; }
.egg-card.incubating { border-style: dashed; border-color: var(--ink-3); }
.shelf-row { margin-bottom: 14px; }
.shelf-row .plank { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; padding: 8px; border-radius: var(--r-md); background: var(--surface-2); border-bottom: 4px solid var(--line); }
.slot { aspect-ratio: 1; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); padding: 4px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; font-size: 11px; overflow: hidden; position: relative; }
.slot img { width: 100%; flex: 1; min-height: 0; object-fit: contain; }
.slot.empty { background: var(--surface-3); border-style: dashed; color: var(--ink-3); justify-content: center; font-size: 22px; cursor: default; }
.slot.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.slot .cur { position: absolute; top: 4px; left: 4px; font-size: 10px; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 6px; }
.slot .new { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.empty-note { font-size: 12px; color: var(--ink-3); margin: 6px 2px 0; }
.shelf-detail { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.shelf-detail .big { aspect-ratio: 1; border-radius: var(--r-md); background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.shelf-detail .big img { width: 100%; height: 100%; object-fit: contain; }
.shelf-detail h4 { margin: 0; font-size: 16px; }
.shelf-detail p { margin: 0; color: var(--ink-2); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.locked { background: var(--surface-3); color: var(--ink-3); border-style: dashed; }
.meter { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; } .meter i { display: block; height: 100%; background: var(--ink-2); }
.ach { padding: 0 14px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; overflow: auto; }
.ach .a { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; font-size: 12px; }
.ach .a b { display: block; font-size: 13px; } .ach .a.locked { background: var(--surface-2); color: var(--ink-3); border-style: dashed; }

/* ---------- 설정 ---------- */
.settings select { font: inherit; border: 1px solid var(--line); border-radius: var(--r-xs); padding: 4px 8px; background: var(--surface); }
.settings .keys { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--surface-2); border-radius: var(--r-xs); padding: 2px 8px; }

/* ---------- 전체 화면 앱 흉내 ---------- */
#fullscreen-app { position: absolute; inset: 0; z-index: 60; background: #2b2e33; color: #c9ccd1; display: grid; place-items: center; cursor: pointer; }

/* ---------- 토스트 ---------- */
.toasts { position: fixed; right: 16px; bottom: calc(var(--taskbar-h) + var(--pip-size) + 28px); z-index: 85; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; max-width: calc(100vw - 32px); }
.toast { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-sm); padding: 8px 12px; font-size: 13px; animation: tIn .2s ease-out; }
.toast.ach { border-left: 4px solid var(--ink-2); }
@keyframes tIn { from { transform: translateY(8px); opacity: 0; } }

/* ---------- 디버그 ---------- */
.debug { position: fixed; right: 16px; top: 12px; z-index: 95; background: rgba(255, 255, 255, .92); border: 1px dashed var(--ink-3); border-radius: var(--r-sm); font-size: 12px; width: 300px; }
.debug-toggle { width: 100%; border: 0; background: transparent; text-align: left; font-weight: 600; padding: 6px 10px; }
.debug-body { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.debug.collapsed .debug-body { display: none; }
.debug .row { display: flex; align-items: center; gap: 8px; } .debug .wrap { flex-wrap: wrap; gap: 4px; }
.debug .row button { font-size: 12px; padding: 3px 8px; }
.debug .mono { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--ink-2); white-space: pre-line; display: block; }

/* ---------- 폰(축소 표시) ---------- */
@media (max-width: 720px) {
  :root { --pip-size: 180px; --taskbar-h: 44px; --pip-gap: 10px; }
  .desk-icons { flex-direction: row; width: auto; flex-wrap: wrap; }
  .tb-search, .tb-app { display: none; }
  .win { left: 8px !important; right: 8px; top: 8px !important; width: auto !important; height: auto !important; bottom: calc(var(--taskbar-h) + 8px); }
  #win-notepad { bottom: auto; height: 160px !important; top: 110px !important; }
  .shelf-main { grid-template-columns: 1fr; overflow: auto; }
  .shelf-left { overflow: visible; }
  .eggs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .debug { left: auto; right: 8px; top: 8px; width: auto; max-width: calc(100vw - 16px); }
  .debug:not(.collapsed) { left: 8px; }
  .toasts { bottom: calc(var(--taskbar-h) + var(--pip-size) + 24px); }
}
