/* ── InkMind ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:        #0e1014;
  --panel:     #14171d;
  --panel-2:   #1b1f27;
  --line:      #262b35;
  --text:      #e6e9ef;
  --muted:     #8f98a8;
  --accent:    #6ea8fe;
  --accent-2:  #3d7dfa;
  --paper:     #ffffff;
  --danger:    #ff6b6b;
  --ok:        #4ade80;
  --radius:    10px;
  --tb:        52px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:      #eef1f6;
    --panel:   #ffffff;
    --panel-2: #f4f6fa;
    --line:    #dfe4ec;
    --text:    #1a1e26;
    --muted:   #5f6878;
  }
}

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Pretendard", "Malgun Gothic", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app {
  display: grid;
  grid-template-columns: 232px 1fr 380px;
  height: 100dvh;
  gap: 1px; background: var(--line);
}

.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.panel-head strong { flex: 1; font-size: 13px; letter-spacing: .02em; }
.panel-foot { padding: 8px; border-top: 1px solid var(--line); }

/* ── 노트 목록 ── */
/* AI 가 노트에 얹은 표시 관련 */
#btn-clear-ai { flex: 0 0 auto; white-space: nowrap; border-color: #e11d48; color: #e11d48; }
#btn-clear-ai:hover { background: rgba(225, 29, 72, .12); }
.mini-btn.mark { border-color: #e11d48; color: #e11d48; }
.mini-btn.mark:disabled { opacity: .5; }

/* 확대·축소 묶음 — 배율 숫자가 보여야 지금 얼마나 키웠는지 안다 */
.zoom-group { display: flex; align-items: center; gap: 1px; flex: 0 0 auto; }
.zoom-label {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 12px; font-variant-numeric: tabular-nums; min-width: 46px;
  min-height: 34px; padding: 0 4px; border-radius: 7px;
}
.zoom-label:hover { background: var(--panel-2); color: var(--accent); }
.zoom-label.off { opacity: .55; }

.note-count { font-size: 11.5px; opacity: .55; font-weight: 400; }
.new-note-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: inherit;
  border-radius: 999px; padding: 5px 11px; font-size: 12.5px; cursor: pointer;
  min-height: 32px; white-space: nowrap;
}
.new-note-btn:hover { border-color: var(--accent); color: var(--accent); }

.note-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.note-list li {
  padding: 8px 9px; border-radius: var(--radius); cursor: pointer;
  display: flex; align-items: center; gap: 9px;
}
.note-list li:hover { background: var(--panel-2); }
.note-list li.active { background: var(--accent-2); color: #fff; }

/* 손으로 쓴 노트는 제목만으로 구분되지 않는다. 그림 자체가 가장 빠른 표지다. */
.nthumb {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 7px;
  background: #fff; border: 1px solid var(--line); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.nthumb img { width: 100%; height: 100%; object-fit: contain; }
.nthumb.empty { color: var(--muted); font-size: 16px; opacity: .5; }

.nmain { flex: 1; min-width: 0; }
.note-list .nt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list .nsub {
  font-size: 11px; opacity: .6; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.nacts { flex: 0 0 auto; display: flex; gap: 2px; }
.nact {
  opacity: 0; border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 14px; padding: 6px; border-radius: 6px; line-height: 1;
}
.note-list li:hover .nact, .note-list li.active .nact { opacity: .65; }
.nact:hover { opacity: 1; background: rgba(127, 127, 127, .18); }
.nact.del:hover { color: var(--danger); }
/* 손가락에는 hover 가 없다 — 폰에서는 항상 보이고 누를 수 있게 둔다 */
@media (hover: none) {
  .nact { opacity: .55; min-width: 34px; min-height: 34px; }
}

/* ── 캔버스 영역 ── */
#stage { position: relative; background: var(--bg); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }

/* canvas 는 replaced element라 top/bottom 만으로는 늘어나지 않는다 → 래퍼로 높이를 준다 */
.board-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

#toolbar {
  flex: 0 0 var(--tb); height: var(--tb); z-index: 5;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  min-width: 0;
}
/* 왼쪽 도구들만 가로 스크롤 — 주요 버튼은 항상 보이게 고정 */
.tb-scroll {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none;
}
.tb-scroll::-webkit-scrollbar { display: none; }
.tb-pinned { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 24px; background: var(--line); flex: none; }
.grow { flex: 1 1 auto; }

button { font: inherit; color: inherit; }
.icon-btn, .tool {
  width: 34px; height: 34px; flex: none; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer;
  font-size: 16px; line-height: 1; display: grid; place-items: center;
}
.icon-btn:hover, .tool:hover { background: var(--panel-2); }
.tool.active { background: var(--accent-2); color: #fff; border-color: var(--accent); }
.tool:disabled, .icon-btn:disabled { opacity: .35; cursor: default; }

.primary-btn {
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent-2); color: #fff; font-weight: 600; white-space: nowrap;
}
.primary-btn:hover { background: var(--accent); }
.primary-btn:disabled { opacity: .5; cursor: default; }
.ghost-btn, .mini-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 12px; white-space: nowrap;
}
.mini-btn.ghost { background: transparent; }
.ghost-btn:hover, .mini-btn:hover { border-color: var(--accent); }

.swatches { display: flex; gap: 4px; flex: none; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--text); transform: scale(1.12); }

