:root {
  --bg: #f4f5f7;
  --bg-sidebar: #fff;
  --bg-hover: #f2f2f7;
  --bg-card: #fff;
  --bg-card-1: #f0f5ff;
  --bg-card-2: #f0faf5;
  --bg-msg: #f8f9fa;
  --bg-input: #fff;
  --text: #1d1d1f;
  --text-secondary: #8e8e93;
  --text-muted: #636366;
  --border: #e5e5ea;
  --border-soft: #eee;
  --accent: #007aff;
  --badge-0-bg: #e8f0fe;
  --badge-0-text: #1967d2;
  --badge-1-bg: #d6e4ff;
  --badge-1-text: #0958d9;
  --badge-2-bg: #d9f0e5;
  --badge-2-text: #135200;
  --border-0: #e5e5ea;
  --border-1: #d6e4ff;
  --border-2: #d9f0e5;
  --accent-0: #007aff;
  --accent-1: #4096ff;
  --accent-2: #52c41a;
  --text-1: #2c3e50;
  --text-2: #3a5a3f;
}

[data-theme="dark"] {
  --bg: #1c1c1e;
  --bg-sidebar: #2c2c2e;
  --bg-hover: #3a3a3c;
  --bg-card: #2c2c2e;
  --bg-card-1: #1e2a3a;
  --bg-card-2: #1a2e24;
  --bg-msg: #3a3a3c;
  --bg-input: #3a3a3c;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --text-muted: #8e8e93;
  --border: #38383a;
  --border-soft: #48484a;
  --accent: #0a84ff;
  --badge-0-bg: #1a3a5a;
  --badge-0-text: #64b5f6;
  --badge-1-bg: #2a4a6a;
  --badge-1-text: #90caf9;
  --badge-2-bg: #1a4a2a;
  --badge-2-text: #81c784;
  --border-0: #38383a;
  --border-1: #2a3a5a;
  --border-2: #2a4a3a;
  --accent-0: #0a84ff;
  --accent-1: #64b5f6;
  --accent-2: #66bb6a;
  --text-1: #c0c8d0;
  --text-2: #a0c0a8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; height: 100vh; background: var(--bg); color: var(--text); }

#app { display: flex; height: 100vh; flex-wrap: wrap; }

#sidebar {
  width: 280px; background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
#sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 28px 20px 16px; border-bottom: 1px solid var(--border); }
#brand { display: flex; align-items: center; gap: 8px; }
.book-icon { color: var(--accent); flex-shrink: 0; }
#sidebar-header h1 { font-size: 18px; font-weight: 700; letter-spacing: -.3px; color: var(--text); }

#theme-toggle {
  background: none; border: none; cursor: pointer; padding: 4px; border-radius: 6px;
  color: var(--text-secondary); transition: background .15s; line-height: 0;
}
#theme-toggle:hover { background: var(--bg-hover); }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

#refresh-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 20px 4px; font-size: 12px; color: var(--text-secondary); }
#refresh-btn {
  background: transparent; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px;
  padding: 4px 14px; font-size: 12px; font-weight: 500; cursor: pointer; transition: all .15s;
}
#refresh-btn:hover { background: var(--accent); color: #fff; }
#refresh-btn:disabled { opacity: .4; cursor: not-allowed; background: transparent; color: var(--accent); }

#date-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.date-item {
  padding: 10px 20px; cursor: pointer; color: var(--text);
  font-size: 14px; font-weight: 450; transition: all .12s;
}
.date-item:hover { background: var(--bg-hover); }
.date-item.active { background: var(--bg-hover); font-weight: 600; }
.date-item.is-today { color: var(--accent); }

#content {
  flex: 1; overflow-y: auto; padding: 40px 48px; background: var(--bg);
  display: flex; flex-direction: column;
}
#welcome { text-align: center; padding-top: 100px; color: var(--text-secondary); flex-shrink: 0; }
#welcome h2 { font-size: 20px; font-weight: 600; margin-bottom: 6px; color: var(--text); }

#entry-view { display: none; flex-direction: column; flex: 1; min-height: 0; }
#entry-view.visible { display: flex; }

#entry-date {
  font-size: 22px; font-weight: 700; color: var(--text);
  margin-bottom: 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#entry-scroll { flex: 1; overflow-y: auto; min-height: 0; }
#entry-content { max-width: 680px; display: flex; flex-direction: column; gap: 10px; padding-bottom: 16px; }

