/* METACADY VIEWER — 스마트폰 우선 화면. 밝은 테마가 기본(햇빛 아래 가독성), 어두운 테마는 [밝기] 단추 */
:root {
  --bg: #ffffff; --panel: #f4f6f9; --line: #d5dbe3; --text: #111418; --dim: #5b6572;
  --acc: #1f6fe5; --acc-text: #ffffff; --shade: rgba(10, 14, 20, .45); --card: #ffffff;
}
:root.dark {
  --bg: #1f242b; --panel: #161a20; --line: #333c48; --text: #eef2f7; --dim: #9aa6b5;
  --acc: #3d8bff; --acc-text: #ffffff; --shade: rgba(0, 0, 0, .6); --card: #232a33;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* 위쪽 줄 */
#top { flex: none; display: flex; align-items: center; gap: 10px; height: calc(48px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand b { font-size: min(15px, 3.9vw); letter-spacing: .3px; white-space: nowrap; } .brand i { font-style: normal; }
.b1 { color: #9aa1ab; } .b2 { color: #3d8bff; }
#fileName { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.iconBtn { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 17px; font-weight: 700; line-height: 1; }
#btnFull { display: flex; align-items: center; justify-content: center; padding: 0; }
#btnFull.hidden { display: none; }
#btnFull svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* 도면 화면 — 브라우저가 화면 전체를 확대·스크롤하지 않도록 터치를 모두 여기서 처리 */
#canvasWrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--bg); touch-action: none; }
#canvasWrap canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

/* 첫 화면 안내 */
#welcome { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.wCard { width: 100%; max-width: 420px; text-align: center; }
.wLogo { font-size: min(26px, 5.6vw); letter-spacing: .5px; margin-bottom: 18px; white-space: nowrap; } /* BOUNDY METACADY VIEWER 가 좁은 휴대폰에서도 한 줄 */
.wMain { font-size: 20px; font-weight: 700; line-height: 1.5; margin: 0 0 24px; word-break: keep-all; }
.bigBtn { width: 100%; min-height: 60px; border: none; border-radius: 14px; background: var(--acc); color: var(--acc-text); font-size: 20px; font-weight: 700; }
.bigBtn:active { filter: brightness(.9); }
.wSub { margin: 16px 0 0; font-size: 15px; line-height: 1.7; color: var(--dim); word-break: keep-all; }
.wHow { list-style: none; margin: 18px auto 0; padding: 12px 16px; max-width: 280px; border: 1px solid var(--line); border-radius: 12px; text-align: left; font-size: 15px; line-height: 2; color: var(--dim); }
.wHow b { color: var(--text); }

/* 치수 카드 — 햇빛 아래에서도 읽히게 큰 글씨 · 강한 대비 */
#card { position: absolute; left: 8px; right: 8px; bottom: 8px; max-width: 520px; margin: 0 auto; z-index: 6;
  background: var(--card); color: var(--text); border: 2px solid #ff6a00; border-radius: 16px; padding: 10px 14px 12px; box-shadow: 0 6px 24px rgba(0,0,0,.28); }
.cardHead { display: flex; align-items: center; gap: 8px; }
#cardTitle { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; color: var(--dim); }
#cardNext { flex: none; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); font-size: 14px; font-weight: 700; }
#cardMain { font-size: 34px; font-weight: 800; line-height: 1.2; margin: 2px 0 6px; word-break: break-all; font-variant-numeric: tabular-nums; }
#cardWarn { margin: 0 0 8px; padding: 8px 10px; border-radius: 10px; background: #fff1e0; color: #8a3b00; font-size: 14px; font-weight: 600; line-height: 1.5; word-break: keep-all; }
#cardRows { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; }
#cardRows .row { display: flex; justify-content: space-between; gap: 8px; min-width: 0; padding: 5px 0; border-top: 1px solid var(--line); font-size: 15px; }
#cardRows .row.wide { grid-column: 1 / -1; }
#cardRows .row span { color: var(--dim); white-space: nowrap; } #cardRows .row b { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
#guide { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); width: max-content; z-index: 6;
  padding: 9px 16px; border-radius: 22px; background: #ff6a00; color: #fff; font-size: 16px; font-weight: 700; text-align: center; box-shadow: 0 4px 14px rgba(0,0,0,.25); pointer-events: none; word-break: keep-all; }
#bar button.act { color: #ff6a00; background: rgba(255,106,0,.12); }

/* 좁은 휴대폰: 제목 줄에 BOUNDY METACADY VIEWER 가 들어가면 파일 이름 자리가 모자라서, 파일 이름을 도면 왼쪽 위 이름표로 옮긴다 */
#fileChip { display: none; }
@media (max-width: 520px) {
  #fileName { display: none; }
  #fileChip:not(.hidden) { display: block; position: absolute; top: 8px; left: 8px; max-width: calc(100% - 16px); z-index: 4; pointer-events: none;
    padding: 4px 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); color: var(--dim);
    font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .92; }
  #guide { top: 42px; }
  #toast { top: 96px; }
}