#size { width: 92px; flex: none; accent-color: var(--accent); }

.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; flex: none; cursor: pointer; }
.chk input { accent-color: var(--accent); }

.floating {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 16px; z-index: 6;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 12px; display: flex; align-items: center; gap: 8px;
  font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.35);
}
.live-badge { top: calc(var(--tb) + 12px); bottom: auto; color: var(--ok); }
.hidden { display: none !important; }

/* ── 대화 패널 ── */
.quick-select, select, input[type=text], input[type=password], input[type=number], textarea {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit;
}
.quick-select { font-size: 12px; max-width: 150px; }
textarea { resize: vertical; width: 100%; }

.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.msg .who { font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.msg .body {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word;
}
.msg.user .body { background: var(--accent-2); color: #fff; border-color: transparent; }
.msg .thumb { max-width: 190px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.msg .think {
  font-size: 12px; color: var(--muted); border-left: 2px solid var(--line);
  padding: 4px 0 4px 10px; white-space: pre-wrap; font-style: italic;
}
.msg .acts { display: flex; gap: 6px; }
.msg .err { border-color: var(--danger); color: var(--danger); }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 8px;
            padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: center; gap: 8px; }

/* ── 설정 ── */
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text);
  padding: 0; width: min(560px, 94vw); max-height: 88dvh;
}
dialog::backdrop { background: rgba(0,0,0,.55); }
.settings-form { padding: 18px; overflow-y: auto; max-height: 88dvh; }
.settings-form h2 { margin: 0 0 14px; font-size: 17px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 0 0 12px; }
legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.row > span:first-child { flex: 0 0 130px; font-size: 13px; }
.row > span small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.row input[type=text], .row input[type=password], .row input[type=number], .row select { flex: 1; min-width: 0; }
.row.full { flex-direction: column; align-items: stretch; }
.hint { margin: 6px 0 0; font-size: 11px; color: var(--muted); }

.auth-status {
  margin-top: 8px; padding: 9px 11px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12px; line-height: 1.7; white-space: pre-wrap;
}
.auth-status .good { color: var(--ok); font-weight: 600; }
.auth-status .warn { color: #f59e0b; }
.auth-status code {
  background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 4px;
  font-size: 11px; user-select: all;
}
menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 99;
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--line); max-width: 90vw;
}

.only-narrow { display: none; }

/* ── 로그인 게이트 ──
   폰·태블릿이 주 사용처다. flex + margin:auto 를 쓰는 이유: place-items:center 는
   내용이 화면보다 길어지면 위쪽이 잘려서 스크롤로도 닿을 수 없다. */