#entry-comments { flex-shrink: 0; border-top: 1px solid var(--border); padding-top: 12px; max-width: 680px; background: var(--bg); }
#ec-header { margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
#ec-header h3 { font-size: 15px; font-weight: 600; color: var(--text); }
#ec-count { font-size: 12px; font-weight: 400; color: var(--text-secondary); margin-left: 4px; }
#ec-expand { display: none; background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px; border-radius: 6px; line-height: 0; transition: transform .2s; }
#ec-expand:hover { background: var(--bg-hover); }
#ec-list { display: flex; flex-direction: column; gap: 0; margin-bottom: 10px; }
#ec-list .mb-msg { margin-bottom: 6px; }
#ec-input-area { display: flex; gap: 8px; align-items: flex-end; }
#ec-input {
  flex: 1; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; outline: none; resize: none;
  font-family: inherit; line-height: 1.4; min-height: 36px; max-height: 96px;
  background: var(--bg-input); color: var(--text);
}
#ec-input:focus { border-color: var(--accent); }
#ec-input::placeholder { color: var(--text-secondary); }
#ec-send {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 18px; font-size: 14px; font-weight: 500; cursor: pointer;
  white-space: nowrap; height: 36px; transition: opacity .15s;
}
#ec-send:hover { opacity: .85; }
#ec-send:disabled { opacity: .4; cursor: not-allowed; }

.entry-item {
  border-radius: 8px; padding: 12px 16px; border: 1px solid transparent;
  display: flex; align-items: flex-start; gap: 12px; border-left: 3px solid;
}
.entry-item.depth-0 { margin-left: 0; background: var(--bg-card); border-color: var(--border-0); border-left-color: var(--accent-0); }
.entry-item.depth-1 { margin-left: 4ch; background: var(--bg-card-1); border-color: var(--border-1); border-left-color: var(--accent-1); }
.entry-item.depth-2 { margin-left: 8ch; background: var(--bg-card-2); border-color: var(--border-2); border-left-color: var(--accent-2); }
.entry-item .time-badge {
  border-radius: 4px; padding: 1px 7px; font-size: 12px; font-weight: 500;
  white-space: nowrap; flex-shrink: 0; margin-top: 2px;
}
.entry-item.depth-0 .time-badge { background: var(--badge-0-bg); color: var(--badge-0-text); }
.entry-item.depth-1 .time-badge { background: var(--badge-1-bg); color: var(--badge-1-text); }
.entry-item.depth-2 .time-badge { background: var(--badge-2-bg); color: var(--badge-2-text); }
.entry-item .entry-text { font-size: 15px; color: var(--text); line-height: 1.6; flex: 1; }
.entry-item.depth-1 .entry-text { font-size: 14px; color: var(--text-1); }
.entry-item.depth-2 .entry-text { font-size: 13px; color: var(--text-2); }

#message-board {
  width: 320px; background: var(--bg-sidebar); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; height: 100vh;
}
#mb-header { padding: 28px 20px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
#mb-header h3 { font-size: 16px; font-weight: 600; color: var(--text); }
#mb-count { font-size: 12px; font-weight: 400; color: var(--text-secondary); margin-left: 4px; }
#mb-minimize { display: none; background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px; border-radius: 6px; line-height: 0; transition: transform .2s; }
#mb-minimize:hover { background: var(--bg-hover); }
.show-full-msg #mb-minimize { transform: rotate(180deg); }
#mb-messages { flex: 1; overflow-y: auto; padding: 12px 16px; }
.mb-msg {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 9px 12px; background: var(--bg-msg); border-radius: 8px;
  margin-bottom: 8px; border: 1px solid var(--border-soft);
}
.mb-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px; margin-top: 1px;
}
.mb-body { flex: 1; min-width: 0; }
#mb-input-area {
  padding: 10px 16px 14px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
}
#mb-input {
  flex: 1; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; outline: none; resize: none;
  font-family: inherit; line-height: 1.4; min-height: 36px; max-height: 96px;
  background: var(--bg-input); color: var(--text);
}
#mb-input:focus { border-color: var(--accent); }
#mb-input::placeholder { color: var(--text-secondary); }
#mb-send {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 18px; font-size: 14px; font-weight: 500; cursor: pointer;
  white-space: nowrap; height: 36px; transition: opacity .15s;
}
#mb-send:hover { opacity: .85; }
#mb-send:disabled { opacity: .4; cursor: not-allowed; }

