:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #16181d;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --done: #16a34a;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1d23;
    --text: #f1f2f4;
    --text-muted: #9aa0aa;
    --border: #2a2e37;
    --accent: #4f8cff;
    --accent-contrast: #ffffff;
    --danger: #ef4444;
    --done: #34d399;
  }
}

* { box-sizing: border-box; }

/* [hidden] は他のdisplay指定より必ず優先させる（.view / .overlay 等の対策） */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  flex: 1;
  text-align: center;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 6px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: var(--border); }
.icon-btn-spacer { width: 40px; height: 40px; display: inline-block; }

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(var(--safe-bottom) + 16px);
}

/* --- ホーム: リスト一覧 --- */
.lists {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}
.list-card:active { opacity: 0.7; }

.list-card-main { min-width: 0; flex: 1; }

.list-card-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.list-card-chevron {
  color: var(--text-muted);
  font-size: 18px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 60px;
  line-height: 1.7;
  font-size: 15px;
}

.fab-wrap {
  flex-shrink: 0;
  padding: 10px 16px calc(var(--safe-bottom) + 14px);
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.fab {
  width: 100%;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.fab:active { opacity: 0.85; }

/* --- 進捗バー --- */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.progress-track {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--done);
  transition: width 0.2s ease;
}
.progress-label {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 46px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.history-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.history-caption {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.history-dots {
  display: flex;
  gap: 6px;
}
.history-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.history-dot[data-level="full"] { background: var(--done); }
.history-dot[data-level="partial"] { background: #f59e0b; }
.history-dot[data-level="none"] { background: var(--border); }

/* --- 項目一覧 --- */
.items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.item-checkbox {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: transparent;
  cursor: pointer;
}
.item-checkbox.checked {
  background: var(--done);
  border-color: var(--done);
  color: #fff;
}

.item-text {
  flex: 1;
  font-size: 16px;
  line-height: 1.4;
  word-break: break-word;
  cursor: pointer;
}
.item-row.checked .item-text {
  color: var(--text-muted);
  text-decoration: line-through;
}

.item-edit-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.item-edit-controls button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.item-edit-controls button.danger { color: var(--danger); }

.add-item-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(var(--safe-bottom) + 12px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.add-item-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}
.add-item-btn {
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 10px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

/* --- 設定 --- */
.settings-content { padding-top: 16px; }
.settings-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.settings-heading {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.settings-desc {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  margin: 0 0 12px;
}
.settings-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 8px;
  cursor: pointer;
}
.settings-btn:last-child { margin-bottom: 0; }
.settings-btn.danger { color: var(--danger); }
.version-label {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 20px;
}

/* --- 合言葉ゲート --- */
.gate-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px calc(var(--safe-right) + 24px) calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 24px);
  padding-top: calc(var(--safe-top) + 24px);
}
.gate-title {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  margin: 0 0 8px;
}
.gate-desc {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px;
  line-height: 1.6;
}
.gate-form {
  display: flex;
  gap: 8px;
}
.gate-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
}
.gate-btn {
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 10px;
  padding: 0 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.gate-error {
  color: var(--danger);
  font-size: 13px;
  margin: 12px 0 0;
  text-align: center;
}
.gate-note {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.6;
  margin: 24px 0 0;
}

/* --- オーバーレイ / ダイアログ --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.confirm-box {
  background: var(--surface);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
}
.confirm-message {
  font-size: 15px;
  line-height: 1.6;
  margin: 0 0 14px;
  color: var(--text);
}
.prompt-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 14px;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.confirm-btn {
  border: none;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.confirm-btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.confirm-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- トースト --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  background: rgba(20,20,20,0.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  max-width: 85%;
  text-align: center;
}
