:root {
  --bg: #0b1220;
  --bg-2: #131b2e;
  --panel: #182239;
  --panel-2: #1f2a44;
  --line: #2a385a;
  --text: #e6ecff;
  --muted: #8b95b3;
  --accent: #6aa9ff;
  --accent-2: #4f8af0;
  --danger: #ef6b6b;
  --ok: #5dd39e;
  --warn: #f0b94f;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
               "Pretendard", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  background: var(--accent);
  color: #0b1220;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--accent-2); color: #fff; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.ghost:hover { background: var(--panel); color: var(--text); }
button.danger { background: var(--danger); color: #fff; }
button.primary-sm {
  background: var(--accent); color: #0b1220;
  padding: 6px 12px; font-size: 13px; font-weight: 700;
}
button.primary-sm:hover { background: var(--accent-2); color: #fff; }

input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; width: 100%; }

/* ----- 상단바 ----- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  padding-top: max(8px, env(safe-area-inset-top));
}
.brand {
  background: transparent; color: var(--text);
  border: 0; padding: 4px 8px;
  display: flex; align-items: center; gap: 8px;
  font-size: 17px; font-weight: 700; letter-spacing: 0.5px;
  cursor: pointer;
}
.brand:hover { background: var(--panel); }
.brand-icon { color: var(--accent); font-size: 18px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.topbar-actions input { width: 220px; }

/* ----- 레이아웃 ----- */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - var(--topbar-h));
}
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  padding: 14px;
  overflow-y: auto;
  max-height: calc(100vh - var(--topbar-h));
  position: sticky; top: var(--topbar-h);
}
.sidebar h2 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
  letter-spacing: 1px;
}
.sidebar h2.mt { margin-top: 18px; }
.sidebar ul { list-style: none; padding: 0; margin: 0; }
.sidebar li {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex; justify-content: space-between;
  color: var(--text);
}
.sidebar li.active, .sidebar li:hover { background: var(--panel); }
.sidebar li .count { color: var(--muted); font-size: 12px; }

.main {
  padding: 18px;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
}

/* ----- 입력 ----- */
.composer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 18px;
}
.composer textarea {
  background: var(--bg-2); border-color: var(--line);
  min-height: 320px;     /* 기존의 ~3배 */
  font-size: 16px;
  line-height: 1.6;
}
.composer-row {
  display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap;
  align-items: center;
}
.composer-row input[type="text"] { flex: 1; min-width: 140px; background: var(--bg-2); }
.composer-row select { background: var(--bg-2); }
#mic, #draw, #detail-mic, #detail-draw {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); font-weight: 500;
}
#mic.recording, #detail-mic.recording { background: var(--danger); color: #fff; }

.image-strip {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px;
}
.image-strip img {
  height: 100px; border-radius: 8px; border: 1px solid var(--line);
  object-fit: cover;
}

.status {
  margin: 10px 2px 0;
  display: inline-flex; align-items: center; gap: 6px;
}
.status.saving { color: var(--warn); }
.status.saved  { color: var(--ok); }
.status.err    { color: var(--danger); }

/* ----- 목록 ----- */
.memo-list { display: flex; flex-direction: column; gap: 10px; }
.memo-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.memo-card:hover { border-color: var(--accent); }
.memo-card .head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
  flex-wrap: wrap;
}
.memo-card h3 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memo-card .preview { color: var(--muted); margin: 4px 0 0; font-size: 13px; line-height: 1.5; }
.badge {
  background: var(--panel-2);
  color: var(--accent);
  font-size: 11px;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.tags .tag {
  font-size: 12px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line);
}

/* ----- 상세 ----- */
.memo-detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.detail-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.detail-title-input {
  width: 100%; font-size: 22px; font-weight: 700;
  background: transparent; border: 0; padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}
.detail-title-input:focus { border-bottom-color: var(--accent); }
.memo-detail .meta {
  display: flex; gap: 8px; align-items: center; color: var(--muted); margin: 8px 0 12px;
  flex-wrap: wrap;
}
.badge-edit {
  background: var(--panel-2); color: var(--accent);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 10px; font-size: 12px;
}
.body-edit {
  width: 100%; min-height: 360px;
  background: var(--bg-2); border: 1px solid var(--line);
  padding: 12px; border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}
.detail-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ----- 그림 모달 ----- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  display: grid; place-items: center;
  padding: 16px;
}
/* hidden 속성을 .modal display 규칙보다 우선시키기 위한 명시적 규칙 */
.modal[hidden] { display: none; }
.modal-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  width: min(720px, 96vw);
  max-height: 92vh;
  display: flex; flex-direction: column; gap: 10px;
}
.draw-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.draw-toolbar label {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 13px;
}
.draw-toolbar .spacer { flex: 1; }
#draw-canvas {
  width: 100%; aspect-ratio: 16 / 10;
  background: #fff; border-radius: 8px; border: 1px solid var(--line);
  touch-action: none; cursor: crosshair;
}
#draw-eraser.eraser-active {
  background: var(--warn); color: #0b1220;
  border-color: var(--warn);
}

/* ----- 유틸 ----- */
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ----- 로그인 ----- */
.login-body {
  display: grid; place-items: center; min-height: 100vh;
}
.login-card {
  width: min(360px, 92vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
}
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.login-card input { text-align: center; font-size: 18px; letter-spacing: 4px; }
.error { color: var(--danger); margin-top: 8px; }

/* ====== 모바일 ====== */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }

  .topbar { padding: 6px 10px; }
  .brand-text { font-size: 16px; }
  .topbar-actions input { width: 100%; max-width: 200px; }

  .main { padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }

  .composer { padding: 12px; border-radius: 14px; }
  .composer textarea { min-height: 280px; font-size: 16px; }
  .composer-row { gap: 6px; }
  .composer-row > * { flex: 0 0 auto; }
  .composer-row input[type="text"] { flex: 1 1 100%; order: 99; }   /* 제목은 줄바꿈 */
  .composer-row select { flex: 1 1 auto; min-width: 110px; }
  #new-memo { margin-left: auto; }

  .image-strip img { height: 84px; }

  .memo-card { padding: 10px 12px; }
  .memo-card h3 { font-size: 15px; }

  .memo-detail { padding: 12px; }
  .detail-title-input { font-size: 19px; }
  .body-edit { min-height: 320px; font-size: 16px; }

  .modal-content { width: 100%; padding: 10px; }
  .draw-toolbar { gap: 6px; }
  #draw-canvas { aspect-ratio: 4 / 3; }
}

@media (max-width: 380px) {
  .topbar-actions input { display: none; }   /* 너무 좁을 때 검색 숨김 (브랜드 클릭으로 홈) */
  .composer textarea { min-height: 240px; }
}
