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

:root {
  --bg: #fafafa;
  --card-default: #ffffff;
  --border: #e0e0e0;
  --text: #202124;
  --text-muted: #5f6368;
  --accent: #FFF475;
  --accent-strong: #FBBC04;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN',
               'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 100px;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  background: var(--accent);
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.app-header h1 {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: #202124;
}
.header-icon-btn {
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  padding: 6px; border-radius: 50%;
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center; justify-content: center;
  flex-shrink: 0;
}
.header-icon-btn:active { background: rgba(0,0,0,0.12); }
.header-icon-btn.active { background: rgba(0,0,0,0.18); }

.status-banner {
  padding: 10px 16px;
  font-size: 13px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.status-banner.error { background: #FDDCDA; color: #C62828; }
.status-banner.info  { background: #E3F2FD; color: #1565C0; }

.search-panel {
  background: #fff;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.search-input {
  width: 100%;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
  font-family: inherit;
  background: #fafafa;
  color: var(--text);
}
.search-input:focus { border-color: var(--accent-strong); background: #fff; }
.search-tag-chips {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
}
.search-tag-chips:empty { display: none; }

.memo-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-items: start;
}
@media (min-width: 600px) {
  .memo-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px; padding: 20px;
  }
}

.memo-card {
  background: var(--card-default);
  border-radius: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: box-shadow 0.15s ease;
  word-break: break-word;
  position: relative;
}
.memo-card:active { box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
@media (hover: hover) { .memo-card:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.12); } }
.memo-card.pinned::before {
  content: '📌';
  position: absolute; top: 6px; right: 8px;
  font-size: 12px;
}

.memo-title {
  font-weight: 500; margin-bottom: 6px;
  font-size: 15px; line-height: 1.35;
  padding-right: 18px;
}
.memo-content {
  font-size: 14px; color: var(--text);
  white-space: pre-wrap; line-height: 1.5;
}
.memo-items { list-style: none; }
.memo-item {
  display: flex; align-items: flex-start;
  gap: 8px; padding: 3px 0;
  font-size: 14px; line-height: 1.4;
}
.memo-item input[type="checkbox"] {
  margin-top: 3px; cursor: pointer;
  flex-shrink: 0; width: 16px; height: 16px;
}
.memo-item.checked { color: #999; text-decoration: line-through; }

.fab {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  right: 24px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--accent);
  border: none; font-size: 30px; color: #202124;
  box-shadow: 0 4px 12px rgba(0,0,0,0.22);
  cursor: pointer; z-index: 5; line-height: 1;
}
.fab:active { transform: scale(0.95); background: var(--accent-strong); }

.editor {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 20;
}
@media (min-width: 600px) {
  .editor { align-items: center; padding: 20px; }
}
.editor.hidden { display: none; }

.editor-card {
  background: var(--card-default);
  border-radius: 14px 14px 0 0;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto;
  position: relative;
}
@media (min-width: 600px) {
  .editor-card { border-radius: 14px; }
}

.editor-close {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none;
  font-size: 20px; cursor: pointer;
  color: var(--text-muted);
  width: 36px; height: 36px; border-radius: 50%;
}
.editor-close:active { background: rgba(0,0,0,0.08); }

.editor-title {
  width: 100%; font-size: 18px; font-weight: 500;
  border: none; outline: none;
  padding: 8px 28px 8px 0; margin-bottom: 10px;
  background: transparent; font-family: inherit;
}
.editor-content {
  width: 100%; min-height: 140px;
  font-size: 15px; border: none; outline: none;
  resize: vertical; font-family: inherit;
  background: transparent; line-height: 1.5;
}

.editor-items { list-style: none; margin-bottom: 4px; }
.editor-item {
  display: flex; align-items: center;
  gap: 8px; padding: 6px 0;
}
.editor-item input[type="checkbox"] {
  cursor: pointer; width: 18px; height: 18px; flex-shrink: 0;
}
.editor-item input[type="text"] {
  flex: 1; border: none; outline: none;
  font-size: 15px; background: transparent;
  padding: 4px 0; font-family: inherit;
}
.editor-item input[type="text"].checked {
  color: #999; text-decoration: line-through;
}
.editor-item .remove-item {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 16px; padding: 4px 6px;
}
.add-item-btn {
  background: none; border: none;
  color: var(--text-muted); font-size: 14px;
  padding: 8px 0; cursor: pointer; font-family: inherit;
}

.editor-tags-row {
  padding: 12px 0;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}
.tags-label {
  font-size: 12px; color: var(--text-muted); margin-bottom: 8px;
}
.tags-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer; user-select: none;
  font-family: inherit; color: var(--text);
}
.tag-chip:active { background: rgba(0,0,0,0.05); }
.tag-chip.selected {
  background: var(--accent);
  border-color: #202124;
  font-weight: 500;
}
.tag-add-btn {
  border-style: dashed;
  color: var(--text-muted);
  font-size: 13px;
}

.memo-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.memo-tag {
  font-size: 11px;
  padding: 2px 8px; border-radius: 10px;
  background: rgba(0,0,0,0.10); color: var(--text);
}

.editor-due-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}
.due-label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.editor-due-input {
  flex: 1; font-size: 14px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; outline: none;
  font-family: inherit; background: #fafafa; color: var(--text);
}
.editor-due-input:focus { border-color: var(--accent-strong); background: #fff; }
.due-clear-btn {
  background: none; border: none;
  color: var(--text-muted); font-size: 14px;
  cursor: pointer; padding: 4px 6px; border-radius: 4px;
  flex-shrink: 0;
}

.editor-pin-row {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.pin-label {
  display: inline-flex; align-items: center;
  gap: 6px; cursor: pointer; user-select: none;
}
.pin-label input { cursor: pointer; }

.memo-due {
  display: inline-block;
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: rgba(0,0,0,0.08); color: var(--text-muted);
  margin-top: 8px;
}
.memo-due.due-soon    { background: #FFF3CD; color: #7D4E00; }
.memo-due.due-overdue { background: #FDDCDA; color: #C62828; }

.editor-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  margin-top: 4px; flex-wrap: wrap;
}
.tool-btn {
  background: none; border: none;
  font-size: 18px; cursor: pointer;
  padding: 6px; border-radius: 50%;
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center; justify-content: center;
}
.tool-btn:active { background: rgba(0,0,0,0.08); }
.tool-btn.danger { color: #d93025; }

.color-palette {
  display: flex; gap: 6px; flex: 1;
  flex-wrap: wrap; justify-content: center;
}
.color-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer; padding: 0;
}
.color-btn.selected { border-color: #202124; border-width: 3px; }

.save-btn {
  width: 100%; padding: 13px;
  background: var(--accent);
  border: none; border-radius: 8px;
  font-size: 16px; font-weight: 500;
  cursor: pointer; margin-top: 10px;
  font-family: inherit; color: #202124;
}
.save-btn:active { background: var(--accent-strong); }

.editor-hint {
  font-size: 11px; color: var(--text-muted);
  text-align: center; margin-top: 8px; line-height: 1.5;
}

.color-default { background: #ffffff; }
.color-yellow  { background: #FFF475; }
.color-orange  { background: #FBBC04; }
.color-red     { background: #F28B82; }
.color-green   { background: #CCFF90; }
.color-teal    { background: #A7FFEB; }
.color-blue    { background: #CBF0F8; }
.color-purple  { background: #D7AEFB; }
.color-pink    { background: #FDCFE8; }

.empty-state, .loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  grid-column: 1 / -1;
  line-height: 1.7;
}
.hidden { display: none !important; }
