*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #4a9eff;
  --todo-color: #ff6b6b;
  --bg: #fafafa;
  --surface: #fff;
  --border: #e8e8e8;
  --text: #1a1a1a;
  --muted: #888;
  --radius-card: 16px;
  --radius-btn: 10px;
  --radius-chip: 20px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --max-w: 520px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ===== Layout ===== */
.app-wrapper {
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: 72px;
}

@media (min-width: 768px) {
  .app-wrapper { max-width: 640px; }
}

/* ===== Input area ===== */
.input-area {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row { display: flex; gap: 8px; align-items: center; }

.datetime-row { gap: 6px; }

input[type="datetime-local"],
input[type="date"],
input[type="text"],
textarea {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); }

input[type="datetime-local"] { flex: 1; }

.btn-now {
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

/* mode toggle */
.mode-toggle { display: flex; gap: 6px; }
.mode-btn {
  flex: 1;
  padding: 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--bg);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.mode-btn.active {
  border-color: var(--accent);
  background: #eaf3ff;
  color: var(--accent);
  font-weight: 600;
}
.mode-btn.todo-active {
  border-color: var(--todo-color);
  background: #fff2f2;
  color: var(--todo-color);
  font-weight: 600;
}

/* text input */
.text-input-row { position: relative; }
#textInput {
  padding-right: 44px;
  resize: none;
  height: 40px;
  overflow: hidden;
}
.btn-voice {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  color: var(--muted);
}
.btn-voice.recording { color: var(--todo-color); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* tag area */
.tag-area { display: flex; flex-direction: column; gap: 6px; }
.tag-row { display: flex; gap: 6px; align-items: center; }
#tagInput { flex: 1; }
.tag-suggestions { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-chip {
  padding: 4px 12px;
  background: #f0f0f0;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s;
}
.tag-chip:hover { background: #e0e0e0; }
.tag-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow);
  z-index: 200;
  max-height: 180px;
  overflow-y: auto;
}
.tag-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}
.tag-dropdown-item:hover { background: #f5f5f5; }
.tag-row { position: relative; }

/* mood */
.mood-row { display: flex; gap: 6px; align-items: center; }
.mood-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.mood-btns { display: flex; gap: 4px; }
.mood-btn {
  font-size: 22px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  transition: transform 0.1s, border-color 0.1s;
}
.mood-btn:hover { transform: scale(1.2); }
.mood-btn.selected { border-color: var(--accent); }

/* todo options */
.todo-options { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#dueDate { width: auto; flex: 1; min-width: 130px; }
.priority-btns { display: flex; gap: 4px; }
.priority-btn {
  padding: 6px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--bg);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.priority-btn.selected { border-color: var(--accent); background: #eaf3ff; }

/* submit */
.btn-submit {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-btn);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-submit:active { opacity: 0.8; }
.btn-submit.todo-mode { background: var(--todo-color); }

/* ===== Dashboard ===== */
.dashboard { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.section {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px 8px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.section-body { padding: 8px 0; }

/* Entry list */
.entry-item {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.entry-item:last-child { border-bottom: none; }
.entry-time { font-size: 11px; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.entry-mood { font-size: 18px; }
.entry-content { flex: 1; min-width: 0; }
.entry-tag { font-size: 11px; color: var(--accent); margin-bottom: 2px; }
.entry-text { font-size: 14px; word-break: break-word; }

/* Todo list */
.todo-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  transition: background 0.1s;
}
.todo-item:last-child { border-bottom: none; }
.todo-item:hover { background: #f8f8f8; }
.todo-check {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.todo-item:hover .todo-check { border-color: var(--accent); }
.todo-content { flex: 1; min-width: 0; }
.todo-text { font-size: 14px; }
.todo-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.todo-meta.overdue { color: var(--todo-color); font-weight: 600; }
.priority-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-chip);
  flex-shrink: 0;
}
.priority-badge.high { background: #fff0f0; color: var(--todo-color); }
.priority-badge.mid  { background: #fff8e0; color: #e6a800; }
.priority-badge.low  { background: #f0f8ff; color: var(--accent); }

/* Streak */
.streak-grid {
  display: grid;
  grid-template-columns: repeat(30, 1fr);
  gap: 2px;
  padding: 12px 16px;
}
.streak-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: #eee;
}
.streak-cell.has-entry { background: var(--accent); }

/* Recent done */
.done-item {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.done-item:last-child { border-bottom: none; }
.done-check { color: #4caf50; font-size: 16px; flex-shrink: 0; }
.done-text { font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
.reopen-btn {
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: #f5f5f5;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.reopen-btn:hover { background: #eee; color: var(--text); }

/* Filter tabs (todo page) */
.filter-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}
.filter-tab {
  flex: 1;
  padding: 12px 0;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  transition: all 0.15s;
}
.filter-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* Todo checked state */
.todo-check.checked {
  border-color: #4caf50;
  background: #4caf50;
  color: #fff;
  font-size: 12px;
}

.empty-msg { padding: 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ===== Tab bar ===== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 200;
  max-width: var(--max-w);
  margin: 0 auto;
}

@media (min-width: 768px) {
  .tab-bar { max-width: 640px; }
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 12px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  gap: 2px;
  transition: color 0.15s;
}
.tab-item.active { color: var(--accent); }
.tab-item .tab-icon { font-size: 22px; }

/* ===== Google Sheets FAB ===== */
.sheets-fab {
  position: fixed;
  bottom: 80px;
  right: 12px;
  width: 44px;
  height: 44px;
  background: #0f9d58;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 150;
  transition: transform 0.15s, box-shadow 0.15s;
}
.sheets-fab:hover { transform: scale(1.08); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-chip);
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ===== Books ===== */
.search-area {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Book status filter tabs */
#bookFilterTabs {
  overflow-x: auto;
  scrollbar-width: none;
}
#bookFilterTabs::-webkit-scrollbar { display: none; }
#bookFilterTabs .filter-tab { white-space: nowrap; padding: 10px 12px; font-size: 12px; }

.book-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 12px; }

.book-card {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 12px;
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.book-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.book-cover {
  width: 60px;
  height: 84px;
  object-fit: cover;
  border-radius: 6px;
  background: #eee;
  flex-shrink: 0;
}
.book-cover-placeholder {
  width: 60px;
  height: 84px;
  border-radius: 6px;
  background: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.book-info { flex: 1; min-width: 0; }
.book-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.book-author { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.book-status-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-chip);
  background: #eaf3ff;
  color: var(--accent);
}

.stars { color: #f4b400; font-size: 14px; }

/* Register form */
.register-form {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-group { display: flex; flex-direction: column; }

.medium-btns, .status-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.option-btn {
  padding: 6px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-chip);
  background: var(--bg);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.option-btn.selected { border-color: var(--accent); background: #eaf3ff; color: var(--accent); }

.star-input { display: flex; gap: 4px; }
.star-btn { font-size: 24px; cursor: pointer; color: #ddd; transition: color 0.1s; }
.star-btn.filled { color: #f4b400; }

/* ===== Chat ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
}
.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.ai {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-input-area {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-input-area input { flex: 1; }
.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.quick-btns { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 8px; }
.quick-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-chip);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