.gate {
  position: fixed; inset: 0; z-index: 60; display: flex;
  align-items: center; justify-content: center; background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.gate-card {
  width: min(420px, 100%); margin: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.30);
}
.gate-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.gate-brand h1 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.gate-brand p  { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.gate-lead { margin: 0 0 14px; font-size: 13px; line-height: 1.7; color: var(--muted); }

/* 선택지는 손가락으로 누르는 것이다 — 폭 전체, 최소 높이 확보. */
.gate-choice {
  display: block; width: 100%; text-align: left; cursor: pointer;
  margin-bottom: 10px; padding: 14px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: inherit; -webkit-tap-highlight-color: transparent;
}
.gate-choice b     { display: block; font-size: 15px; }
.gate-choice small { display: block; margin-top: 4px; font-size: 12px; line-height: 1.6;
                     color: var(--muted); }
.gate-choice:hover { border-color: var(--accent-2); }
.gate-choice:active { transform: scale(.995); }
.gate-choice:disabled { opacity: .5; cursor: default; }
.gate-choice.hero {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, rgba(61,125,250,.16), rgba(61,125,250,.04));
}
.gate-choice.hero small b { display: inline; }

/* 키·코드 입력을 게이트 안에서 끝낸다 */
.gate-keyform { margin: 2px 0 10px; padding: 13px; border-radius: 12px;
                border: 1px solid var(--accent-2); background: var(--panel-2); }
.gate-seg { display: flex; gap: 6px; margin-bottom: 10px; }
.gate-seg button {
  flex: 1; padding: 9px 4px; font: inherit; font-size: 12.5px; cursor: pointer;
  border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted);
}
.gate-seg button.on { border-color: var(--accent); color: var(--text); font-weight: 700; }
/* 16px 미만이면 iOS 가 입력할 때 화면을 확대해 버린다 */
#gate-key, #gate-pair-input { width: 100%; font-size: 16px; padding: 12px; }
#gate-pair-input { width: 7em; text-align: center; letter-spacing: .12em; }
.gate-keyhint { margin: 8px 0 0; font-size: 11.5px; line-height: 1.65; color: var(--muted); }
.gate-keynote { margin: 9px 0 0; font-size: 11px; line-height: 1.6; color: var(--muted); }

/* 법으로 걸어 두어야 하는 안내. 작지만 흐릿하지는 않게 — 읽으라고 두는 글이지
   구색으로 두는 글이 아니다. 링크는 본문보다 진하게 해서 누를 것이 보이게 한다. */
/* word-break: keep-all 은 한국어에서 낱말 도중에 줄이 끊기지 않게 한다.
   이걸 안 넣으면 굵게 처리한 '운영자가 노트를 읽을 수 있습니다' 가 카드 밖으로
   삐져나가 '노트' 가 잘려 보였다 — 하필 제일 중요한 문장이다. */
.gate-legal { margin: 16px 0 0; padding-top: 13px; border-top: 1px solid var(--line);
              font-size: 11px; line-height: 1.65; color: var(--muted);
              word-break: keep-all; overflow-wrap: break-word; }
