:root {
  --bg: #f7f6f3;
  --paper: #ffffff;
  --ink: #1f1f1f;
  --muted: #8a8780;
  --line: #e7e5e0;
  --accent: #2f6f4f;
  --accent-soft: #e8f1ec;
  --tab-active: #ffffff;
  --tab-idle: #ecebe7;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.05);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", "맑은 고딕", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-icon { font-size: 20px; }
.nb-title {
  border: none; background: transparent; font-size: 16px; font-weight: 700;
  color: var(--ink); width: 150px; padding: 4px 6px; border-radius: 6px;
}
.nb-title:hover { background: var(--bg); }
.nb-title:focus { outline: 2px solid var(--accent-soft); background: #fff; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap; flex: 1;
  min-width: 280px;
}
.tool-group {
  display: flex; align-items: center; gap: 2px;
  padding: 0 6px; margin: 2px 0;
  border-right: 1px solid var(--line);
}
.tool-group:last-child { border-right: none; }
.toolbar button {
  min-width: 30px; height: 30px; padding: 0 7px;
  border: 1px solid transparent; background: transparent;
  border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s;
}
.toolbar button:hover { background: var(--bg); border-color: var(--line); }
.toolbar button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tool-select {
  height: 30px; border: 1px solid var(--line); background: var(--paper);
  border-radius: 6px; padding: 0 6px; font-size: 13px; cursor: pointer; color: var(--ink);
}
.tool-color {
  display: inline-flex; align-items: center; gap: 2px; height: 30px; padding: 0 4px;
  border: 1px solid transparent; border-radius: 6px; cursor: pointer; position: relative;
}
.tool-color:hover { background: var(--bg); border-color: var(--line); }
.tool-color span { font-size: 14px; font-weight: 700; }
.tool-color.hl span { font-weight: 400; }
.tool-color input[type="color"] {
  width: 18px; height: 18px; border: none; padding: 0; background: none; cursor: pointer;
}

/* ---------- Status / cloud ---------- */
.status { display: flex; align-items: center; gap: 8px; flex-shrink: 0; font-size: 13px; color: var(--muted); }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: #b9b6ae; flex-shrink: 0; }
.sync-dot.local { background: #b9b6ae; }
.sync-dot.saving { background: #e6b34d; animation: pulse 1s infinite; }
.sync-dot.synced { background: var(--accent); }
.sync-dot.error { background: #d9534f; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }
.save-btn {
  border: 1px solid var(--line); background: var(--paper); color: var(--muted);
  border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background .12s, color .12s, border-color .12s;
}
.save-btn:hover { background: var(--bg); }
.save-btn.dirty { background: var(--accent); color: #fff; border-color: var(--accent); }
.save-btn.dirty:hover { background: #265b40; }
.cloud-btn {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 13px;
}
.cloud-btn:hover { background: var(--bg); }
.cloud-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- Sheet / editor ---------- */
.sheet-area { flex: 1; overflow: auto; padding: 28px 16px 8px; position: relative; }
.editor {
  max-width: 820px; margin: 0 auto; min-height: calc(100vh - 200px);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 56px 64px; line-height: 1.7; outline: none; font-size: 16px;
}
.editor:focus { border-color: #d8d6d0; }
.editor:empty:before {
  content: "여기에 자유롭게 적어보세요…"; color: var(--muted); pointer-events: none;
}
.editor h1 { font-size: 1.9em; margin: .6em 0 .3em; }
.editor h2 { font-size: 1.5em; margin: .6em 0 .3em; }
.editor h3 { font-size: 1.2em; margin: .6em 0 .3em; }
.editor p { margin: .5em 0; }
.editor ul, .editor ol { padding-left: 1.4em; margin: .5em 0; }
.editor blockquote {
  margin: .6em 0; padding: .2em 1em; border-left: 3px solid var(--accent);
  color: #4a4a4a; background: var(--accent-soft); border-radius: 0 6px 6px 0;
}
.editor pre {
  background: #2b2b2b; color: #f3f3f3; padding: 14px 16px; border-radius: 8px;
  font-family: "SF Mono", Consolas, "D2Coding", monospace; font-size: .92em; overflow-x: auto;
}
.editor a { color: var(--accent); }
.editor table { border-collapse: collapse; margin: .6em 0; width: 100%; }
.editor table td, .editor table th { border: 1px solid var(--line); padding: 6px 10px; min-width: 40px; }
.editor table th { background: var(--bg); font-weight: 600; }
.editor ul[data-check] { list-style: none; padding-left: .2em; }
.editor li.check { list-style: none; }
.editor input[type="checkbox"] { margin-right: .5em; transform: translateY(1px); cursor: pointer; }

.word-count {
  max-width: 820px; margin: 6px auto 0; text-align: right; color: var(--muted); font-size: 12px;
  padding-right: 4px;
}

/* ---------- Excel-style tabs ---------- */
.tabbar {
  display: flex; align-items: flex-end; gap: 2px;
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 0 8px; height: 40px; overflow-x: auto; flex-shrink: 0;
}
.tabbar::-webkit-scrollbar { height: 6px; }
.tab-add {
  flex-shrink: 0; width: 30px; height: 28px; margin-bottom: 4px; margin-right: 4px;
  border: 1px solid var(--line); background: var(--paper); border-radius: 6px;
  cursor: pointer; font-size: 16px; color: var(--muted); line-height: 1;
}
.tab-add:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tabs { display: flex; align-items: flex-end; gap: 2px; }
.tab {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px 0 12px; margin-bottom: 0;
  background: var(--tab-idle); border: 1px solid var(--line); border-bottom: none;
  border-radius: 8px 8px 0 0; cursor: pointer; font-size: 13px; color: #555;
  white-space: nowrap; max-width: 200px; position: relative; user-select: none;
}
.tab:hover { background: #f3f2ee; }
.tab.active {
  background: var(--tab-active); color: var(--ink); font-weight: 600; height: 34px;
  box-shadow: 0 -2px 6px rgba(0,0,0,.04);
}
.tab.active:before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent); border-radius: 8px 8px 0 0;
}
.tab .tab-name {
  font: inherit; color: inherit; max-width: 150px; outline: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tab .tab-name[contenteditable="true"] {
  background: #fff; outline: 1.5px solid var(--accent); border-radius: 4px;
  padding: 0 4px; cursor: text; overflow: visible;
}
.tab .tab-close {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px; border-radius: 4px; opacity: 0;
}
.tab:hover .tab-close, .tab.active .tab-close { opacity: 1; }
.tab .tab-close:hover { background: #e0ded8; color: #d9534f; }
.tab-spacer { flex: 1; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(20,20,20,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--paper); width: min(440px, 92vw); border-radius: 14px;
  padding: 26px 26px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-card h2 { margin: 0 0 8px; font-size: 19px; }
.modal-desc { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.modal-input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 15px; margin-bottom: 10px;
}
.modal-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.modal-check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: #555; margin-bottom: 6px; }
.modal-msg { font-size: 13px; min-height: 18px; margin: 4px 0; }
.modal-msg.ok { color: var(--accent); }
.modal-msg.err { color: #d9534f; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 9px 18px; font-size: 14px; cursor: pointer; font-weight: 600;
}
.btn-primary:hover { background: #265b40; }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); color: #555;
  border-radius: 8px; padding: 9px 14px; font-size: 14px; cursor: pointer;
}
.btn-ghost:hover { background: var(--bg); }
.btn-ghost.danger { color: #d9534f; border-color: #f0c9c7; }
.btn-ghost.danger:hover { background: #fcf0ef; }
.modal-foot { margin: 12px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; text-align: center; }
.hidden { display: none !important; }

/* OAuth 버튼 */
.oauth-list { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 6px; }
.oauth-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 11px 14px; border-radius: 9px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--line); background: #fff; color: #1f1f1f;
  transition: filter .12s, box-shadow .12s;
}
.oauth-btn:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); filter: brightness(.99); }
.oauth-btn .oauth-ico {
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 800; font-size: 13px;
}
.oauth-btn.google .oauth-ico { background: #fff; color: #4285F4; border: 1px solid #e0e0e0; }
.oauth-btn.kakao  { background: #FEE500; border-color: #FEE500; color: #191600; }
.oauth-btn.kakao  .oauth-ico { background: #191600; color: #FEE500; }
.oauth-btn.naver  { background: #03C75A; border-color: #03C75A; color: #fff; }
.oauth-btn.naver  .oauth-ico { background: #fff; color: #03C75A; }

.divider { display: flex; align-items: center; gap: 10px; margin: 14px 0 10px; color: var(--muted); font-size: 12px; }
.divider:before, .divider:after { content: ""; flex: 1; height: 1px; background: var(--line); }

.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 12.5px; padding: 4px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 56px; left: 50%; transform: translateX(-50%);
  background: #2b2b2b; color: #fff; padding: 9px 16px; border-radius: 20px;
  font-size: 13px; z-index: 200; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  opacity: 1; transition: opacity .3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .editor { padding: 28px 22px; min-height: calc(100vh - 230px); }
  .sheet-area { padding: 14px 8px 4px; }
  .nb-title { width: 110px; }
  .toolbar { order: 3; width: 100%; min-width: 0; }
  .status { margin-left: auto; }
  .tool-group { padding: 0 4px; }
}
