:root {
  --bg: #fafaf7;
  --fg: #222;
  --muted: #888;
  --accent: #8b6f47;
  --border: #e5e3dd;
  --card: #fff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.55 Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--fg);
}

.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-page form {
  background: var(--card);
  padding: 2.5rem 2rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 1rem;
}
.login-page h1 { margin: 0 0 0.5rem; font-size: 1.6rem; text-align: center; }
.login-page input {
  padding: 0.75rem; font-size: 1rem; border: 1px solid var(--border); border-radius: 4px;
  font-family: inherit;
}
.login-page button {
  padding: 0.75rem; font-size: 1rem; background: var(--accent); color: white;
  border: 0; border-radius: 4px; cursor: pointer;
}
.error { color: #b00020; min-height: 1.2em; font-size: 0.9rem; }

header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.tabs { display: flex; gap: 0.25rem; }
.tab, header button, header a {
  padding: 0.4rem 0.9rem;
  background: transparent; border: 1px solid transparent;
  border-radius: 4px; cursor: pointer; font: inherit; font-size: 0.95rem;
  color: inherit; text-decoration: none;
}
.tab.active { background: var(--accent); color: white; }
header button:hover, header a:hover { background: #eee; }
.tab.active:hover { background: var(--accent); }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 0.9rem; }

.view { max-width: 760px; margin: 0 auto; padding: 1.5rem 1rem; }
.hidden { display: none !important; }

.write-toolbar, .read-toolbar {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
  flex-wrap: wrap;
}
.write-toolbar input[type="date"],
.read-toolbar input[type="search"],
.read-toolbar select,
.read-toolbar button {
  font: inherit; padding: 0.4rem 0.6rem;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--card);
}
.read-toolbar input[type="search"] { flex: 1; min-width: 180px; }
.read-toolbar button { cursor: pointer; }
.read-toolbar button:hover { background: #eee; }

.otd {
  background: #fff6e0;
  border: 1px solid #ead9a4;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.otd h3 { margin: 0 0 0.75rem; font-size: 1rem; color: var(--accent); }
.otd-card { padding: 0.5rem 0; border-top: 1px dashed #ead9a4; }
.otd-card:first-of-type { border-top: 0; padding-top: 0; }
.otd-date { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.otd-snippet { font-style: italic; font-size: 0.95rem; }
.otd-full { margin-top: 0.5rem; padding: 0; background: var(--card); border-radius: 4px; padding: 0.75rem; }
.link-btn {
  background: none; border: 0; padding: 0.25rem 0;
  color: var(--accent); cursor: pointer; font: inherit; font-size: 0.85rem;
  text-decoration: underline;
}

#editor-container { background: var(--card); border-radius: 6px; }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--border); }
.ql-container.ql-snow { min-height: 60vh; font: inherit; font-size: 1.05rem; }
.ql-editor { padding: 1.5rem; }
.ql-editor img { max-width: 100%; height: auto; border-radius: 4px; margin: 0.5rem 0; cursor: pointer; }
.ql-editor img.selected-img { outline: 2px solid var(--accent); outline-offset: 2px; }

.img-size-toolbar {
  position: absolute;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px;
  display: flex; gap: 2px;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.img-size-toolbar button {
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  min-width: 32px;
}
.img-size-toolbar button:hover { background: var(--bg); }
.img-size-toolbar button.active { background: var(--accent); color: white; }
.ql-editor iframe.ql-video, .entry-body iframe.ql-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: 0;
  border-radius: 4px;
  margin: 0.5rem 0;
}
.ql-editor audio, .entry-body audio { width: 100%; margin: 0.5rem 0; display: block; }
.ql-toolbar.ql-snow .ql-audio { width: auto; padding: 0 0.5rem; font: inherit; }
.ql-toolbar.ql-snow .ql-audio::before { content: '🎵'; font-size: 0.9rem; }
.ql-toolbar.ql-snow .ql-audio:hover { color: var(--accent); }

.ql-editor .gallery, .entry-body .gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem;
  margin: 0.5rem 0;
}
.ql-editor .gallery img, .entry-body .gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  aspect-ratio: 1;
  margin: 0;
  border-radius: 4px;
}

.stats-bar {
  display: flex; gap: 1rem; flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.stats-bar .stat { display: flex; flex-direction: column; min-width: 80px; }
.stats-bar .stat .value { font-size: 1.3rem; color: var(--accent); font-weight: bold; }
.stats-bar .stat .label { color: var(--muted); font-size: 0.8rem; }

.calendar-wrap {
  background: var(--card); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.75rem 1rem; margin-bottom: 1rem;
}
.calendar-wrap summary { cursor: pointer; color: var(--accent); font-weight: bold; user-select: none; }
.calendar-header { display: flex; align-items: center; gap: 0.5rem; margin: 0.75rem 0; }
.calendar-header button { padding: 0.25rem 0.75rem; font: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.calendar-header #cal-year { font-size: 1.1rem; font-weight: bold; min-width: 4rem; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }
.cal-month { }
.cal-month-name { font-size: 0.85rem; color: var(--muted); text-align: center; margin-bottom: 0.25rem; }
.cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day {
  aspect-ratio: 1; border-radius: 2px; background: #efece3;
  font-size: 0.7rem; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  cursor: default;
}
.cal-day.filled { background: #c8a574; color: white; cursor: pointer; }
.cal-day.filled.filled-2 { background: #a8875b; }
.cal-day.filled.filled-3 { background: var(--accent); }
.cal-day.empty-month { visibility: hidden; }
.cal-day.filled:hover { outline: 2px solid var(--accent); }

.comments-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.comments-section h3 { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--muted); }
.comment {
  background: var(--bg); border-radius: 4px; padding: 0.5rem 0.75rem; margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.comment-meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem; display: flex; justify-content: space-between; }
.comment-body { white-space: pre-wrap; }
.comment-delete {
  background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 0.75rem;
}
.comment-delete:hover { color: #b00020; }
.comment-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.comment-form textarea {
  flex: 1; font: inherit; font-size: 0.9rem; padding: 0.5rem;
  border: 1px solid var(--border); border-radius: 4px; resize: vertical;
  min-height: 2.5rem; max-height: 10rem;
}
.comment-form button {
  font: inherit; padding: 0 1rem; background: var(--accent); color: white;
  border: 0; border-radius: 4px; cursor: pointer; align-self: stretch;
}

.entry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
}
.entry h2 {
  margin: 0 0 1rem;
  font-size: 1.2rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}
.entry-body img { max-width: 100%; height: auto; border-radius: 4px; }

.resize-dialog {
  border: 0; border-radius: 8px; padding: 0;
  max-width: 520px; width: 92vw;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.resize-dialog::backdrop { background: rgba(0,0,0,0.4); }
.resize-form { padding: 1.5rem; display: flex; flex-direction: column; gap: 0.75rem; font: inherit; }
.resize-form h3 { margin: 0; color: var(--accent); font-size: 1rem; }
.resize-preview {
  position: relative;
  background: #f3f1eb; border-radius: 4px;
  max-height: 320px; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  user-select: none;
  cursor: ns-resize;
}
.resize-preview img { max-width: 100%; max-height: 320px; display: block; pointer-events: none; }
.resize-handle {
  position: absolute; right: 0; bottom: 0;
  width: 22px; height: 22px;
  background: var(--accent);
  cursor: nwse-resize;
  border-radius: 4px 0 4px 0;
  box-shadow: -1px -1px 0 var(--card);
}
.resize-handle:hover { background: #a8875b; }
.resize-hint { text-align: center; font-size: 0.8rem; margin-top: -0.25rem; }
.resize-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.resize-form input[type="range"] { width: 100%; }
.resize-info { font-size: 0.85rem; color: var(--muted); padding: 0.5rem; background: var(--bg); border-radius: 4px; text-align: center; }
.resize-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.resize-actions button {
  padding: 0.5rem 1rem; font: inherit; font-size: 0.95rem;
  border: 1px solid var(--border); border-radius: 4px; background: var(--card); cursor: pointer;
}
.resize-actions button.primary { background: var(--accent); color: white; border-color: var(--accent); }

@media (max-width: 640px) {
  .view { padding: 1rem 0.5rem; }
  .entry { padding: 1rem; }
  header { flex-wrap: wrap; }
}