.gate-legal a { color: var(--fg); text-decoration: underline; text-underline-offset: 2px; }
.gate-legal b { color: var(--fg); }
.settings-legal { margin: 4px 18px 0; font-size: 12px; color: var(--muted); }
.settings-legal a { color: var(--muted); }
.gate-keyrow { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.gate-keyrow .primary-btn { padding: 11px 16px; font-size: 14px; }

.gate-msg { min-height: 18px; margin: 10px 0 0; font-size: 12.5px; color: var(--danger);
            line-height: 1.5; }
.gate-msg.ok { color: var(--ok); }

.gate-why { margin: 14px 0 0; border-top: 1px solid var(--line); padding-top: 12px; }
.gate-why summary { cursor: pointer; font-size: 12px; color: var(--muted); padding: 3px 0; }
.gate-why summary:hover { color: var(--text); }
.gate-why p { margin: 8px 0 0; font-size: 11.5px; line-height: 1.75; color: var(--muted); }

.gate-links { margin: 14px 0 0; font-size: 12px; text-align: center; color: var(--muted); }
.gate-links a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.gate-links a:hover { color: var(--text); }
.gate-links span { margin: 0 8px; opacity: .5; }

.gate-busy { display: flex; align-items: center; justify-content: center; gap: 10px;
             padding: 16px 0; font-size: 14px; color: var(--muted); }
.spinner {
  width: 15px; height: 15px; border-radius: 50%; display: inline-block;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 계정 / 자격증명 ── */
.who-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.who-name { flex: 1; font-size: 12px; color: var(--muted); overflow: hidden;
            text-overflow: ellipsis; white-space: nowrap; }
.who-name.warn { color: var(--warn, #f59e0b); }

/* 체험·요금제 잔량. 다 쓰고 나서야 알게 되면 늦다. */
.plan-row { font-size: 11.5px; color: var(--muted); margin-bottom: 8px;
            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-row.warn { color: var(--warn, #f59e0b); }

/* 이미 로그인돼 있다는 표시. 이게 없으면 AI 연결 화면이 '로그인 실패'로 읽힌다. */
.gate-signedin {
  margin: 0 0 12px; padding: 9px 12px; border-radius: 9px; font-size: 13px;
  background: color-mix(in srgb, var(--ok, #16a34a) 12%, transparent);
  color: var(--ok, #16a34a); word-break: break-all;
}

.active-tag { font-size: 11.5px; color: var(--ok); align-self: center; }

/* 기기 연결 */
.pair-cols { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.pair-col { flex: 1 1 240px; min-width: 0; }
.pair-label { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.pair-code {
  margin-top: 8px; padding: 10px; text-align: center; border-radius: 9px;
  background: var(--panel); border: 1px dashed var(--accent);
  font-size: 26px; font-weight: 700; letter-spacing: .18em;
  font-variant-numeric: tabular-nums; user-select: all;
}
.pair-code small { display: block; margin-top: 4px; font-size: 11px; font-weight: 400;
                   letter-spacing: 0; color: var(--muted); }
#pair-input { width: 8em; text-align: center; letter-spacing: .12em; font-size: 15px; }
#pair-count { font-size: 11.5px; color: var(--muted); font-weight: 400; }

.sub-note { margin-top: 12px; padding: 11px 13px; border: 1px solid var(--line);
            border-radius: 10px; background: var(--panel-2); }
.sub-note > b { font-size: 13px; }
.sub-note .hint { margin: 6px 0 0; }

.cred-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 0; }
.cred-name { flex: 0 0 128px; font-size: 13px; }
.cred-name em { display: block; font-style: normal; font-size: 11px; color: var(--muted); }
.cred-name em.on { color: var(--ok); }
.cred-row input { flex: 1 1 150px; min-width: 0; }
.hint a { color: var(--accent); }

/* ── 내 AI 계정 OAuth ── */
.oauth-box {
  border: 1px solid var(--accent-2); border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(61,125,250,.10), transparent);
  padding: 12px 14px; margin-bottom: 12px;
}
.oauth-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.oauth-head b { flex: 1; font-size: 14px; }
.oauth-head em {
  font-style: normal; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.oauth-head em.on { color: var(--ok); border-color: var(--ok); }
.oauth-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }

.adv { margin: 4px 0 10px; }
.adv summary { cursor: pointer; font-size: 12px; color: var(--muted); padding: 4px 0; }
.adv summary:hover { color: var(--text); }
.adv[open] summary { margin-bottom: 4px; }

/* ── 반응형: 태블릿 / 폰 ── */
@media (max-width: 1100px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px #0008; }
  #sidebar.open { transform: none; }
  #chat { position: fixed; inset: 0 0 0 auto; width: min(420px, 92vw); z-index: 20; transform: translateX(100%); transition: transform .2s; box-shadow: 0 0 40px #0008; }
  #chat.open { transform: none; }
  .only-narrow { display: grid; }
  #btn-ask { padding: 8px 10px; font-size: 12px; }
}
@media (max-width: 560px) {
  #size { width: 64px; }
  .swatches .swatch:nth-child(n+6) { display: none; }

  /* 폰에서는 카드가 아니라 '화면' 처럼 보이는 게 자연스럽다 */
  .gate { padding-left: max(14px, env(safe-area-inset-left));
          padding-right: max(14px, env(safe-area-inset-right)); }
  .gate-card { padding: 18px 4px; border: none; background: none; box-shadow: none; }
  .gate-choice { padding: 15px 16px; }
  .gate-choice b { font-size: 15.5px; }
}