.toast {
  display: none; position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px; border-radius: 8px; font-size: 14px; z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,.15); opacity: 1; transition: opacity .3s;
}
.toast.info { background: var(--badge-0-bg); color: var(--badge-0-text); }
.toast.success { background: var(--badge-2-bg); color: var(--badge-2-text); }
.toast.warn { background: #fef7e0; color: #e37400; }
[data-theme="dark"] .toast.warn { background: #3a3a1a; color: #ffb74d; }
.toast.error { background: #ffebee; color: #d32f2f; }
[data-theme="dark"] .toast.error { background: #4a1a1a; color: #ef5350; }

@media (max-width: 1199px) {
  #message-board { width: 100%; border-left: none; border-top: 1px solid var(--border); }
}
@media (max-width: 768px) {
  #app { flex-direction: column; flex-wrap: nowrap; }
  #sidebar { width: 100%; border-right: none; flex: 1; max-height: none; padding-bottom: 28vh; }
  #content { padding: 16px 20px; display: none; }
  #welcome { display: none !important; }

  #message-board {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    height: 28vh; width: 100%; border-left: none; border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0; box-shadow: 0 -3px 12px rgba(0,0,0,.08);
    background: var(--bg-sidebar); transition: height .25s;
  }
  #mb-header { cursor: pointer; padding: 12px 16px 10px; }
  #message-board #mb-messages { padding: 0 16px 12px; }
  #mb-minimize { display: inline-flex; }
  .show-full-msg #mb-minimize { transform: rotate(180deg); }
  #message-board .mb-msg:nth-child(n+3) { display: none; }
  #message-board #mb-input-area { display: none !important; }
  #message-board #mb-messages { overflow: hidden; }

  .show-entry #sidebar { display: none; }
  .show-entry #content {
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
    width: 100%; height: 100vh; z-index: 200; background: var(--bg);
  }
  .show-entry #message-board { display: none; }
  .show-entry #entry-scroll { flex: 1; overflow-y: auto; }
  .show-entry #entry-comments { flex-shrink: 0; }

  #ec-expand { display: inline-flex; }
  #entry-comments .mb-msg:nth-child(n+3) { display: none; }
  .show-full-cmt #entry-comments { position: fixed; bottom: 0; left: 0; right: 0; z-index: 400; height: 100vh; background: var(--bg-sidebar); overflow-y: auto; padding: 16px 20px; border-top: 1px solid var(--border); }
  .show-full-cmt #entry-comments .mb-msg:nth-child(n+3) { display: flex; }
  .show-full-cmt #ec-expand { transform: rotate(180deg); }

  .show-full-msg #message-board {
    height: 100vh; max-height: 100vh; border-radius: 0; z-index: 300;
  }
  .show-full-msg #mb-header { padding: 28px 20px 14px; cursor: default; }
  .show-full-msg #message-board .mb-msg:nth-child(n+3) { display: flex; }
  .show-full-msg #message-board #mb-input-area { display: flex !important; }
  .show-full-msg #message-board #mb-messages { overflow-y: auto; flex: 1; padding: 12px 16px; }
}

#mobile-entry-bar { display: none; }
@media (max-width: 768px) {
  #mobile-entry-bar {
    display: none; align-items: center; gap: 8px; padding: 0 0 14px;
    border-bottom: 1px solid var(--border); margin-bottom: 16px;
  }
  .show-entry #mobile-entry-bar { display: flex; }
  #mobile-back {
    display: inline-flex; align-items: center; gap: 4px;
    background: none; border: none; color: var(--accent);
    font-size: 14px; cursor: pointer; padding: 4px 4px 4px 0;
    flex-shrink: 0;
  }
  #mobile-entry-title {
    font-size: 15px; font-weight: 600; color: var(--text); flex: 1; text-align: center; margin-right: 40px;
  }
}

#changelog-btn {
  background: var(--accent); border: none; border-radius: 6px;
  color: #fff; font-size: 12px; font-weight: 600; padding: 4px 12px;
  cursor: pointer; transition: opacity .15s; line-height: 1.4; white-space: nowrap;
}
#changelog-btn:hover { opacity: .8; }

#changelog-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 500; align-items: center; justify-content: center; }
#changelog-modal.show { display: flex; }
#changelog-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.35); }
#changelog-panel {
  position: relative; background: var(--bg-sidebar); display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
#changelog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#changelog-header h3 { font-size: 17px; font-weight: 700; color: var(--text); }
#changelog-close {
  background: none; border: none; color: var(--text-secondary); cursor: pointer;
  padding: 4px; border-radius: 6px; line-height: 0;
}
#changelog-close:hover { background: var(--bg-hover); color: var(--text); }
#changelog-body { padding: 20px 24px; overflow-y: auto; line-height: 2; }
.cl-item { font-size: 14px; color: var(--text); padding: 2px 0; }
.cl-date { padding: 6px 0 2px; }
.cl-date span {
  background: linear-gradient(180deg, transparent 55%, #ffd54f 55%);
  padding: 0 4px; font-size: 15px; font-weight: 700; color: var(--text);
}
[data-theme="dark"] .cl-date span {
  background: linear-gradient(180deg, transparent 55%, #5c4a00 55%);
}

@media (min-width: 769px) {
  #changelog-panel { width: 500px; max-height: 90vh; border-radius: 14px; }
}
@media (max-width: 768px) {
  #changelog-panel { width: 100%; height: 100%; border-radius: 0; }
  #changelog-header { padding: 16px 20px; }
  #changelog-body { padding: 16px 20px; }
  .cl-date span { font-size: 14px; }
}