/* 알림 · 여는 중 */
#toast { position: absolute; left: 50%; top: 62px; transform: translateX(-50%); max-width: calc(100% - 32px); width: max-content;
  padding: 10px 16px; border-radius: 12px; background: rgba(17, 20, 24, .88); color: #fff; font-size: 15px; line-height: 1.5; text-align: center;
  opacity: 0; transition: opacity .25s; pointer-events: none; word-break: keep-all; }
#toast.on { opacity: 1; }
#busy { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; gap: 12px; background: var(--shade); color: #fff; font-size: 17px; font-weight: 600; }
#busy.on { display: flex; }
#busy i { width: 26px; height: 26px; border: 3px solid rgba(255, 255, 255, .35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 아래쪽 단추 줄 — 엄지손가락이 닿는 곳 */
#bar { flex: none; display: flex; background: var(--panel); border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#bar button { flex: 1; min-height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: none; background: none; font-size: 13px; font-weight: 600; }
#bar button:active { background: var(--line); }
#bar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
#bar svg .fill { fill: currentColor; stroke: none; }
#bar button:disabled { opacity: .35; }

/* 아래에서 올라오는 창 (레이어 · 도움말) */
#sheet { position: fixed; inset: 0; z-index: 20; background: var(--shade); display: flex; align-items: flex-end; justify-content: center; }
.sheetBox { width: 100%; max-width: 560px; max-height: 78%; display: flex; flex-direction: column; background: var(--card); color: var(--text);
  border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
.sheetHead { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sheetHead b { font-size: 18px; }
#sheetBody { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 16px 16px; }
.lyTools { display: flex; gap: 8px; padding: 10px 0; }
.lyTools button { flex: 1; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 15px; font-weight: 600; }
.lyRow { display: flex; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); cursor: pointer; }
.lyRow .sw { flex: none; width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line); }
.lyRow .nm { flex: 1; min-width: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lyRow.off .nm { color: var(--dim); text-decoration: line-through; }
.tgl { flex: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; transition: background .15s; }
.tgl::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .15s; }
.lyRow.on .tgl { background: var(--acc); } .lyRow.on .tgl::after { left: 23px; }
.help h3 { font-size: 16px; margin: 16px 0 6px; } .help p, .help li { font-size: 15px; line-height: 1.7; margin: 0; word-break: keep-all; }
.help ul { margin: 0; padding-left: 20px; } .help .ver { margin-top: 18px; color: var(--dim); font-size: 13px; }
.help .lead { font-size: 17px; font-weight: 700; margin-top: 10px; }

/* 휴대폰을 가로로 돌렸을 때 — 높이가 낮으니 단추 줄을 오른쪽 세로 줄로 옮기고 제목 줄을 얇게 해서 도면 자리를 넓힌다 */
@media (orientation: landscape) and (max-height: 540px) {
  #app { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); }
  #top { grid-column: 1 / -1; height: calc(40px + env(safe-area-inset-top)); }
  .iconBtn { width: 32px; height: 32px; font-size: 15px; }
  #canvasWrap { grid-column: 1; grid-row: 2; }
  #bar { grid-column: 2; grid-row: 2; flex-direction: column; width: calc(78px + env(safe-area-inset-right)); border-top: none; border-left: 1px solid var(--line);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) 0; }
  #bar button { min-height: 0; gap: 2px; font-size: 11.5px; }
  #bar svg { width: 22px; height: 22px; }
  #card { left: auto; right: 8px; top: auto; bottom: 8px; width: min(330px, 52%); max-height: calc(100% - 16px); overflow-y: auto; margin: 0; padding: 8px 12px 10px; }
  #cardMain { font-size: 28px; margin: 0 0 4px; }
  #cardRows { grid-template-columns: 1fr; }
  #cardRows .row { padding: 3px 0; font-size: 14px; }
  #welcome { padding: 10px; } .wLogo { font-size: 20px; margin-bottom: 8px; } .wMain { font-size: 17px; margin-bottom: 12px; }
  .bigBtn { min-height: 48px; font-size: 18px; } .wSub { margin-top: 8px; font-size: 14px; } .wHow { display: none; }
  .sheetBox { max-height: 92%; }
}

/* 가로로 넓은 화면(태블릿 가로 · PC) — 단추 줄을 조금 낮게 */
@media (min-width: 900px) { #bar button { min-height: 54px; flex-direction: row; gap: 8px; font-size: 14px; } #bar svg { width: 22px; height: 22px; } }
